Class: SqlSearchNSort::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/sql_search_n_sort/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_filesObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/sql_search_n_sort/install_generator.rb', line 11

def copy_files
  base_path = "app/views/application"
    copy_file('_search_form.html.haml', File.join(base_path, '_search_form.html.haml'))
    copy_file('_sort_form.html.haml', File.join(base_path, '_sort_form.html.haml'))

    base_path = "app/assets/javascripts"
    copy_file('sql_search_n_sort.js', File.join(base_path, 'sql_search_n_sort.js'))

    base_path = "config/initializers"
    copy_file('sql_search_n_sort.rb', File.join(base_path, 'sql_search_n_sort.rb'))
end

#insert_into_app_controllerObject



33
34
35
36
37
38
39
40
# File 'lib/generators/sql_search_n_sort/install_generator.rb', line 33

def insert_into_app_controller
  inject_into_file "app/controllers/application_controller.rb",
    before: /^end/ do
      %Q`\n\tinclude SqlSortSetup\n
  before_action :setup_sql_sort, :only => [:index, :sort_only_index]
   \n`
    end
end

#require_jqueryObject



23
24
25
26
27
28
29
30
31
# File 'lib/generators/sql_search_n_sort/install_generator.rb', line 23

def require_jquery
  #could be either application.js or application.js.coffee or maybe something else in the future
  if app_js_fl = Dir["#{destination_root}/app/assets/javascripts/*"].select{|f| f =~ /application\.js/}.first
    inject_into_file app_js_fl,
    before: "\n//= require_tree ." do
      "\n//= require jquery"
    end
  end
end