lesli 5.1.13 → 5.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/lesli/application_lesli_controller.rb +27 -0
  3. data/app/controllers/lesli/items/attachments_controller.rb +3 -3
  4. data/app/controllers/lesli/items/discussions_controller.rb +2 -2
  5. data/app/controllers/lesli/items/tasks_controller.rb +2 -2
  6. data/app/controllers/lesli/roles_controller.rb +1 -6
  7. data/app/controllers/lesli/users_controller.rb +1 -5
  8. data/app/helpers/lesli/announcements_helper.rb +14 -0
  9. data/app/helpers/lesli/navigation_helper.rb +1 -1
  10. data/app/interfaces/lesli/responder_interface.rb +11 -4
  11. data/app/models/concerns/lesli/account_initializer.rb +5 -45
  12. data/app/models/concerns/lesli/user_extensions.rb +4 -2
  13. data/app/models/lesli/items/attachment.rb +3 -3
  14. data/app/models/lesli/role.rb +14 -2
  15. data/app/models/lesli/user.rb +7 -0
  16. data/app/operators/lesli/account_operator.rb +84 -0
  17. data/app/operators/lesli/resource_operator.rb +123 -0
  18. data/app/services/lesli/application_lesli_service.rb +33 -116
  19. data/app/services/lesli/resource_service.rb +12 -159
  20. data/app/services/lesli/role_service.rb +11 -229
  21. data/app/services/lesli/user_service.rb +37 -117
  22. data/app/views/lesli/layouts/application-lesli.html.erb +1 -1
  23. data/app/views/lesli/partials/_application-lesli-announcements.html.erb +28 -0
  24. data/app/views/lesli/partials/_application-lesli-header.html.erb +3 -2
  25. data/app/views/lesli/partials/_application-lesli-turbo.html.erb +5 -0
  26. data/config/initializers/lesli.rb +7 -2
  27. data/config/locales/translations.en.yml +57 -48
  28. data/config/locales/translations.es.yml +55 -45
  29. data/db/migrate/v1/0000000210_create_lesli_users.rb +1 -0
  30. data/db/seed/xyz.rb +1 -3
  31. data/lib/generators/lesli/base_generator.rb +41 -3
  32. data/lib/generators/lesli/controller/controller_generator.rb +1 -1
  33. data/lib/generators/lesli/controller/templates/controller.rb.tt +12 -7
  34. data/lib/generators/lesli/model/model_generator.rb +1 -1
  35. data/lib/generators/lesli/resource/resource_generator.rb +290 -0
  36. data/lib/generators/lesli/resource/templates/controller.rb.tt +99 -0
  37. data/lib/generators/lesli/resource/templates/locale.en.yml.tt +13 -0
  38. data/lib/generators/lesli/resource/templates/migration.rb.tt +28 -0
  39. data/lib/generators/lesli/resource/templates/model.rb.tt +38 -0
  40. data/lib/generators/lesli/resource/templates/operator.rb.tt +15 -0
  41. data/lib/generators/lesli/resource/templates/service.rb.tt +52 -0
  42. data/lib/generators/lesli/resource/templates/tests/controller_test.rb.tt +14 -0
  43. data/lib/generators/lesli/resource/templates/tests/model_test.rb.tt +24 -0
  44. data/lib/generators/lesli/resource/templates/tests/operator_test.rb.tt +15 -0
  45. data/lib/generators/lesli/resource/templates/tests/service_test.rb.tt +17 -0
  46. data/lib/generators/lesli/resource/templates/views/_form.html.erb.tt +17 -0
  47. data/lib/generators/lesli/resource/templates/views/edit.html.erb.tt +4 -0
  48. data/lib/generators/lesli/resource/templates/views/index.html.erb.tt +22 -0
  49. data/lib/generators/lesli/resource/templates/views/new.html.erb.tt +4 -0
  50. data/lib/generators/lesli/resource/templates/views/show.html.erb.tt +17 -0
  51. data/lib/generators/lesli/scaffold/scaffold_generator.rb +4 -39
  52. data/lib/generators/lesli/service/service_generator.rb +1 -1
  53. data/lib/generators/lesli/service/templates/service.rb.tt +15 -7
  54. data/lib/generators/lesli/views/views_generator.rb +1 -1
  55. data/lib/generators/lesli_generator.rb +11 -0
  56. data/lib/lesli/courier.rb +66 -34
  57. data/lib/lesli/database_tasks.rb +145 -0
  58. data/lib/lesli/version.rb +2 -2
  59. data/lib/tasks/lesli/db.rake +16 -93
  60. data/lib/tasks/lesli/resources.rake +1 -1
  61. data/readme.md +3 -1
  62. metadata +24 -3
  63. data/app/views/lesli/partials/_application-lesli-sidebar.html.erb +0 -50
