super 0.0.5 → 0.0.10

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +4 -1
  3. data/CONTRIBUTING.md +56 -0
  4. data/README.md +68 -38
  5. data/STABILITY.md +50 -0
  6. data/app/assets/javascripts/super/application.js +1170 -359
  7. data/app/assets/stylesheets/super/application.css +78105 -50441
  8. data/app/controllers/super/application_controller.rb +44 -52
  9. data/app/helpers/super/form_builder_helper.rb +23 -0
  10. data/app/views/layouts/super/application.html.erb +26 -6
  11. data/app/views/super/application/{_resources_header.html.erb → _collection_header.html.erb} +5 -6
  12. data/app/views/super/application/_display_rich_text.html.erb +1 -0
  13. data/app/views/super/application/_filter.html.erb +14 -0
  14. data/app/views/super/application/_filter_type_select.html.erb +18 -0
  15. data/app/views/super/application/_filter_type_text.html.erb +16 -0
  16. data/app/views/super/application/_filter_type_timestamp.html.erb +23 -0
  17. data/app/views/super/application/_flash.html.erb +13 -13
  18. data/app/views/super/application/_form_field__destroy.html.erb +1 -9
  19. data/app/views/super/application/_form_field_checkbox.html.erb +1 -0
  20. data/app/views/super/application/_form_field_rich_text_area.html.erb +1 -0
  21. data/app/views/super/application/_form_field_select.html.erb +1 -23
  22. data/app/views/super/application/_form_field_text.html.erb +1 -13
  23. data/app/views/super/application/_form_has_many.html.erb +1 -1
  24. data/app/views/super/application/{_resource_header.html.erb → _member_header.html.erb} +6 -6
  25. data/app/views/super/application/_super_layout.html.erb +12 -17
  26. data/app/views/super/application/_super_pagination.html.erb +16 -0
  27. data/app/views/super/application/_super_panel.html.erb +3 -7
  28. data/app/views/super/application/_super_schema_display_actions.html.erb +5 -0
  29. data/app/views/super/application/_super_schema_display_index.html.erb +24 -0
  30. data/app/views/super/application/_super_schema_display_show.html.erb +8 -0
  31. data/app/views/super/application/_super_schema_form.html.erb +15 -0
  32. data/app/views/super/application/edit.html.erb +2 -6
  33. data/app/views/super/application/index.html.erb +2 -6
  34. data/app/views/super/application/new.html.erb +2 -6
  35. data/app/views/super/application/show.html.erb +2 -6
  36. data/app/views/super/feather/{_chevron_down.svg → _chevron_down.html} +0 -0
  37. data/config/locales/en.yml +5 -0
  38. data/docs/README.md +4 -2
  39. data/docs/action_text.md +48 -0
  40. data/docs/cheat.md +41 -0
  41. data/docs/faq.md +3 -3
  42. data/docs/installation.md +21 -0
  43. data/docs/quick_start.md +1 -16
  44. data/docs/webpacker.md +13 -5
  45. data/frontend/super-frontend/dist/application.css +78105 -50441
  46. data/frontend/super-frontend/dist/application.js +1170 -359
  47. data/lib/generators/super/action_text/USAGE +23 -0
  48. data/lib/generators/super/action_text/action_text_generator.rb +30 -0
  49. data/lib/generators/super/action_text/templates/pack_super_action_text.css +23 -0
  50. data/lib/generators/super/action_text/templates/pack_super_action_text.js +4 -0
  51. data/lib/generators/super/install/install_generator.rb +16 -0
  52. data/lib/generators/super/resource/templates/resources_controller.rb.tt +1 -31
  53. data/lib/generators/super/webpacker/USAGE +5 -4
  54. data/lib/generators/super/webpacker/webpacker_generator.rb +3 -2
  55. data/lib/super.rb +21 -3
  56. data/lib/super/action_inquirer.rb +2 -2
  57. data/lib/super/assets.rb +112 -38
  58. data/lib/super/client_error.rb +43 -0
  59. data/lib/super/compatibility.rb +13 -1
  60. data/lib/super/configuration.rb +21 -69
  61. data/lib/super/controls.rb +9 -116
  62. data/lib/super/controls/optional.rb +79 -0
  63. data/lib/super/controls/required.rb +13 -0
  64. data/lib/super/controls/steps.rb +114 -0
  65. data/lib/super/display.rb +66 -3
  66. data/lib/super/display/guesser.rb +34 -0
  67. data/lib/super/display/schema_types.rb +61 -25
  68. data/lib/super/engine.rb +9 -1
  69. data/lib/super/error.rb +17 -9
  70. data/lib/super/filter.rb +12 -0
  71. data/lib/super/filter/form_object.rb +97 -0
  72. data/lib/super/filter/guesser.rb +30 -0
  73. data/lib/super/filter/operator.rb +103 -0
  74. data/lib/super/filter/plugin.rb +47 -0
  75. data/lib/super/filter/schema_types.rb +112 -0
  76. data/lib/super/form.rb +35 -0
  77. data/lib/super/form/builder.rb +204 -0
  78. data/lib/super/form/guesser.rb +27 -0
  79. data/lib/super/form/inline_errors.rb +26 -0
  80. data/lib/super/form/schema_types.rb +29 -22
  81. data/lib/super/form/strong_params.rb +29 -0
  82. data/lib/super/layout.rb +28 -0
  83. data/lib/super/link.rb +55 -32
  84. data/lib/super/pagination.rb +55 -0
  85. data/lib/super/panel.rb +13 -0
  86. data/lib/super/partial.rb +12 -0
  87. data/lib/super/partial/resolving.rb +24 -0
  88. data/lib/super/plugin.rb +34 -63
  89. data/lib/super/schema.rb +12 -22
  90. data/lib/super/schema/common.rb +25 -0
  91. data/lib/super/schema/guesser.rb +77 -0
  92. data/lib/super/version.rb +1 -1
  93. data/lib/super/view_helper.rb +1 -20
  94. metadata +90 -33
  95. data/app/helpers/super/application_helper.rb +0 -32
  96. data/app/views/super/application/_form.html.erb +0 -17
  97. data/app/views/super/application/_form_inline_errors.html.erb +0 -10
  98. data/app/views/super/application/_index.html.erb +0 -45
  99. data/app/views/super/application/_show.html.erb +0 -10
  100. data/docs/controls.md +0 -39
  101. data/frontend/super-frontend/build.js +0 -36
  102. data/frontend/super-frontend/package.json +0 -21
  103. data/frontend/super-frontend/postcss.config.js +0 -6
  104. data/frontend/super-frontend/src/javascripts/super/application.ts +0 -18
  105. data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +0 -21
  106. data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +0 -1
  107. data/frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts +0 -15
  108. data/frontend/super-frontend/src/stylesheets/super/application.css +0 -77
  109. data/frontend/super-frontend/tailwind.config.js +0 -9
  110. data/frontend/super-frontend/tsconfig.json +0 -13
  111. data/frontend/super-frontend/yarn.lock +0 -5540
  112. data/lib/super/step.rb +0 -36
  113. data/lib/tasks/super_tasks.rake +0 -4
