super 0.0.6 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -0
  3. data/CONTRIBUTING.md +56 -0
  4. data/README.md +55 -57
  5. data/Rakefile +16 -14
  6. data/STABILITY.md +50 -0
  7. data/app/assets/javascripts/super/application.js +297 -97
  8. data/app/assets/stylesheets/super/application.css +5600 -0
  9. data/app/controllers/super/application_controller.rb +15 -6
  10. data/app/helpers/super/form_builder_helper.rb +25 -0
  11. data/app/views/layouts/super/application.html.erb +22 -6
  12. data/app/views/super/application/_display_rich_text.html.erb +1 -0
  13. data/app/views/super/application/_filter.html.erb +6 -0
  14. data/app/views/super/application/_filter_type_select.html.erb +21 -0
  15. data/app/views/super/application/_filter_type_text.html.erb +18 -0
  16. data/app/views/super/application/_filter_type_timestamp.html.erb +24 -0
  17. data/app/views/super/application/_form_field__destroy.html.erb +1 -9
  18. data/app/views/super/application/_form_field_checkbox.html.erb +1 -0
  19. data/app/views/super/application/_form_field_rich_text_area.html.erb +1 -0
  20. data/app/views/super/application/_form_field_select.html.erb +1 -23
  21. data/app/views/super/application/_form_field_text.html.erb +1 -13
  22. data/app/views/super/application/_query.html.erb +18 -0
  23. data/app/views/super/application/_sort.html.erb +18 -0
  24. data/app/views/super/application/_sort_expression.html.erb +25 -0
  25. data/app/views/super/application/_super_layout.html.erb +5 -5
  26. data/app/views/super/application/_super_pagination.html.erb +16 -0
  27. data/app/views/super/application/_super_panel.html.erb +2 -2
  28. data/app/views/super/application/_super_schema_display_index.html.erb +9 -24
  29. data/app/views/super/application/_super_schema_display_show.html.erb +4 -4
  30. data/app/views/super/application/_super_schema_form.html.erb +3 -3
  31. data/app/views/super/application/edit.html.erb +2 -6
  32. data/app/views/super/application/index.html.erb +2 -6
  33. data/app/views/super/application/new.html.erb +2 -6
  34. data/app/views/super/application/show.html.erb +2 -6
  35. data/app/views/super/feather/README.md +1 -0
  36. data/app/views/super/feather/_x.html +15 -0
  37. data/config/routes.rb +2 -0
  38. data/docs/README.md +4 -2
  39. data/docs/action_text.md +48 -0
  40. data/docs/cheat.md +8 -8
  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/docs/yard_customizations.rb +2 -0
  46. data/frontend/super-frontend/dist/application.css +5600 -0
  47. data/frontend/super-frontend/dist/application.js +297 -97
  48. data/lib/generators/super/action_text/USAGE +23 -0
  49. data/lib/generators/super/action_text/action_text_generator.rb +32 -0
  50. data/lib/generators/super/action_text/templates/pack_super_action_text.css +23 -0
  51. data/lib/generators/super/action_text/templates/pack_super_action_text.js +4 -0
  52. data/lib/generators/super/install/install_generator.rb +2 -0
  53. data/lib/generators/super/resource/resource_generator.rb +2 -0
  54. data/lib/generators/super/resource/templates/resources_controller.rb.tt +1 -31
  55. data/lib/generators/super/webpacker/USAGE +5 -4
  56. data/lib/generators/super/webpacker/webpacker_generator.rb +5 -2
  57. data/lib/super.rb +23 -2
  58. data/lib/super/action_inquirer.rb +2 -0
  59. data/lib/super/assets.rb +114 -38
  60. data/lib/super/client_error.rb +2 -0
  61. data/lib/super/compatibility.rb +15 -1
  62. data/lib/super/configuration.rb +22 -69
  63. data/lib/super/controls.rb +6 -25
  64. data/lib/super/controls/optional.rb +71 -24
  65. data/lib/super/controls/required.rb +3 -29
  66. data/lib/super/controls/steps.rb +44 -53
  67. data/lib/super/controls/view.rb +55 -0
  68. data/lib/super/display.rb +80 -0
  69. data/lib/super/display/guesser.rb +36 -0
  70. data/lib/super/display/schema_types.rb +28 -33
  71. data/lib/super/engine.rb +11 -1
  72. data/lib/super/error.rb +14 -0
  73. data/lib/super/filter.rb +14 -0
  74. data/lib/super/filter/form_object.rb +94 -0
  75. data/lib/super/filter/guesser.rb +32 -0
  76. data/lib/super/filter/operator.rb +105 -0
  77. data/lib/super/filter/schema_types.rb +114 -0
  78. data/lib/super/form.rb +29 -40
  79. data/lib/super/form/builder.rb +206 -0
  80. data/lib/super/form/guesser.rb +29 -0
  81. data/lib/super/form/inline_errors.rb +28 -0
  82. data/lib/super/form/schema_types.rb +31 -29
  83. data/lib/super/form/strong_params.rb +31 -0
  84. data/lib/super/layout.rb +2 -0
  85. data/lib/super/link.rb +2 -0
  86. data/lib/super/navigation/automatic.rb +2 -0
  87. data/lib/super/pagination.rb +57 -0
  88. data/lib/super/panel.rb +2 -0
  89. data/lib/super/partial.rb +14 -0
  90. data/lib/super/partial/resolving.rb +2 -0
  91. data/lib/super/plugin.rb +36 -63
  92. data/lib/super/query/form_object.rb +48 -0
  93. data/lib/super/schema.rb +2 -24
  94. data/lib/super/schema/common.rb +27 -0
  95. data/lib/super/schema/guesser.rb +79 -0
  96. data/lib/super/sort.rb +110 -0
  97. data/lib/super/version.rb +3 -1
  98. data/lib/super/view_helper.rb +2 -19
  99. metadata +74 -22
  100. data/app/helpers/super/application_helper.rb +0 -39
  101. data/app/views/super/application/_form_inline_errors.html.erb +0 -10
  102. data/frontend/super-frontend/build.js +0 -36
  103. data/frontend/super-frontend/package.json +0 -21
  104. data/frontend/super-frontend/postcss.config.js +0 -6
  105. data/frontend/super-frontend/src/javascripts/super/application.ts +0 -18
  106. data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +0 -19
  107. data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +0 -1
  108. data/frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts +0 -15
  109. data/frontend/super-frontend/src/stylesheets/super/application.css +0 -77
  110. data/frontend/super-frontend/tailwind.config.js +0 -15
  111. data/frontend/super-frontend/tsconfig.json +0 -13
  112. data/frontend/super-frontend/yarn.lock +0 -5448
