Class: Infold::ProjectGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Infold::ProjectGenerator
- Defined in:
- lib/generators/infold/project/project_generator.rb
Instance Method Summary collapse
- #create_component_relation_field ⇒ Object
- #create_header_menu_file ⇒ Object
- #create_locale_file ⇒ Object
- #modify_routes_file ⇒ Object
- #setup ⇒ Object
Instance Method Details
#create_component_relation_field ⇒ Object
13 14 15 16 17 18 |
# File 'lib/generators/infold/project/project_generator.rb', line 13 def create_component_relation_field @modal_apps = App.all.joins(:app_view_modal).distinct file_path = File.join("#{@dist_path}/app/components/#{@ns_snake}/form", "relation_fieldset_component.rb") File.delete(file_path) if File.exist?(file_path) template "relation_fieldset_component.rb", file_path end |
#create_header_menu_file ⇒ Object
41 42 43 44 45 46 |
# File 'lib/generators/infold/project/project_generator.rb', line 41 def @menu_items = MenuItem.all file_path = File.join("#{@dist_path}/app/views/#{@ns_snake}/common/_header_menu.html.haml") File.delete(file_path) if File.exist?(file_path) template "_header_menu.haml", file_path end |
#create_locale_file ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/generators/infold/project/project_generator.rb', line 48 def create_locale_file Model.all.each do |model| @model = ActiveDecorator::Decorator.instance.decorate(model) locale_file_path = File.join("#{@dist_path}/config/locales/#{@ns_snake}/models", "#{model.name.underscore}.#{I18n.default_locale.presence || 'en'}.yml") File.delete(locale_file_path) if File.exist?(locale_file_path) template "locales/model.yml", locale_file_path end App.all.each do |app| @app = ActiveDecorator::Decorator.instance.decorate(app) @view_index = app.app_view_index @view_modal = app.app_view_modal locale_file_path = File.join("#{@dist_path}/config/locales/#{@ns_snake}/forms", "#{@app.model.name.underscore}_search_form.#{I18n.default_locale.presence || 'en'}.yml") File.delete(locale_file_path) if File.exist?(locale_file_path) template "locales/form.yml", locale_file_path end end |
#modify_routes_file ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/infold/project/project_generator.rb', line 20 def modify_routes_file route_file = Rails.root.join("config", "routes", "#{@ns_snake}.rb") current_route = File.read(route_file).to_s App.all.each do |app| code = "resources :#{app.model.name_pluralize}" next if current_route.match?(/#{code}$/) inject_into_file route_file, after: "namespace '#{@ns_snake}' do" do "\n #{code}" end end root_base = "authenticated :#{@ns_snake}_user do root :to =>" root_code = "#{root_base} '#{@project.root_app.model.name_pluralize}#index', as: :root end" if current_route.match?(/#{root_base}/) gsub_file route_file, /#{root_base}.*$/, root_code else inject_into_file route_file, after: "namespace '#{@ns_snake}' do" do "\n #{root_code}" end end end |
#setup ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/generators/infold/project/project_generator.rb', line 5 def setup raise '' if name.to_i == -1 @project = Project.first @dist_path = Rails.root @ns_camel = @project.namespace.camelize @ns_snake = @project.namespace.underscore end |