Class: ScaffoldAdmin::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ScaffoldAdmin::InstallGenerator
- Defined in:
- lib/generators/scaffold_admin/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #array_classes ⇒ Object
- #array_javascripts ⇒ Object
- #array_views ⇒ Object
- #copy_files ⇒ Object
- #inject_code_helper ⇒ Object
Class Method Details
.source_root ⇒ Object
5 6 7 |
# File 'lib/generators/scaffold_admin/install_generator.rb', line 5 def self.source_root @_install_source_root ||= File.("../templates", __FILE__) end |
Instance Method Details
#array_classes ⇒ Object
51 52 53 |
# File 'lib/generators/scaffold_admin/install_generator.rb', line 51 def array_classes %w[controller helper model migration] end |
#array_javascripts ⇒ Object
59 60 61 |
# File 'lib/generators/scaffold_admin/install_generator.rb', line 59 def array_javascripts %w[app bootstrap.min bootswatch html5 jquery-1.7.2.min jquery.easing.1.3 login] end |
#array_views ⇒ Object
55 56 57 |
# File 'lib/generators/scaffold_admin/install_generator.rb', line 55 def array_views %w[edit _form index new show] end |
#copy_files ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/scaffold_admin/install_generator.rb', line 9 def copy_files gem 'will_paginate' copy_file "config/initializers/will_paginate.rb", "config/initializers/will_paginate.rb" array_classes.each do |klass| copy_file "#{klass}.rb", "lib/templates/#{klass}.rb" end array_views.each do |view| copy_file "views/#{view}.html.erb", "lib/templates/views/#{view}.html.erb" end copy_file "layouts/admin.html.erb", "app/views/layouts/admin.html.erb" copy_file "stylesheets/ie.css", "app/assets/stylesheets/ie.css" copy_file "stylesheets/layout.css", "app/assets/stylesheets/layout.css" copy_file "stylesheets/bootstrap-responsive.css", "app/assets/stylesheets/bootstrap-responsive.css" copy_file "stylesheets/bootstrap.css.erb", "app/assets/stylesheets/bootstrap.css.erb" copy_file "stylesheets/docs.css.erb", "app/assets/stylesheets/docs.css.erb" array_javascripts.each do |js| copy_file "javascripts/#{js}.js", "app/assets/javascripts/#{js}.js" end directory "images/icons", "app/assets/images/icons" end |
#inject_code_helper ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/scaffold_admin/install_generator.rb', line 36 def inject_code_helper path = IO.readlines("config/routes.rb") content = File.open(File.("../templates/code_application_helper.rb", __FILE__), 'r') {|file| file.read} sentinel = /module ApplicationHelper/ app = /::Application/ engine = /::Engine/ application = path.first.gsub(/::(.*)/, "").chomp.underscore if path.first =~ app inject_into_file "app/helpers/application_helper.rb", "\n#{content}\n", { after: sentinel, verbose: false } elsif path.first =~ engine inject_into_file "app/helpers/#{application}/application_helper.rb", "\n#{content}\n", { after: sentinel, verbose: false } end end |