Class: Infold::AppGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Infold::AppGenerator
- Defined in:
- lib/generators/infold/app/app_generator.rb
Instance Method Summary collapse
- #create_association_view_form_file ⇒ Object
- #create_controller_file ⇒ Object
- #create_search_form_file ⇒ Object
- #create_view_form_file ⇒ Object
- #create_view_index_file ⇒ Object
- #create_view_modal_search_file ⇒ Object
- #create_view_show_file ⇒ Object
- #setup ⇒ Object
Instance Method Details
#create_association_view_form_file ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/generators/infold/app/app_generator.rb', line 86 def create_association_view_form_file @view = @app.app_view_form return if @view.blank? base_path = "#{@dist_path}/app/views/#{@ns_snake}" @view.form_associations.select(&:display?).each do |form_association| @form_association = form_association view_path = File.join(base_path, "#{@app.model.name_pluralize}/_#{form_association.model_association.model.name.underscore}_fields.html.haml") File.delete(view_path) if File.exist?(view_path) template("views/_association_fields.haml", view_path) unless File.exist?(view_path) end end |
#create_controller_file ⇒ Object
29 30 31 32 33 34 |
# File 'lib/generators/infold/app/app_generator.rb', line 29 def create_controller_file base_path = "#{@dist_path}/app/controllers/#{@ns_snake}" controller_file_path = File.join(base_path, "#{@app.model.name_pluralize}_controller.rb") File.delete(controller_file_path) if File.exist?(controller_file_path) template "controller.rb", controller_file_path end |
#create_search_form_file ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/generators/infold/app/app_generator.rb', line 53 def create_search_form_file @view = @app.app_view_index @view_modal = @app.app_view_modal return if @view.blank? && @view_modal.blank? base_path = "#{@dist_path}/app/forms/#{@ns_snake}" form_file_path = File.join(base_path, "#{@app.model.name.underscore}_search_form.rb") File.delete(form_file_path) if File.exist?(form_file_path) template "search_form.rb", form_file_path end |
#create_view_form_file ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/generators/infold/app/app_generator.rb', line 63 def create_view_form_file @view = @app.app_view_form return if @view.blank? base_path = "#{@dist_path}/app/views/#{@ns_snake}" %w(new edit _form).each do |v| view_path = File.join(base_path, "#{@app.model.name_pluralize}/#{v}.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/#{v}.haml", view_path end view_path = File.join(base_path, "#{@app.model.name_pluralize}/new.html+turbo_frame.haml") File.delete(view_path) if File.exist?(view_path) template "views/new+turbo_frame.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/edit.html+turbo_frame.haml") File.delete(view_path) if File.exist?(view_path) template "views/edit+turbo_frame.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/form.turbo_stream.haml") File.delete(view_path) if File.exist?(view_path) template "views/form.turbo_stream.haml", view_path end |
#create_view_index_file ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/infold/app/app_generator.rb', line 36 def create_view_index_file @view = @app.app_view_index base_path = "#{@dist_path}/app/views/#{@ns_snake}" view_path = File.join(base_path, "#{@app.model.name_pluralize}/index.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/index.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/_index_row.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/_index_row.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/index.csv.ruby") File.delete(view_path) if File.exist?(view_path) template "views/index.csv.ruby", view_path end |
#create_view_modal_search_file ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/generators/infold/app/app_generator.rb', line 124 def create_view_modal_search_file @view = @app.app_view_modal return if @view.blank? base_path = "#{@dist_path}/app/views/#{@ns_snake}" view_path = File.join(base_path, "#{@app.model.name_pluralize}/index.html+turbo_frame.haml") File.delete(view_path) if File.exist?(view_path) template "views/index+turbo_frame.haml", view_path end |
#create_view_show_file ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/generators/infold/app/app_generator.rb', line 98 def create_view_show_file @view = @app.app_view_show return if @view.blank? base_path = "#{@dist_path}/app/views/#{@ns_snake}" view_path = File.join(base_path, "#{@app.model.name_pluralize}/show.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/show.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/show.html+turbo_frame.haml") File.delete(view_path) if File.exist?(view_path) template "views/show+turbo_frame.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/_detail.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/_detail.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/_detail_modal_wrapper.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/_detail_modal_wrapper.haml", view_path view_path = File.join(base_path, "#{@app.model.name_pluralize}/_show_operation.html.haml") File.delete(view_path) if File.exist?(view_path) template "views/_show_operation.haml", view_path end |
#setup ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/infold/app/app_generator.rb', line 5 def setup raise '' if name.to_i == -1 @app = App.includes( :model, app_view_index: [search_result_columns: [:model_column], search_result_attachment_fields: [:attachment_field], csv_columns: [:model_column], search_conditions: :model_column], app_view_show: [show_columns: :model_column, show_associations: [show_association_columns: :model_column]], app_view_form: [form_columns: :model_column, form_associations: [form_association_columns: :model_column]], app_view_modal: [search_result_columns: [:model_column], search_result_attachment_fields: [:attachment_field], search_conditions: :model_column] ).find_by(id: name.to_i) raise "#{t('infold.no_app')}: #{name}" if @app.blank? @app = ActiveDecorator::Decorator.instance.decorate(@app) @dist_path = Rails.root ns = Project.first.namespace @ns_camel = ns.camelize @ns_snake = ns.underscore end |