data/lib/super/sort.rb ADDED
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ module Sort
5
+ class FormObject
6
+ DIRECTIONS = ["asc", "desc"]
7
+
8
+ def initialize(model:, params:, default:, sortable_columns:)
9
+ @model = model
10
+ @params = params.dup
11
+ @default = default
12
+ @sortable_columns = sortable_columns.map(&:to_s)
13
+
14
+ @params.permit!
15
+ end
16
+
17
+ attr_reader :sortable_columns
18
+
19
+ def to_partial_path
20
+ "sort"
21
+ end
22
+
23
+ def exprs
24
+ sanitized_expr_params.map { |ordering| Expression.new(**ordering) }
25
+ end
26
+
27
+ def new_expr
28
+ Expression.new(a: nil, d: :desc)
29
+ end
30
+
31
+ class Expression
32
+ attr_accessor :a # attribute
33
+ attr_accessor :d # direction
34
+
35
+ def initialize(a:, d:)
36
+ @a = a
37
+ @d = d.to_s
38
+ end
39
+
40
+ def with_index(index)
41
+ @index = index
42
+ self
43
+ end
44
+
45
+ # This is for `fields_for` to work
46
+ def id
47
+ @index
48
+ end
49
+
50
+ def persisted?
51
+ false
52
+ end
53
+ end
54
+
55
+ def persisted?
56
+ false
57
+ end
58
+
59
+ def apply_changes(query)
60
+ exprs.each do |expr|
61
+ query = query.order(expr.a => expr.d)
62
+ end
63
+
64
+ query
65
+ end
66
+
67
+ private
68
+
69
+ # Stringifies the values
70
+ def sanitized_expr_params
71
+ seen = {}
72
+ normalized_expr_params
73
+ .each do |p|
74
+ p[:a] = p[:a].presence&.to_s&.strip
75
+ p[:d] = p[:d].presence&.to_s&.strip
76
+ end
77
+ .select { |p| p[:a].present? && DIRECTIONS.include?(p[:d]) }
78
+ .select { |p| @sortable_columns.include?(p[:a]) }
79
+ .select do |p|
80
+ next false if seen.key?(p[:a])
81
+
82
+ seen[p[:a]] = true
83
+ true
84
+ end
85
+ end
86
+
87
+ # Symbolizes the keys
88
+ def normalized_expr_params
89
+ from_params = @params[:exprs]
90
+
91
+ return default_as_query if from_params.nil?
92
+
93
+ if from_params.is_a?(Array)
94
+ return from_params.map(&:to_h).map(&:symbolize_keys)
95
+ end
96
+
97
+ from_params.to_h.values.map(&:symbolize_keys)
98
+ end
99
+
100
+ def default_as_query
101
+ @default.map do |attribute_name, direction|
102
+ {
103
+ a: attribute_name,
104
+ d: direction,
105
+ }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
data/lib/super/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
- VERSION = "0.0.6"
4
+ VERSION = "0.0.11"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  module ViewHelper
3
5
  module_function