@@ -29,7 +29,7 @@ module Lesli
29
29
  # Example:
30
30
  # app/models/lesli_support
31
31
  def model_directory
32
- File.join(ENGINE_ROOT, "app/models", engine_name)
32
+ engine_root.join("app/models", engine_name)
33
33
  end
34
34
 
35
35
  # Returns the final path of the generated model file.
@@ -0,0 +1,290 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require_relative "../base_generator"
5
+
6
+ module Lesli
7
+ module Generators
8
+ # Generates a complete account-scoped Lesli resource inside an engine.
9
+ class ResourceGenerator < BaseGenerator
10
+ ALLOWED_ITEMS = %w[activities attachments discussions tasks].freeze
11
+
12
+ desc "Generate a complete account-scoped resource inside a Lesli engine"
13
+
14
+ argument :attributes,
15
+ type: :array,
16
+ default: [],
17
+ banner: "field:type field:type"
18
+
19
+ class_option :skip_operator,
20
+ type: :boolean,
21
+ default: false,
22
+ desc: "Do not generate the resource operator"
23
+
24
+ class_option :skip_views,
25
+ type: :boolean,
26
+ default: false,
27
+ desc: "Do not generate HTML views"
28
+
29
+ class_option :skip_tests,
30
+ type: :boolean,
31
+ default: false,
32
+ desc: "Do not generate tests"
33
+
34
+ class_option :items,
35
+ type: :array,
36
+ default: [],
37
+ desc: "Shared items to enable: activities attachments discussions tasks"
38
+
39
+ class_option :migration_namespace,
40
+ type: :numeric,
41
+ desc: "Two-digit Lesli migration feature namespace"
42
+
43
+ source_root File.expand_path("templates", __dir__)
44
+
45
+ def validate_engine
46
+ raise Thor::Error, "Missing engine account model: #{account_model_path}" unless account_model_path.file?
47
+ raise Thor::Error, "Missing engine routes file: #{routes_path}" unless routes_path.file?
48
+
49
+ unsupported_items = selected_items - ALLOWED_ITEMS
50
+ raise Thor::Error, "Unsupported Lesli items: #{unsupported_items.join(', ')}" if unsupported_items.any?
51
+
52
+ conflicting_migration = migration_with_same_version
53
+ return unless conflicting_migration
54
+
55
+ raise Thor::Error, <<~MESSAGE.squish
56
+ Migration version #{migration_version} already belongs to
57
+ #{conflicting_migration.basename}. Choose another --migration-namespace.
58
+ MESSAGE
59
+ end
60
+
61
+ def create_model
62
+ template "model.rb.tt", model_path
63
+ end
64
+
65
+ def create_migration
66
+ template "migration.rb.tt", migration_path
67
+ end
68
+
69
+ def create_service
70
+ template "service.rb.tt", service_path
71
+ end
72
+
73
+ def create_operator
74
+ return if options[:skip_operator]
75
+
76
+ template "operator.rb.tt", operator_path
77
+ end
78
+
79
+ def create_controller
80
+ template "controller.rb.tt", controller_path
81
+ end
82
+
83
+ def create_views
84
+ return if options[:skip_views]
85
+
86
+ template "views/_form.html.erb.tt", views_path.join("_form.html.erb")
87
+ template "views/index.html.erb.tt", views_path.join("index.html.erb")
88
+ template "views/show.html.erb.tt", views_path.join("show.html.erb")
89
+ template "views/new.html.erb.tt", views_path.join("new.html.erb")
90
+ template "views/edit.html.erb.tt", views_path.join("edit.html.erb")
91
+ end
92
+
93
+ def create_locale
94
+ template "locale.en.yml.tt", locale_path
95
+ end
96
+
97
+ def create_tests
98
+ return if options[:skip_tests]
99
+
100
+ template "tests/model_test.rb.tt", model_test_path
101
+ template "tests/service_test.rb.tt", service_test_path
102
+ template "tests/controller_test.rb.tt", controller_test_path
103
+ template "tests/operator_test.rb.tt", operator_test_path unless options[:skip_operator]
104
+ end
105
+
106
+ def add_account_association
107
+ association = <<~RUBY.indent(8)
108
+ has_many :#{resource_collection_name},
109
+ class_name: "#{namespaced_resource_class_name}",
110
+ foreign_key: :account_id,
111
+ dependent: :destroy
112
+ RUBY
113
+
114
+ update_class_file(account_model_path, "Account", association, "has_many :#{resource_collection_name}")
115
+ end
116
+
117
+ def add_resource_route
118
+ route = " resources :#{resource_collection_name}\n"
119
+ update_routes_file(route)
120
+ end
121
+
122
+ private
123
+
124
+ def update_class_file(path, class_name, content, marker)
125
+ existing_content = path.read
126
+ return if behavior != :revoke && existing_content.include?(marker)
127
+
128
+ inject_into_class path, class_name, content
129
+ end
130
+
131
+ def update_routes_file(route)
132
+ existing_content = routes_path.read
133
+ return if behavior != :revoke && existing_content.include?(route.strip)
134
+
135
+ inject_into_file routes_path, route, after: /routes\.draw do\s*\n/
136
+ end
137
+
138
+ def model_path
139
+ engine_root.join("app/models", engine_name, "#{resource_name}.rb")
140
+ end
141
+
142
+ def service_path
143
+ engine_root.join("app/services", engine_name, "#{resource_name}_service.rb")
144
+ end
145
+
146
+ def operator_path
147
+ engine_root.join("app/operators", engine_name, "#{resource_name}_operator.rb")
148
+ end
149
+
150
+ def controller_path
151
+ engine_root.join("app/controllers", engine_name, "#{resource_collection_name}_controller.rb")
152
+ end
153
+
154
+ def views_path
155
+ engine_root.join("app/views", engine_name, resource_collection_name)
156
+ end
157
+
158
+ def locale_path
159
+ engine_root.join("config/locales", "#{engine_name}.#{resource_name}.en.yml")
160
+ end
161
+
162
+ def model_test_path
163
+ engine_root.join("test/models", engine_name, "#{resource_name}_test.rb")
164
+ end
165
+
166
+ def service_test_path
167
+ engine_root.join("test/services", engine_name, "#{resource_name}_service_test.rb")
168
+ end
169
+
170
+ def operator_test_path
171
+ engine_root.join("test/operators", engine_name, "#{resource_name}_operator_test.rb")
172
+ end
173
+
174
+ def controller_test_path
175
+ engine_root.join("test/controllers", engine_name, "#{resource_collection_name}_controller_test.rb")
176
+ end
177
+
178
+ def migration_path
179
+ existing_resource_migration ||
180
+ migration_directory.join("#{migration_version}_create_#{table_name}.rb")
181
+ end
182
+
183
+ def existing_resource_migration
184
+ @existing_resource_migration ||= begin
185
+ pattern = engine_root.join("db/migrate/**/*_create_#{table_name}.rb")
186
+ path = Dir[pattern.to_s].sort.first
187
+ Pathname.new(path) if path
188
+ end
189
+ end
190
+
191
+ def migration_directory
192
+ account_migration_path.dirname
193
+ end
194
+
195
+ def account_migration_path
196
+ @account_migration_path ||= begin
197
+ pattern = engine_root.join("db/migrate/**/*_create_#{account_table_name}.rb")
198
+ path = Dir[pattern.to_s].sort.find do |candidate|
199
+ File.basename(candidate).match?(/\A\d{10}_/)
200
+ end
201
+
202
+ raise Thor::Error, "Could not find the versioned #{account_table_name} migration" unless path
203
+
204
+ Pathname.new(path)
205
+ end
206
+ end
207
+
208
+ def migration_version
209
+ @migration_version ||= begin
210
+ return existing_resource_migration.basename.to_s.first(10) if existing_resource_migration
211
+
212
+ "#{engine_migration_prefix}#{migration_namespace_code}0110"
213
+ end
214
+ end
215
+
216
+ def migration_with_same_version
217
+ pattern = engine_root.join("db/migrate/**/#{migration_version}_*.rb")
218
+
219
+ Dir[pattern.to_s].map { |path| Pathname.new(path) }.find do |path|
220
+ path != existing_resource_migration
221
+ end
222
+ end
223
+
224
+ def engine_migration_prefix
225
+ account_migration_path.basename.to_s.first(4)
226
+ end
227
+
228
+ def migration_namespace_code
229
+ namespace = options[:migration_namespace]&.to_i
230
+ namespace ||= next_migration_namespace
231
+
232
+ unless namespace.between?(1, 99)
233
+ raise Thor::Error, "Migration namespace must be between 1 and 99"
234
+ end
235
+
236
+ namespace.to_s.rjust(2, "0")
237
+ end
238
+
239
+ def next_migration_namespace
240
+ pattern = engine_root.join("db/migrate/**/*.rb")
241
+ namespaces = Dir[pattern.to_s].filter_map do |path|
242
+ version = File.basename(path)[/\A\d{10}/]
243
+ next unless version&.start_with?(engine_migration_prefix)
244
+
245
+ version[4, 2].to_i
246
+ end
247
+
248
+ [namespaces.max.to_i + 1, 1].max
249
+ end
250
+
251
+ def migration_class_name
252
+ "Create#{engine_name.camelize}#{resource_collection_name.camelize}"
253
+ end
254
+
255
+ def database_attributes
256
+ attributes.reject do |attribute|
257
+ attribute.virtual? || %w[account account_id deleted_at created_at updated_at].include?(attribute.name)
258
+ end
259
+ end
260
+
261
+ def selected_items
262
+ @selected_items ||= Array(options[:items]).map(&:to_s).map(&:downcase).uniq.sort
263
+ end
264
+
265
+ def item_enabled?(name)
266
+ selected_items.include?(name.to_s)
267
+ end
268
+
269
+ def form_attributes
270
+ attributes.reject { |attribute| attribute.name == "id" }
271
+ end
272
+
273
+ def index_attributes
274
+ form_attributes.reject(&:virtual?)
275
+ end
276
+
277
+ def operator_class_name
278
+ "#{resource_class_name}Operator"
279
+ end
280
+
281
+ def valid_attribute_pairs
282
+ attributes.filter_map do |attribute|
283
+ next if attribute.reference? || attribute.virtual?
284
+
285
+ [attribute.column_name, attribute.default]
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= controller_class_name %>Controller < ApplicationController
5
+ before_action :<%= set_resource_method_name %>, only: %i[show edit update destroy]
6
+
7
+ def index
8
+ <%= resource_collection_instance %> = respond_with_pagination(
9
+ <%= service_class_name %>.new(current_user, query).index
10
+ )
11
+ end
12
+
13
+ def show
14
+ <%= resource_instance %> = <%= resource_instance %>_service.show
15
+ end
16
+
17
+ def new
18
+ <%= resource_instance %> = <%= resource_class_name %>.new
19
+ end
20
+
21
+ def edit
22
+ end
23
+
24
+ def create
25
+ service = <%= service_class_name %>.new(current_user, query).create(<%= params_method_name %>)
26
+ <%= resource_instance %> = service.result
27
+
28
+ if service.successful?
29
+ respond_with_lesli(
30
+ turbo: stream_redirection(<%= resource_name %>_path(<%= resource_instance %>)),
31
+ json: <%= resource_instance %>,
32
+ redirect: <%= resource_name %>_path(<%= resource_instance %>)
33
+ )
34
+ else
35
+ respond_with_lesli(
36
+ turbo: stream_notification_danger(service.errors_as_sentence),
37
+ json: { errors: service.errors },
38
+ html: :new,
39
+ status: :unprocessable_entity
40
+ )
41
+ end
42
+ end
43
+
44
+ def update
45
+ service = <%= resource_instance %>_service.update(<%= params_method_name %>)
46
+ <%= resource_instance %> = service.result
47
+
48
+ if service.successful?
49
+ respond_with_lesli(
50
+ turbo: stream_notification_success(t(".<%= resource_name %>_updated")),
51
+ json: <%= resource_instance %>,
52
+ redirect: <%= resource_name %>_path(<%= resource_instance %>)
53
+ )
54
+ else
55
+ respond_with_lesli(
56
+ turbo: stream_notification_danger(service.errors_as_sentence),
57
+ json: { errors: service.errors },
58
+ html: :edit,
59
+ status: :unprocessable_entity
60
+ )
61
+ end
62
+ end
63
+
64
+ def destroy
65
+ service = <%= resource_instance %>_service.destroy
66
+
67
+ if service.successful?
68
+ respond_with_lesli(
69
+ turbo: stream_redirection(<%= resource_collection_name %>_path),
70
+ json: nil,
71
+ redirect: <%= resource_collection_name %>_path
72
+ )
73
+ else
74
+ respond_with_lesli(
75
+ turbo: stream_notification_danger(service.errors_as_sentence),
76
+ json: { errors: service.errors },
77
+ status: :unprocessable_entity
78
+ )
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def <%= set_resource_method_name %>
85
+ <%= resource_instance %>_service = <%= service_class_name %>.new(current_user, query).find(id: params[:id])
86
+ return respond_with_not_found unless <%= resource_instance %>_service.found?
87
+
88
+ <%= resource_instance %> = <%= resource_instance %>_service.result
89
+ end
90
+
91
+ def <%= params_method_name %>
92
+ params.require(:<%= resource_name %>).permit(
93
+ <% permitted_attributes.each_with_index do |attribute, index| -%>
94
+ :<%= attribute %><%= "," unless index == permitted_attributes.length - 1 %>
95
+ <% end -%>
96
+ )
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,13 @@
1
+ en:
2
+ <%= engine_name %>:
3
+ <%= resource_collection_name %>:
4
+ index:
5
+ title: "<%= resource_collection_name.humanize %>"
6
+ show:
7
+ title: "<%= resource_class_name %>"
8
+ new:
9
+ title: "New <%= resource_class_name %>"
10
+ edit:
11
+ title: "Edit <%= resource_class_name %>"
12
+ update:
13
+ <%= resource_name %>_updated: "<%= resource_class_name %> updated successfully"
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= migration_class_name %> < ActiveRecord::Migration[8.1]
4
+ def change
5
+ create_table :<%= table_name %> do |t|
6
+ <% database_attributes.each do |attribute| -%>
7
+ <% if attribute.reference? -%>
8
+ t.references :<%= attribute.name %><%= attribute.inject_options %>
9
+ <% elsif attribute.password_digest? -%>
10
+ t.string :password_digest<%= attribute.inject_options %>
11
+ <% elsif attribute.token? -%>
12
+ t.string :<%= attribute.column_name %><%= attribute.inject_options %>
13
+ <% else -%>
14
+ t.<%= attribute.type %> :<%= attribute.column_name %><%= attribute.inject_options %>
15
+ <% end -%>
16
+ <% end -%>
17
+ t.datetime :deleted_at, index: true
18
+ t.timestamps
19
+ end
20
+
21
+ add_reference(
22
+ :<%= table_name %>,
23
+ :account,
24
+ null: false,
25
+ foreign_key: { to_table: :<%= account_table_name %> }
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= resource_class_name %> < Lesli::ApplicationLesliRecord
5
+ belongs_to :account, class_name: "<%= engine_namespace %>::Account"
6
+ <% attributes.select(&:reference?).each do |attribute| -%>
7
+ belongs_to :<%= attribute.name %>, optional: true
8
+ <% end -%>
9
+ <% attributes.select(&:rich_text?).each do |attribute| -%>
10
+ has_rich_text :<%= attribute.name %>
11
+ <% end -%>
12
+ <% attributes.select(&:attachment?).each do |attribute| -%>
13
+ has_one_attached :<%= attribute.name %>
14
+ <% end -%>
15
+ <% attributes.select(&:attachments?).each do |attribute| -%>
16
+ has_many_attached :<%= attribute.name %>
17
+ <% end -%>
18
+ <% if selected_items.any? -%>
19
+
20
+ # Shared resource items
21
+ <% selected_items.each do |item| -%>
22
+ include Lesli::Items::<%= item.camelize %>
23
+ <% end -%>
24
+
25
+ def lesli_item_account
26
+ account
27
+ end
28
+
29
+ def lesli_item_accessible_by?(user)
30
+ <% if engine_namespace == "Lesli" -%>
31
+ user.present? && account == user.account
32
+ <% else -%>
33
+ user.present? && account.account == user.account
34
+ <% end -%>
35
+ end
36
+ <% end -%>
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= engine_namespace %>
4
+ # Add explicit non-CRUD operations for <%= resource_class_name %> here.
5
+ class <%= operator_class_name %>
6
+ def initialize(<%= resource_name %>:, actor:)
7
+ @<%= resource_name %> = <%= resource_name %>
8
+ @actor = actor
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :<%= resource_name %>, :actor
14
+ end
15
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= service_class_name %> < Lesli::ApplicationLesliService
5
+ def find(id:)
6
+ super(resources.find_by(id: id))
7
+ end
8
+
9
+ def index
10
+ resources
11
+ .order(id: :desc)
12
+ .page(query.dig(:pagination, :page))
13
+ .per(query.dig(:pagination, :perPage))
14
+ end
15
+
16
+ def show
17
+ resource
18
+ end
19
+
20
+ def create(attributes)
21
+ self.resource = resources.new(attributes)
22
+
23
+ unless resource.save
24
+ error(resource.errors.full_messages.to_sentence)
25
+ end
26
+
27
+ self
28
+ end
29
+
30
+ def update(attributes)
31
+ unless resource.update(attributes)
32
+ error(resource.errors.full_messages.to_sentence)
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ def destroy
39
+ unless resource.destroy
40
+ error(resource.errors.full_messages.to_sentence)
41
+ end
42
+
43
+ self
44
+ end
45
+
46
+ private
47
+
48
+ def resources
49
+ <%= account_resource_scope %>
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ require "test_helper"
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= controller_class_name %>ControllerTest < ActiveSupport::TestCase
5
+ test "defines the complete resource routes" do
6
+ route_names = <%= engine_namespace %>::Engine.routes.routes.filter_map(&:name)
7
+
8
+ assert_includes route_names, "<%= resource_collection_name %>"
9
+ assert_includes route_names, "<%= resource_name %>"
10
+ assert_includes route_names, "new_<%= resource_name %>"
11
+ assert_includes route_names, "edit_<%= resource_name %>"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= resource_class_name %>Test < ActiveSupport::TestCase
5
+ test "inherits from the shared Lesli record" do
6
+ assert_operator <%= resource_class_name %>, :<, Lesli::ApplicationLesliRecord
7
+ end
8
+
9
+ test "belongs to the local engine account" do
10
+ account = <%= resource_class_name %>.reflect_on_association(:account)
11
+
12
+ assert_equal :belongs_to, account&.macro
13
+ assert_equal "<%= engine_namespace %>::Account", account&.class_name
14
+ end
15
+ <% if selected_items.any? -%>
16
+
17
+ test "includes the configured shared items" do
18
+ <% selected_items.each do |item| -%>
19
+ assert_includes <%= resource_class_name %>.ancestors, Lesli::Items::<%= item.camelize %>
20
+ <% end -%>
21
+ end
22
+ <% end -%>
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= operator_class_name %>Test < ActiveSupport::TestCase
5
+ test "is a plain Ruby resource operator" do
6
+ operator = <%= operator_class_name %>.new(
7
+ <%= resource_name %>: Object.new,
8
+ actor: Object.new
9
+ )
10
+
11
+ assert_instance_of <%= operator_class_name %>, operator
12
+ refute_operator <%= operator_class_name %>, :<, Lesli::ApplicationLesliService
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require "test_helper"
2
+
3
+ module <%= engine_namespace %>
4
+ class <%= service_class_name %>Test < ActiveSupport::TestCase
5
+ test "inherits from the Lesli service contract" do
6
+ assert_operator <%= service_class_name %>, :<, Lesli::ApplicationLesliService
7
+ end
8
+
9
+ test "implements the complete resource CRUD contract" do
10
+ operations = %i[find index show create update destroy]
11
+
12
+ operations.each do |operation|
13
+ assert_includes <%= service_class_name %>.instance_methods(false), operation
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ <%%= form_with(model: <%= resource_instance %>, builder: LesliView::Forms::Builder) do |form| %>
2
+ <%%= form.fieldset do %>
3
+ <% form_attributes.each do |attribute| -%>
4
+ <% if attribute.rich_text? -%>
5
+ <%%= form.field_control_textarea_rich(:<%= attribute.name %>, label: false) %>
6
+ <% elsif attribute.type == :text -%>
7
+ <%%= form.field_control_textarea(:<%= attribute.name %>, label: false) %>
8
+ <% elsif attribute.reference? -%>
9
+ <%%= form.field_control_select(:<%= attribute.column_name %>, []) %>
10
+ <% elsif !attribute.attachment? && !attribute.attachments? -%>
11
+ <%%= form.field_control(:<%= attribute.column_name %>) %>
12
+ <% end -%>
13
+ <% end -%>
14
+
15
+ <%%= form.field_control_submit %>
16
+ <%% end %>
17
+ <%% end %>
@@ -0,0 +1,4 @@
1
+ <%%= render(LesliView::Layout::Container.new("edit-<%= resource_name %>")) do %>
2
+ <%%= render(LesliView::Components::Header.new(t("<%= engine_name %>.<%= resource_collection_name %>.edit.title"))) %>
3
+ <%%= render("form") %>
4
+ <%% end %>
@@ -0,0 +1,22 @@
1
+ <%% columns = [
2
+ <% if index_attributes.empty? -%>
3
+ { label: "ID", field: "id" }
4
+ <% else -%>
5
+ <% index_attributes.each_with_index do |attribute, index| -%>
6
+ { label: "<%= attribute.human_name %>", field: "<%= attribute.column_name %>" }<%= "," unless index == index_attributes.length - 1 %>
7
+ <% end -%>
8
+ <% end -%>
9
+ ] %>
10
+
11
+ <%%= render(LesliView::Layout::Container.new("<%= engine_domain_name %>-<%= resource_collection_name %>")) do %>
12
+ <%%= render(LesliView::Components::Header.new(
13
+ t("<%= engine_name %>.<%= resource_collection_name %>.index.title"),
14
+ new_path: new_<%= resource_name %>_path
15
+ )) %>
16
+ <%%= render(LesliView::Components::Toolbar.new) %>
17
+ <%%= render(LesliView::Elements::Table.new(
18
+ columns: columns,
19
+ records: <%= resource_collection_instance %>.dig(:records),
20
+ link: -> (<%= resource_name %>) { <%= resource_name %>_path(<%= resource_name %>) }
21
+ )) %>
22
+ <%% end %>
@@ -0,0 +1,4 @@
1
+ <%%= render(LesliView::Layout::Container.new("new-<%= resource_name %>")) do %>
2
+ <%%= render(LesliView::Components::Header.new(t("<%= engine_name %>.<%= resource_collection_name %>.new.title"))) %>
3
+ <%%= render("form") %>
4
+ <%% end %>