class DatepickerGenerator

Public Instance Methods

finish() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 33
def finish
  puts "Done."
end
modify_application_css() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 23
def modify_application_css
  if asset_already_required_in_manifest?('datepicker', style_file, style_root_path)
    puts "*= require datepicker already exists in #{style_file}..."
  else
    require_tree_exists? ? content_to_add = include_tree?(true) : content_to_add = include_tree?(false)
    File.open(style_root_path + style_file, "w") { |file| file.puts content_to_add }
    puts "*= require datepicker added to #{style_file}..."
  end
end
modify_application_js() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 7
def modify_application_js
  js_file
  assets = ['datepicker', 'jquery.mask']
  file = File.open(js_root_path + js_file, 'a')
  file << "\n"
  assets.each do |asset|
    if asset_already_required_in_manifest?(asset, js_file, js_root_path)
      puts "#{check_last_line_is_blank}//= require #{asset} already exists in #{js_file}..."
    else
      file << "//= require #{asset}\n"
      puts "//= require #{asset} added to #{js_file}..."
    end
  end
  file.close
end

Private Instance Methods

asset_already_required_in_manifest?(asset, file, path) click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 75
def asset_already_required_in_manifest?(asset, file, path)
  file_to_check = File.open(path + file, "r")
  if file.include? "js"
    file_to_check.grep(/(\/\/= require #{asset})/).size > 0
  elsif file.include? "css"
    file_to_check.grep(/(\*\= require #{asset})/).size > 0
  end
end
include_tree?(exists) click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 43
def include_tree?(exists)
  if exists
    text.gsub(/(\*\= require_tree \.)/, "*= require datepicker\n *= require_tree .")
  else
    text.gsub(/(\*\/)/, " *= require datepicker\n*/")
  end
end
js_file() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 62
def js_file
  js_file = 'application.js'
  File.file?(js_root_path + js_file) ? js_file : nil
end
js_root_path() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 71
def js_root_path
  'app/assets/javascripts/'
end
require_tree_exists?() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 39
def require_tree_exists?
  File.readlines(style_root_path + style_file).grep(/(\*\= require_tree \.)/).size > 0
end
style_file() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 55
def style_file
  css_file = 'application.css'
  scss_file = 'application.scss'
  return css if File.file?(style_root_path + css_file)
  File.file?(style_root_path + scss_file) ? scss_file : nil
end
style_root_path() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 67
def style_root_path
  'app/assets/stylesheets/'
end
text() click to toggle source
# File lib/generators/datepicker/datepicker_generator.rb, line 51
def text
  File.read(style_root_path + style_file) unless style_file.nil?
end