@@ -20,24 +22,5 @@ module Super
20
22
 
21
23
  result.compact.join(" ")
22
24
  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
25
  end
43
26
  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.6
4
+ version: 0.0.11
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-12-09 00:00:00.000000000 Z
11
+ date: 2021-03-03 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
@@ -184,7 +198,21 @@ dependencies:
184
198
  - - ">="
185
199
  - !ruby/object:Gem::Version
186
200
  version: '0'
187
- description:
201
+ - !ruby/object:Gem::Dependency
202
+ name: simplecov
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ description:
188
216
  email:
189
217
  - engineering@zachahn.com
190
218
  executables: []
@@ -192,26 +220,38 @@ extensions: []
192
220
  extra_rdoc_files: []
193
221
  files:
194
222
  - ".yardopts"
223
+ - CONTRIBUTING.md
195
224
  - LICENSE
196
225
  - README.md
197
226
  - Rakefile
227
+ - STABILITY.md
198
228
  - app/assets/config/super_manifest.js
199
229
  - app/assets/javascripts/super/application.js
200
230
  - app/assets/stylesheets/super/application.css
201
231
  - app/controllers/super/application_controller.rb
202
- - app/helpers/super/application_helper.rb
232
+ - app/helpers/super/form_builder_helper.rb
203
233
  - app/views/layouts/super/application.html.erb
204
234
  - app/views/super/application/_collection_header.html.erb
235
+ - app/views/super/application/_display_rich_text.html.erb
236
+ - app/views/super/application/_filter.html.erb
237
+ - app/views/super/application/_filter_type_select.html.erb
238
+ - app/views/super/application/_filter_type_text.html.erb
239
+ - app/views/super/application/_filter_type_timestamp.html.erb
205
240
  - app/views/super/application/_flash.html.erb
206
241
  - app/views/super/application/_form_field__destroy.html.erb
242
+ - app/views/super/application/_form_field_checkbox.html.erb
243
+ - app/views/super/application/_form_field_rich_text_area.html.erb
207
244
  - app/views/super/application/_form_field_select.html.erb
208
245
  - app/views/super/application/_form_field_text.html.erb
209
246
  - app/views/super/application/_form_fieldset.html.erb
210
247
  - app/views/super/application/_form_has_many.html.erb
211
248
  - app/views/super/application/_form_has_one.html.erb
212
- - app/views/super/application/_form_inline_errors.html.erb
213
249
  - app/views/super/application/_member_header.html.erb
