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



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

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
# 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"
  begin
    inject_into_file("#{target_file_path}.coffee", js_to_add, after: ref)
  rescue Errno::ENOENT
    inject_into_file("#{target_file_path}.js.coffee", js_to_add, after: ref)
  end
end

#add_stylesheetsObject



14
15
16
17
18
19
20
21
# File 'lib/generators/activeadmin_ancestry_view/install/install_generator.rb', line 14

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