Class: Superglue::Generators::ViewCollectionGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Superglue::Generators::ViewCollectionGenerator
- Includes:
- Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/superglue/view_collection/view_collection_generator.rb
Instance Method Summary collapse
- #append_mapping ⇒ Object
- #copy_js_files ⇒ Object
- #copy_prop_files ⇒ Object
- #create_root_folder ⇒ Object
Instance Method Details
#append_mapping ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/generators/superglue/view_collection/view_collection_generator.rb', line 47 def append_mapping available_views.each do |action| app_js = if ["typescript"] "#{app_js_path}/page_to_page_mapping.ts" else "#{app_js_path}/page_to_page_mapping.js" end component_name = [plural_table_name, action].map(&:camelcase).join if match_file(app_js, /pageIdentifierToPageComponent = {$/) prepend_to_file app_js do "import #{component_name} from '#{view_path}/#{controller_file_path}/#{action}'\n" end inject_into_file app_js, after: /pageIdentifierToPageComponent = {$/ do "\n '#{[controller_file_path, action].join("/")}': #{component_name}," end else say "Skipping appending to #{app_js}, you may be using a bundler that supports globing." end end end |
#copy_js_files ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/superglue/view_collection/view_collection_generator.rb', line 34 def copy_js_files available_views.each do |view| @action_name = view if ["typescript"] filename = filename_with_tsx_extensions(view) template "ts/" + filename, File.join("app/views", controller_file_path, filename) else filename = filename_with_jsx_extensions(view) template "js/" + filename, File.join("app/views", controller_file_path, filename) end end end |
#copy_prop_files ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/superglue/view_collection/view_collection_generator.rb', line 24 def copy_prop_files available_views.each do |view| @action_name = view filename = filename_with_extensions(view) template "props/" + filename, File.join("app/views", controller_file_path, filename) end template "props/_form.json.props", File.join("app/views", controller_file_path, "_form.json.props") end |
#create_root_folder ⇒ Object
19 20 21 22 |
# File 'lib/generators/superglue/view_collection/view_collection_generator.rb', line 19 def create_root_folder path = File.join("app/views", controller_file_path) empty_directory path unless File.directory?(path) end |