250
+ - app/views/super/application/_query.html.erb
251
+ - app/views/super/application/_sort.html.erb
252
+ - app/views/super/application/_sort_expression.html.erb
214
253
  - app/views/super/application/_super_layout.html.erb
254
+ - app/views/super/application/_super_pagination.html.erb
215
255
  - app/views/super/application/_super_panel.html.erb
216
256
  - app/views/super/application/_super_schema_display_actions.html.erb
217
257
  - app/views/super/application/_super_schema_display_index.html.erb
@@ -224,27 +264,23 @@ files:
224
264
  - app/views/super/application/show.html.erb
225
265
  - app/views/super/feather/README.md
226
266
  - app/views/super/feather/_chevron_down.html
267
+ - app/views/super/feather/_x.html
227
268
  - config/locales/en.yml
228
269
  - config/routes.rb
229
270
  - docs/README.md
271
+ - docs/action_text.md
230
272
  - docs/cheat.md
231
273
  - docs/faq.md
274
+ - docs/installation.md
232
275
  - docs/quick_start.md
233
276
  - docs/webpacker.md
234
277
  - docs/yard_customizations.rb
235
- - frontend/super-frontend/build.js
236
278
  - frontend/super-frontend/dist/application.css
237
279
  - frontend/super-frontend/dist/application.js
238
- - frontend/super-frontend/package.json
239
- - frontend/super-frontend/postcss.config.js
240
- - frontend/super-frontend/src/javascripts/super/application.ts
241
- - frontend/super-frontend/src/javascripts/super/apply_template_controller.ts
242
- - frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts
243
- - frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts
244
- - frontend/super-frontend/src/stylesheets/super/application.css
245
- - frontend/super-frontend/tailwind.config.js
246
- - frontend/super-frontend/tsconfig.json
247
- - frontend/super-frontend/yarn.lock
280
+ - lib/generators/super/action_text/USAGE
281
+ - lib/generators/super/action_text/action_text_generator.rb
282
+ - lib/generators/super/action_text/templates/pack_super_action_text.css
283
+ - lib/generators/super/action_text/templates/pack_super_action_text.js
248
284
  - lib/generators/super/install/USAGE
249
285
  - lib/generators/super/install/install_generator.rb
250
286
  - lib/generators/super/install/templates/base_controller.rb.tt
@@ -265,11 +301,23 @@ files:
265
301
  - lib/super/controls/optional.rb
266
302
  - lib/super/controls/required.rb
267
303
  - lib/super/controls/steps.rb
304
+ - lib/super/controls/view.rb
305
+ - lib/super/display.rb
306
+ - lib/super/display/guesser.rb
268
307
  - lib/super/display/schema_types.rb
269
308
  - lib/super/engine.rb
270
309
  - lib/super/error.rb
310
+ - lib/super/filter.rb
311
+ - lib/super/filter/form_object.rb
312
+ - lib/super/filter/guesser.rb
313
+ - lib/super/filter/operator.rb
314
+ - lib/super/filter/schema_types.rb
271
315
  - lib/super/form.rb
316
+ - lib/super/form/builder.rb
317
+ - lib/super/form/guesser.rb
318
+ - lib/super/form/inline_errors.rb
272
319
  - lib/super/form/schema_types.rb
320
+ - lib/super/form/strong_params.rb
273
321
  - lib/super/layout.rb
274
322
  - lib/super/link.rb
275
323
  - lib/super/navigation/automatic.rb
@@ -278,14 +326,18 @@ files:
278
326
  - lib/super/partial.rb
279
327
  - lib/super/partial/resolving.rb
280
328
  - lib/super/plugin.rb
329
+ - lib/super/query/form_object.rb
281
330
  - lib/super/schema.rb
331
+ - lib/super/schema/common.rb
332
+ - lib/super/schema/guesser.rb
333
+ - lib/super/sort.rb
282
334
  - lib/super/version.rb
283
335
  - lib/super/view_helper.rb
284
- homepage:
336
+ homepage:
285
337
  licenses:
286
338
  - LGPL-3.0-only
