Class: ActiveadminAncestryView::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_concernsObject



28
29
30
31
32
33
34
35
# File 'lib/generators/activeadmin_ancestry_view/install/install_generator.rb', line 28

def add_concerns
  ref = 'has_ancestry'
  Dir['app/models/**/*.rb'].each do |model_file|
    if File.readlines(model_file).grep(/has_ancestry/).any?
      inject_into_file(model_file, concern_to_add, before: ref)
    end
  end
end

#add_javascriptsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/activeadmin_ancestry_view/install/install_generator.rb', line 4

def add_javascripts
  target_file_path = 'app/assets/javascripts/active_admin'
  ref = "#= require active_admin/base\n"
  vanilla_ref = "//= require active_admin/base\n"
  begin
    inject_into_file("#{target_file_path}.coffee", js_to_add, after: ref)
  rescue
    begin
      inject_into_file("#{target_file_path}.js.coffee", js_to_add, after: ref)
    rescue
      inject_into_file("#{target_file_path}.js", vanilla_js_to_add, after: vanilla_ref)
    end
  end
end

#add_stylesheetsObject



19
20
21
22
23
24
25
26
# File 'lib/generators/activeadmin_ancestry_view/install/install_generator.rb', line 19

def add_stylesheets
  target_file_path = 'app/assets/stylesheets/active_admin'
  begin
    prepend_file("#{target_file_path}.scss", css_to_add)
  rescue Errno::ENOENT
    prepend_file("#{target_file_path}.css.scss", css_to_add)
  end
end