Class: Templaty::CrudGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Templaty::CrudGenerator
- Defined in:
- lib/generators/templaty/crud_generator.rb
Instance Method Summary collapse
- #controller ⇒ Object
- #css ⇒ Object
- #hbs ⇒ Object
- #i18n ⇒ Object
- #js ⇒ Object
- #model ⇒ Object
- #pages ⇒ Object
- #route_gridyable ⇒ Object
- #route_resource ⇒ Object
- #seed ⇒ Object
- #shared ⇒ Object
- #spec ⇒ Object
- #warning ⇒ Object
Instance Method Details
#controller ⇒ Object
28 29 30 31 32 33 |
# File 'lib/generators/templaty/crud_generator.rb', line 28 def controller from = 'crud/app/controllers/system/table_controller.rb.erb' to = "app/controllers/system/#{[:table]}_controller.rb" template(from, to) end |
#css ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/generators/templaty/crud_generator.rb', line 35 def css %w[form index].each do |name| from = "crud/app/assets/stylesheets/namespace/views/table/#{name}.scss.erb" to = "app/assets/stylesheets/#{[:namespace]}/views/#{[:table]}/#{name}.scss" template(from, to) end end |
#hbs ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/templaty/crud_generator.rb', line 44 def hbs %w[table.gridy.hbs.erb].each do |name| from = "crud/app/assets/templates/namespace/#{name}" to = "app/javascript/templates/#{[:namespace]}/#{[:table]}.gridy.hbs" template(from, to) end `gulp hbs` end |
#i18n ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/templaty/crud_generator.rb', line 55 def i18n actions = %w[create destroy edit index show update] %w[en pt-BR ru].each do |locale| actions.each do |name| next if name == 'show' && [:show_route] != true from = "crud/config/locales/#{locale}/namespace/table/#{name}.yml.erb" to = "config/locales/#{locale}/#{[:namespace]}/#{[:table]}/#{name}.yml" template(from, to) end from = "crud/config/locales/#{locale}/model.yml.erb" to = "config/locales/#{locale}/#{[:table].singularize}.yml" template(from, to) end end |
#js ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/generators/templaty/crud_generator.rb', line 75 def js %w[form index].each do |name| from = "crud/app/javascripts/#{name}.js.erb" to = "app/javascript/pages/#{[:namespace]}/views/#{[:table]}/#{name}.js" template(from, to) end end |
#model ⇒ Object
84 85 86 87 88 89 |
# File 'lib/generators/templaty/crud_generator.rb', line 84 def model from = 'crud/app/models/model.rb.erb' to = "app/models/#{[:table].singularize}.rb" template(from, to) end |
#pages ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/generators/templaty/crud_generator.rb', line 91 def pages %w[ _form.html.erb _submenu.html.erb _title.html.erb edit.html.erb gridy.json.jbuilder index.html.erb new.html.erb ].each do |name| from = "crud/app/views/namespace/table/#{name}.erb" to = "app/views/#{[:namespace]}/#{[:table]}/#{name}" template(from, to) end end |
#route_gridyable ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/generators/templaty/crud_generator.rb', line 120 def route_gridyable route %( concern :gridyable do get :gridy, defaults: { format: :json }, on: :collection end ) end |
#route_resource ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/generators/templaty/crud_generator.rb', line 108 def route_resource content = <<~HEREDOC resources :#{[:table]}, concerns: :gridyable, #{[:show_route] ? nil : 'except: :show,'} path: :#{[:path]}, path_names: { new: :novo, edit: :editar } HEREDOC route content, namespace: [:namespace] end |
#seed ⇒ Object
128 129 130 131 132 133 |
# File 'lib/generators/templaty/crud_generator.rb', line 128 def seed from = 'crud/db/seeds/pd/model.rb.erb' to = "db/seeds/pd/#{[:table].singularize}.rb" template(from, to) end |
#shared ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/generators/templaty/crud_generator.rb', line 135 def shared %w[_model.html.erb].each do |name| from = "crud/app/views/shared/icons/#{name}.erb" to = "app/views/shared/guide/_#{[:table].singularize}.html.erb" template(from, to) end end |
#spec ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/generators/templaty/crud_generator.rb', line 144 def spec %w[ spec/controllers/namespace/model/create_spec.rb spec/controllers/namespace/model/destroy_spec.rb spec/controllers/namespace/model/edit_spec.rb spec/controllers/namespace/model/gridy/json_spec.rb spec/controllers/namespace/model/gridy/unlogged_spec.rb spec/controllers/namespace/model/index_spec.rb spec/controllers/namespace/model/new_spec.rb spec/controllers/namespace/model/update_spec.rb spec/features/namespace/model/create_spec.rb spec/features/namespace/model/destroy_spec.rb spec/features/namespace/model/gridy/initial_spec.rb spec/features/namespace/model/gridy/search_spec.rb spec/features/namespace/model/gridy/sort_spec.rb spec/features/namespace/model/update_spec.rb spec/models/model/list_spec.rb ].each do |path| from = "crud/#{path}.erb" to = path.sub('namespace', [:namespace]).sub('model', [:table].singularize) template(from, to) end end |
#warning ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/generators/templaty/crud_generator.rb', line 169 def warning puts("\n=== Plese edit the following files: ===\n\n") # rubocop:disable Rails/Output %w[en pt-BR ru].each do |locale| puts("code config/locales/#{locale}/#{[:table].singularize}.yml:5") # rubocop:disable Rails/Output end puts("code db/seeds/pd/#{[:table].singularize}.rb") # rubocop:disable Rails/Output end |