@@ -5,26 +5,10 @@ module Super
5
5
  #
6
6
  # The various "schema types" are likely of more interest
7
7
  class Schema
8
- # @param schema_type [Display::SchemaTypes, Form::SchemaTypes]
9
- def initialize(schema_type)
10
- @schema_type = schema_type
11
- @fields = Fields.new
12
-
13
- if @schema_type.respond_to?(:setup)
14
- @schema_type.setup(fields: @fields)
15
- end
16
-
17
- if block_given?
18
- yield(@fields, @schema_type)
19
- end
20
- end
21
-
22
- attr_reader :fields
23
-
24
- def field_keys
25
- fields.keys
26
- end
27
-
8
+ # This class can be thought of as a Hash, where the keys usually refer to
9
+ # the model's column name and the value refers to the column type. Note
10
+ # though that this isn't always the case—different `SchemaTypes` can do
11
+ # whatever makes sense in their context
28
12
  class Fields
29
13
  include Enumerable
30
14
 
@@ -44,9 +28,13 @@ module Super
44
28
  @backing.keys
45
29
  end
46
30
 
47
- def each
31
+ def values
32
+ @backing.values
33
+ end
34
+
35
+ def each(&block)
48
36
  if block_given?
49
- return @backing.each(&Proc.new)
37
+ return @backing.each(&block)
50
38
  end
51
39
 
52
40
  enum_for(:each)