287
339
  metadata: {}
288
- post_install_message:
340
+ post_install_message:
289
341
  rdoc_options: []
290
342
  require_paths:
291
343
  - lib
@@ -300,8 +352,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
352
  - !ruby/object:Gem::Version
301
353
  version: '0'
302
354
  requirements: []
303
- rubygems_version: 3.1.4
304
- signing_key:
355
+ rubygems_version: 3.2.4
356
+ signing_key:
305
357
  specification_version: 4
306
358
  summary: A simple, powerful, zero dependency Rails admin framework
307
359
  test_files: []
@@ -1,39 +0,0 @@
1
- module Super
2
- # View helpers, available within views
3
- module ApplicationHelper
4
- def super_render_partialish(partialish)
5
- if partialish.respond_to?(:to_partial_path)
6
- if partialish.is_a?(Super::Partial)
7
- render(partialish, partialish.locals)
8
- else
9
- render(partialish)
10
- end
11
- else
12
- partialish
13
- end
14
- end
15
-
16
- def super_format_for_display(schema, record, column)
17
- formatter = schema.fields[column]
18
-
19
- formatted =
20
- if formatter.real?
21
- value = record.public_send(column)
22
- formatter.present(value)
23
- else
24
- formatter.present
25
- end
26
-
27
- if formatted.respond_to?(:to_partial_path)
28
- if formatted.respond_to?(:locals)
29
- formatted.locals[:record] ||= record
30
- render(formatted, formatted.locals)
31
- else
32
- render(formatted)
33
- end
34
- else
35
- formatted
36
- end
37
- end
38
- end
39
- end
@@ -1,10 +0,0 @@
1
- <% if form.object %>
2
- <% Super::ViewHelper.errors_accounting_for_reflections(form.object, column).each do |error_message| %>
3
- <p class="text-red-400 text-xs italic pt-1"><%= error_message %></p>
4
- <% end %>
5
- <% else %>
6
- <p class="text-red-400 text-xs italic pt-1">
7
- This form doesn't have an object, so something is probably wrong.
8
- Maybe <code>accepts_nested_attributes_for</code> isn't set up?
9
- </p>
10
- <% end %>
@@ -1,36 +0,0 @@
1
- const Bundler = require("parcel-bundler");
2
- const fs = require("fs");
3
- const path = require("path");
4
-
5
- const entryFiles = [
6
- "src/stylesheets/super/application.css",
7
- "src/javascripts/super/application.ts",
8
- ];
9
-
10
- const options = {
11
- outDir: "../../app/assets",
12
- watch: process.argv.includes("--watch"),
13
- cacheDir: "tmp/parcel/cache",
14
- global: "Super",
15
- contentHash: false,
16
- minify: false,
17
- sourceMaps: false,
18
- hmr: false,
19
- };
20
-
21
- const bundler = new Bundler(entryFiles, options);
22
-
23
- bundler.on("bundled", function(bundle) {
24
- bundle.childBundles.forEach(function(childBundle) {
25
- var basename = path.basename(childBundle.name);
26
- var destDir = path.join(__dirname, "dist");
27
- var destPath = path.join(destDir, basename);
28
-
29
- console.log(destPath);
30
- fs.copyFileSync(childBundle.name, destPath);
31
- });
32
- console.log();
33
- console.log();
34
- });
35
-
36
- bundler.bundle();
@@ -1,21 +0,0 @@
1
- {
2
- "dependencies": {
3
- "@rails/ujs": "^6.0.2-1",
4
- "stimulus": "^2.0.0",
5
- "tailwindcss": "^1.0.1"
6
- },
7
- "devDependencies": {
8
- "parcel-bundler": "^1.12.3",
9
- "prettier": "1.19.1",
10
- "typescript": "^3.7.4"
11
- },
12
- "scripts": {
13
- "build": "node build.js",
14
- "watch": "node build.js --watch",
15
- "typescript": "tsc --watch",
16
- "lint": "prettier --write src/**/*.ts *.js"
17
- },
18
- "prettier": {
19
- "trailingComma": "es5"
20
- }
21
- }