Class: Repack::ViewGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Repack::ViewGenerator
- Defined in:
- lib/generators/repack/view_generator.rb
Overview
:nodoc:
Instance Method Summary collapse
- #create_container ⇒ Object
- #create_entry_file ⇒ Object
- #create_rails_view ⇒ Object
- #normalize_view_name ⇒ Object
- #update_webpack_entry ⇒ Object
Instance Method Details
#create_container ⇒ Object
30 31 32 33 34 35 |
# File 'lib/generators/repack/view_generator.rb', line 30 def create_container name = @view.titleize.gsub(/ /, '') file = "client/containers/#{name}.js" copy_file "boilerplate/views/ContainerTemplate.js", file gsub_file file, /Placeholder/, name end |
#create_entry_file ⇒ Object
23 24 25 26 27 28 |
# File 'lib/generators/repack/view_generator.rb', line 23 def create_entry_file file = "client/#{@view.gsub(/ /, '')}.js" name = @view.titleize.gsub(/ /, '') copy_file "boilerplate/views/ViewTemplate.js", file gsub_file file, /Placeholder/, name end |
#create_rails_view ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/repack/view_generator.rb', line 37 def create_rails_view name = @view.downcase.gsub(/ /, '_') empty_directory "app/views/#{name.pluralize}" if Gem.loaded_specs.has_key? 'haml-rails' file = "app/views/#{name.pluralize}/index.html.haml" copy_file "boilerplate/views/rails_view.html.haml", file gsub_file file, /placeholder/, name else file = "app/views/#{name.pluralize}/index.html.erb" copy_file "boilerplate/views/rails_view.html.erb", file gsub_file file, /placeholder/, name end end |
#normalize_view_name ⇒ Object
8 9 10 11 |
# File 'lib/generators/repack/view_generator.rb', line 8 def normalize_view_name raise "View name argument missing" if args.length == 0 @view = args[0] end |
#update_webpack_entry ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/generators/repack/view_generator.rb', line 13 def update_webpack_entry name = @view.downcase.gsub(/ /, "_") path = "'#{name}': './client/#{name}.js'," insert_into_file 'config/webpack.config.js', after: /entry: {\n/ do "\#{path}\n CONFIG\n end\nend\n" |