@@ -65,6 +53,8 @@ module Super
65
53
  inside = {}
66
54
  @backing = inside
67
55
  yield
56
+ return inside
57
+ ensure
68
58
  @backing = outside
69
59
  inside
70
60
  end
@@ -0,0 +1,25 @@
1
+ module Super
2
+ class Schema
3
+ module Common
4
+ def each_attribute_name
5
+ if block_given?
6
+ @fields.keys.each do |key|
7
+ yield(key)
8
+ end
9
+ end
10
+
11
+ enum_for(:each_attribute_name)
12
+ end
13
+
14
+ def each_attribute
15
+ if block_given?
16
+ @fields.each do |key, value|
17
+ yield(key, value)
18
+ end
19
+ end
20
+
21
+ enum_for(:each_attribute)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,77 @@
1
+ module Super
2
+ class Schema
3
+ class Guesser
4
+ def initialize(model:, fields:, type:)
5
+ @model = model
6
+ @fields = fields
7
+ @type = type
8
+ @rejects = []
9
+ end
10
+
11
+ def limit
12
+ @limit = yield
13
+ self
14
+ end
15
+
16
+ def reject(&block)
17
+ @rejects.push(block)
18
+ self
19
+ end
20
+
21
+ def ignore_foreign_keys
22
+ @rejects.push(-> (attribute_name) { is_foreign_key[attribute_name] })
23
+ self
24
+ end
25
+
26
+ def assign_type(&block)
27
+ @assign_type = block
28
+ self
29
+ end
30
+
31
+ def call
32
+ result = sorted_attribute_names
33
+ result = @rejects.reduce(result) do |intermediary_result, rejection_proc|
34
+ intermediary_result.reject(&rejection_proc)
35
+ end
36
+
37
+ result = result.first(@limit) if @limit && @limit != Float::INFINITY
38
+
39
+ result.each do |name|
40
+ @fields[name] = @assign_type.call(name)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def sorted_attribute_names
47
+ @model
48
+ .attribute_names
49
+ .sort_by { |name| sort_weight[name] }
50
+ end
51
+
52
+ def sort_weight
53
+ @sort_weight ||= Hash.new do |hash, name|
54
+ hash[name] =
55
+ case name
56
+ when "id" then 0
57
+ when "title" then 1000
58
+ when "name" then 1300
59
+ when "created_at" then 9500
60
+ when "updated_at" then 9750
61
+ else
62
+ 2000 + hash.size
63
+ end
64
+ end
65
+ end
66
+
67
+ def is_foreign_key
68
+ @is_foreign_key ||=
69
+ @model
70
+ .reflect_on_all_associations
71
+ .select { |a| a.macro == :belongs_to }
72
+ .map { |a| [a.foreign_key, true] }
73
+ .to_h
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module Super
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -14,30 +14,11 @@ module Super
14
14
  raise %(Expected exactly two elements (["class", some_condition]), got: #{c.inspect})
15
15
  end
16
16
 
17
- c if c.last
17
+ c.first if c.last
18
18
  end
19
19
  end
20
20
 
21
21
  result.compact.join(" ")
22
22
  end
23
-
24
- def errors_accounting_for_reflections(model_instance, column_or_association)
25
- errable_fields(model_instance, column_or_association)
26
- .flat_map { |field| Compatability.rails_50_errable_fields(field) }
27
- .flat_map { |field| model_instance.errors.full_messages_for(field) }
28
- .uniq
29
- end
30
-
31
- def errable_fields(model_instance, column_or_association)
32
- column_or_association = column_or_association.to_s
33
- reflection = model_instance.class.reflect_on_association(column_or_association)
34
- reflection ||= model_instance.class.reflections.values.find { |r| r.foreign_key == column_or_association }
35
-
36
- if reflection
37
- [reflection.name.to_s, reflection.foreign_key.to_s]
38
- else
39
- [column_or_association]
40
- end
41
- end
42
23
  end
43
24
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-02 00:00:00.000000000 Z
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: capybara
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +84,22 @@ dependencies:
70
84
  name: puma
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.3'
73
90
  - - ">="
74
91
  - !ruby/object:Gem::Version
75
- version: '0'
92
+ version: 4.3.6
76
93
  type: :development
77
94
  prerelease: false
78
95
  version_requirements: !ruby/object:Gem::Requirement
79
96
  requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '4.3'
80
100
  - - ">="
81
101
  - !ruby/object:Gem::Version
82
- version: '0'
102
+ version: 4.3.6
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: sqlite3
85
105
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +184,21 @@ dependencies:
164
184
  - - ">="
165
185
  - !ruby/object:Gem::Version
166
186
  version: '0'
167
- description:
187
+ - !ruby/object:Gem::Dependency
188
+ name: i18n-debug
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ description:
168
202
  email:
169
203
  - engineering@zachahn.com
170
204
  executables: []
@@ -172,57 +206,63 @@ extensions: []
172
206
  extra_rdoc_files: []
173
207
  files:
174
208
  - ".yardopts"
209
+ - CONTRIBUTING.md
175
210
  - LICENSE
176
211
  - README.md
177
212
  - Rakefile
213
+ - STABILITY.md
178
214
  - app/assets/config/super_manifest.js
179
215
  - app/assets/javascripts/super/application.js
180
216
  - app/assets/stylesheets/super/application.css
181
217
  - app/controllers/super/application_controller.rb
182
- - app/helpers/super/application_helper.rb
218
+ - app/helpers/super/form_builder_helper.rb
183
219
  - app/views/layouts/super/application.html.erb
220
+ - app/views/super/application/_collection_header.html.erb
221
+ - app/views/super/application/_display_rich_text.html.erb
222
+ - app/views/super/application/_filter.html.erb
223
+ - app/views/super/application/_filter_type_select.html.erb
224
+ - app/views/super/application/_filter_type_text.html.erb
225
+ - app/views/super/application/_filter_type_timestamp.html.erb
184
226
  - app/views/super/application/_flash.html.erb
185
- - app/views/super/application/_form.html.erb
186
227
  - app/views/super/application/_form_field__destroy.html.erb
228
+ - app/views/super/application/_form_field_checkbox.html.erb
229
+ - app/views/super/application/_form_field_rich_text_area.html.erb
187
230
  - app/views/super/application/_form_field_select.html.erb
188
231
  - app/views/super/application/_form_field_text.html.erb
189
232
  - app/views/super/application/_form_fieldset.html.erb
190
233
  - app/views/super/application/_form_has_many.html.erb
191
234
  - app/views/super/application/_form_has_one.html.erb
192
- - app/views/super/application/_form_inline_errors.html.erb
193
- - app/views/super/application/_index.html.erb
194
- - app/views/super/application/_resource_header.html.erb
195
- - app/views/super/application/_resources_header.html.erb
196
- - app/views/super/application/_show.html.erb
235
+ - app/views/super/application/_member_header.html.erb
197
236
  - app/views/super/application/_super_layout.html.erb
237
+ - app/views/super/application/_super_pagination.html.erb
198
238
  - app/views/super/application/_super_panel.html.erb
239
+ - app/views/super/application/_super_schema_display_actions.html.erb
240
+ - app/views/super/application/_super_schema_display_index.html.erb
241
+ - app/views/super/application/_super_schema_display_show.html.erb
242
+ - app/views/super/application/_super_schema_form.html.erb
199
243
  - app/views/super/application/edit.html.erb
200
244
  - app/views/super/application/index.html.erb
201
245
  - app/views/super/application/new.html.erb
202
246
  - app/views/super/application/nothing.html.erb
203
247
  - app/views/super/application/show.html.erb
204
248
  - app/views/super/feather/README.md
205
- - app/views/super/feather/_chevron_down.svg
249
+ - app/views/super/feather/_chevron_down.html
250
+ - config/locales/en.yml
206
251
  - config/routes.rb
207
252
  - docs/README.md
208
- - docs/controls.md
253
+ - docs/action_text.md
254
+ - docs/cheat.md
209
255
  - docs/faq.md
256
+ - docs/installation.md
210
257
  - docs/quick_start.md
211
258
  - docs/webpacker.md
212
259
  - docs/yard_customizations.rb
213
- - frontend/super-frontend/build.js
214
260
  - frontend/super-frontend/dist/application.css
215
261
  - frontend/super-frontend/dist/application.js
216
- - frontend/super-frontend/package.json
217
- - frontend/super-frontend/postcss.config.js
218
- - frontend/super-frontend/src/javascripts/super/application.ts
219
- - frontend/super-frontend/src/javascripts/super/apply_template_controller.ts
220
- - frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts
221
- - frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts
222
- - frontend/super-frontend/src/stylesheets/super/application.css
223
- - frontend/super-frontend/tailwind.config.js
224
- - frontend/super-frontend/tsconfig.json
225
- - frontend/super-frontend/yarn.lock
262
+ - lib/generators/super/action_text/USAGE
263
+ - lib/generators/super/action_text/action_text_generator.rb
264
+ - lib/generators/super/action_text/templates/pack_super_action_text.css
265
+ - lib/generators/super/action_text/templates/pack_super_action_text.js
226
266
  - lib/generators/super/install/USAGE
227
267
  - lib/generators/super/install/install_generator.rb
228
268
  - lib/generators/super/install/templates/base_controller.rb.tt
@@ -236,31 +276,48 @@ files:
236
276
  - lib/super.rb
237
277
  - lib/super/action_inquirer.rb
238
278
  - lib/super/assets.rb
279
+ - lib/super/client_error.rb
239
280
  - lib/super/compatibility.rb
240
281
  - lib/super/configuration.rb
241
282
  - lib/super/controls.rb
283
+ - lib/super/controls/optional.rb
284
+ - lib/super/controls/required.rb
285
+ - lib/super/controls/steps.rb
242
286
  - lib/super/display.rb
287
+ - lib/super/display/guesser.rb
243
288
  - lib/super/display/schema_types.rb
244
289
  - lib/super/engine.rb
245
290
  - lib/super/error.rb
291
+ - lib/super/filter.rb
292
+ - lib/super/filter/form_object.rb
293
+ - lib/super/filter/guesser.rb
294
+ - lib/super/filter/operator.rb
295
+ - lib/super/filter/plugin.rb
296
+ - lib/super/filter/schema_types.rb
297
+ - lib/super/form.rb
298
+ - lib/super/form/builder.rb
299
+ - lib/super/form/guesser.rb
300
+ - lib/super/form/inline_errors.rb
246
301
  - lib/super/form/schema_types.rb
302
+ - lib/super/form/strong_params.rb
247
303
  - lib/super/layout.rb
248
304
  - lib/super/link.rb
249
305
  - lib/super/navigation/automatic.rb
250
306
  - lib/super/pagination.rb
251
307
  - lib/super/panel.rb
252
308
  - lib/super/partial.rb
309
+ - lib/super/partial/resolving.rb
253
310
  - lib/super/plugin.rb
254
311
  - lib/super/schema.rb
255
- - lib/super/step.rb
312
+ - lib/super/schema/common.rb
313
+ - lib/super/schema/guesser.rb
256
314
  - lib/super/version.rb
257
315
  - lib/super/view_helper.rb
258
- - lib/tasks/super_tasks.rake
259
- homepage:
316
+ homepage:
260
317
  licenses:
261
318
  - LGPL-3.0-only
262
319
  metadata: {}
263
- post_install_message:
320
+ post_install_message:
264
321
  rdoc_options: []
265
322
  require_paths:
266
323
  - lib
@@ -275,8 +332,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
332
  - !ruby/object:Gem::Version
276
333
  version: '0'
277
334
  requirements: []
278
- rubygems_version: 3.1.3
279
- signing_key:
335
+ rubygems_version: 3.2.4
336
+ signing_key:
280
337
  specification_version: 4
281
338
  summary: A simple, powerful, zero dependency Rails admin framework
282
339
  test_files: []
@@ -1,32 +0,0 @@
1
- module Super
2
- module ApplicationHelper
3
- def super_resolve_list_for_rendering(partials, block = -> {})
4
- block_result = block.call
5
- if block_result.present?
6
- partials = [block_result, *partials]
7
- end
8
-
9
- partials = partials.map do |partial|
10
- if partial.is_a?(Symbol)
11
- instance_variable_get(partial)
12
- else
13
- partial
14
- end
15
- end
16
-
17
- partials.compact
18
- end
19
-
20
- def super_render_partialish(partialish)
21
- if partialish.respond_to?(:to_partial_path)
22
- if partialish.is_a?(Super::Partial)
23
- render(partialish, partialish.locals)
24
- else
25
- render(partialish)
26
- end
27
- else
28
- partialish
29
- end
30
- end
31
- end
32
- end