Class: ActiveScaffold::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_concern_routesObject



9
10
11
12
# File 'lib/generators/active_scaffold/install_generator.rb', line 9

def add_concern_routes
  route 'concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)'
  route 'concern :active_scaffold_association, ActiveScaffold::Routing::Association.new'
end

#add_to_javascript_manifestObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/active_scaffold/install_generator.rb', line 14

def add_to_javascript_manifest
  file = 'app/assets/javascripts/application.js'
  unless File.exist?(file)
    if Rails.version >= '6.0'
      create_javascript_manifest file
      return
    end
    say_status :missing, file, :red
    return if options[:pretend]
    raise Thor::Error, "JS file #{file} is required for ActiveScaffold"
  end
  original_js = File.binread(file)
  if original_js.include?('require active_scaffold')
    say_status('skipped', "insert into #{file}", :yellow)
  else
    insert_into_file file, after: %r{//= require +.*ujs['"]?\n} do
      "//= require active_scaffold\n"
    end
  end
  setup_jquery file, original_js
end

#add_to_stylesheet_manifestObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/active_scaffold/install_generator.rb', line 36

def add_to_stylesheet_manifest
  file = 'app/assets/stylesheets/application.css'
  return unless File.exist?(file)
  original_css = File.binread(file)
  if original_css.match?(/require active_scaffold$/)
    say_status('skipped', 'insert into app/assets/stylesheets/application.css', :yellow)
  else
    insert_into_file 'app/assets/stylesheets/application.css', before: %r{[ ]*\*/} do
      " *= require active_scaffold\n"
    end
  end
end