Class: Rang::Assets::Generators::InitGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/rang/assets/init/init_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_html_attributeObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails/generators/rang/assets/init/init_generator.rb', line 27

def add_html_attribute
  if !no? "\n\nAdd ng-app='#{Rang::Util.application_name}' to application.html? [Yn]", :cyan
    in_root do
      if layout_handler == "ActionView::Template::Handlers::ERB"
        gsub_file layout_file, "<html>", "<html ng-app='#{Rang::Util.application_name}'>"
      elsif layout_handler == "Slim::RailsTemplate"
        gsub_file layout_file, /^html$/, "html ng-app='#{Rang::Util.application_name}'"
      end
    end
  end
end

#create_assets!Object



20
21
22
23
24
25
# File 'lib/rails/generators/rang/assets/init/init_generator.rb', line 20

def create_assets!
  template 'application.js', 'app/assets/frontend/application.js'
  template 'application.scss', 'app/assets/frontend/application.scss'
  template '_base.scss', 'app/assets/frontend/style/_base.scss'
  template 'components.js', 'app/assets/frontend/components/components.js'
end

#deprecate_old_assets!Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rails/generators/rang/assets/init/init_generator.rb', line 8

def deprecate_old_assets!
  empty_directory 'app/assets.removed'

  ["javascripts", "stylesheets"].each do |dir|
    if File.exist? "app/assets/#{dir}"
      say_status :move, "app/assets/#{dir} -> app/assets.removed/#{dir}"
      run "mv app/assets/#{dir} app/assets.removed/#{dir}", verbose: false
    end
    remove_dir "app/assets/#{dir}"
  end
end