super 0.0.12 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +0 -1
  3. data/README.md +38 -46
  4. data/app/assets/javascripts/super/application.js +5747 -3803
  5. data/app/assets/stylesheets/super/application.css +114686 -71486
  6. data/app/controllers/super/application_controller.rb +44 -37
  7. data/app/controllers/super/substructure_controller.rb +276 -0
  8. data/app/helpers/super/form_builder_helper.rb +7 -0
  9. data/app/views/layouts/super/application.html.erb +4 -19
  10. data/app/views/super/application/_collection_header.html.erb +2 -2
  11. data/app/views/super/application/_display_actions.html.erb +1 -1
  12. data/app/views/super/application/_display_index.html.erb +2 -2
  13. data/app/views/super/application/_display_show.html.erb +1 -1
  14. data/app/views/super/application/_filter.html.erb +62 -2
  15. data/app/views/super/application/_form_field.html.erb +5 -0
  16. data/app/views/super/application/_layout.html.erb +1 -1
  17. data/app/views/super/application/_member_header.html.erb +2 -2
  18. data/app/views/super/application/_pagination.html.erb +1 -1
  19. data/app/views/super/application/_site_footer.html.erb +3 -0
  20. data/app/views/super/application/_site_header.html.erb +17 -0
  21. data/app/views/super/application/_sort_expression.html.erb +2 -2
  22. data/app/views/super/feather/README.md +0 -1
  23. data/frontend/super-frontend/dist/application.css +114686 -71486
  24. data/frontend/super-frontend/dist/application.js +5747 -3803
  25. data/lib/generators/super/install/install_generator.rb +0 -16
  26. data/lib/generators/super/install/templates/base_controller.rb.tt +0 -8
  27. data/lib/generators/super/resource/templates/resources_controller.rb.tt +4 -4
  28. data/lib/generators/super/webpacker/webpacker_generator.rb +9 -5
  29. data/lib/super.rb +5 -2
  30. data/lib/super/action_inquirer.rb +18 -3
  31. data/lib/super/assets.rb +44 -23
  32. data/lib/super/badge.rb +60 -0
  33. data/lib/super/cheat.rb +17 -0
  34. data/lib/super/compatibility.rb +19 -0
  35. data/lib/super/display/guesser.rb +3 -1
  36. data/lib/super/display/schema_types.rb +51 -2
  37. data/lib/super/error.rb +2 -0
  38. data/lib/super/filter.rb +1 -1
  39. data/lib/super/filter/form_object.rb +74 -48
  40. data/lib/super/filter/guesser.rb +2 -0
  41. data/lib/super/filter/operator.rb +90 -64
  42. data/lib/super/filter/schema_types.rb +63 -80
  43. data/lib/super/form/builder.rb +110 -27
  44. data/lib/super/form/field_transcript.rb +43 -0
  45. data/lib/super/form/guesser.rb +10 -1
  46. data/lib/super/form/schema_types.rb +73 -16
  47. data/lib/super/link.rb +38 -32
  48. data/lib/super/link_builder.rb +58 -0
  49. data/lib/super/navigation.rb +164 -0
  50. data/lib/super/pagination.rb +2 -44
  51. data/lib/super/reset.rb +22 -0
  52. data/lib/super/schema.rb +4 -0
  53. data/lib/super/useful/builder.rb +4 -4
  54. data/lib/super/version.rb +1 -1
  55. data/lib/tasks/super/cheat.rake +9 -0
  56. metadata +14 -19
  57. data/CONTRIBUTING.md +0 -56
  58. data/Rakefile +0 -36
  59. data/app/views/super/application/_filter_type_select.html.erb +0 -21
  60. data/app/views/super/application/_filter_type_text.html.erb +0 -18
  61. data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
  62. data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
  63. data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
  64. data/app/views/super/application/_form_field_select.html.erb +0 -1
  65. data/app/views/super/application/_form_field_text.html.erb +0 -1
  66. data/app/views/super/feather/_chevron_down.html +0 -1
  67. data/docs/cheat.md +0 -41
  68. data/lib/super/controls.rb +0 -22
  69. data/lib/super/controls/optional.rb +0 -113
  70. data/lib/super/controls/steps.rb +0 -106
  71. data/lib/super/controls/view.rb +0 -55
  72. data/lib/super/navigation/automatic.rb +0 -73
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class LinkBuilder
5
+ def initialize(text, href, **options)
6
+ @text = text
7
+ @href = href
8
+ @options = options
9
+ @requirements = []
10
+ @requirements += gather_requirements(text)
11
+ @requirements += gather_requirements(href)
12
+ @requirements += gather_requirements(options)
13
+
14
+ unknown_arguments = @requirements - known_requirements
15
+ if unknown_arguments.any?
16
+ raise Error::ArgumentError, "Unknown arguments: #{unknown_arguments.join(", ")}"
17
+ end
18
+ end
19
+
20
+ attr_reader :requirements
21
+
22
+ def to_s(default_options: nil, **kwargs)
23
+ resolve(**kwargs).to_s(default_options: default_options)
24
+ end
25
+
26
+ def resolve(**kwargs)
27
+ Link.new(
28
+ into_value(@text, kwargs),
29
+ into_value(@href, kwargs),
30
+ **into_value(@options, kwargs),
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ def known_requirements
37
+ %i[params record].freeze
38
+ end
39
+
40
+ def gather_requirements(value_or_proc)
41
+ return [] if !value_or_proc.is_a?(Proc)
42
+
43
+ requirements =
44
+ value_or_proc
45
+ .parameters
46
+ .select { |(kind, name)| kind = :keyreq }
47
+ .map(&:last)
48
+ end
49
+
50
+ def into_value(value_or_proc, kwargs)
51
+ if value_or_proc.kind_of?(Proc)
52
+ value_or_proc.call(**kwargs)
53
+ else
54
+ value_or_proc
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class Navigation
5
+ def initialize
6
+ @builder = Builder.new
7
+ @definition = yield @builder
8
+ if !@definition.is_a?(Array)
9
+ @definition = [@definition]
10
+ end
11
+ end
12
+
13
+ def definition
14
+ return @defs if instance_variable_defined?(:@defs)
15
+
16
+ searcher = RouteFormatterButReallySearcher.new
17
+ inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
18
+ inspector.format(searcher)
19
+ all_matches = searcher.matches
20
+ unused_matches = all_matches.each_with_object({}) { |match, hash| hash[match] = true }
21
+
22
+ defs = expand_proc_syntax_sugar(@definition)
23
+ defs = validate_and_determine_explicit_links(defs, unused_matches)
24
+ @defs = expand_directives(defs, all_matches, unused_matches.keys)
25
+ end
26
+
27
+ private
28
+
29
+ # This expands the syntax sugar that allows `nav.menu("Name")[nav.link(Item)]`
30
+ def expand_proc_syntax_sugar(definition)
31
+ definition.map do |link_or_menu_or_rest_or_menuproc|
32
+ link_or_menu_or_rest =
33
+ if link_or_menu_or_rest_or_menuproc.is_a?(Proc)
34
+ link_or_menu_or_rest_or_menuproc.call
35
+ else
36
+ link_or_menu_or_rest_or_menuproc
37
+ end
38
+
39
+ if link_or_menu_or_rest.is_a?(Menu)
40
+ link_or_menu_or_rest.links = link_or_menu_or_rest.links.map do |menu_item|
41
+ if menu_item.is_a?(Proc)
42
+ menu_item.call
43
+ else
44
+ menu_item
45
+ end
46
+ end
47
+ end
48
+
49
+ link_or_menu_or_rest
50
+ end
51
+ end
52
+
53
+ def validate_and_determine_explicit_links(definition, unused_links)
54
+ definition.each do |link_or_menu_or_rest|
55
+ if link_or_menu_or_rest.is_a?(Super::Link)
56
+ unused_links.delete(link_or_menu_or_rest.href)
57
+ elsif link_or_menu_or_rest.is_a?(Menu)
58
+ link_or_menu_or_rest.links.each do |link_or_rest|
59
+ if link_or_rest.is_a?(Menu)
60
+ raise Super::Error::ArgumentError, "Navigation menus can't be nested"
61
+ end
62
+
63
+ if link_or_rest.is_a?(Link)
64
+ unused_links.delete(link_or_rest.href)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def expand_directives(defs, all_hrefs, rest_hrefs)
72
+ defs.flat_map do |link_or_menu_or_rest|
73
+ if link_or_menu_or_rest.is_a?(Menu)
74
+ link_or_menu_or_rest.links = link_or_menu_or_rest.links.flat_map do |link_or_rest|
75
+ if link_or_rest == ALL
76
+ linkify_hrefs(all_hrefs)
77
+ elsif link_or_rest == REST
78
+ linkify_hrefs(rest_hrefs)
79
+ else
80
+ link_or_rest
81
+ end
82
+ end
83
+
84
+ link_or_menu_or_rest
85
+ elsif link_or_menu_or_rest == ALL
86
+ linkify_hrefs(all_hrefs)
87
+ elsif link_or_menu_or_rest == REST
88
+ linkify_hrefs(rest_hrefs)
89
+ else
90
+ link_or_menu_or_rest
91
+ end
92
+ end
93
+ end
94
+
95
+ def linkify_hrefs(hrefs)
96
+ hrefs.map do |href|
97
+ Super::Link.new(href.split("/").last.humanize, href)
98
+ end
99
+ end
100
+
101
+ ALL = Object.new
102
+ REST = Object.new
103
+ Menu = Struct.new(:title, :links)
104
+
105
+ class Builder
106
+ def link(model, **kwargs)
107
+ text = model.model_name.human.pluralize
108
+ parts = Super::Link.polymorphic_parts(model)
109
+
110
+ Super::Link.new(text, parts, **kwargs)
111
+ end
112
+
113
+ def link_to(*args, **kwargs)
114
+ Super::Link.new(*args, **kwargs)
115
+ end
116
+
117
+ def menu(title, *links)
118
+ menu = Menu.new(title, links)
119
+ proc do |*more_links|
120
+ menu.links += more_links
121
+ menu
122
+ end
123
+ end
124
+
125
+ def rest
126
+ REST
127
+ end
128
+
129
+ def all
130
+ ALL
131
+ end
132
+ end
133
+
134
+ class RouteFormatterButReallySearcher
135
+ def initialize(route_namespace: Super.configuration.path)
136
+ @route_namespace = route_namespace.strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip
137
+ @route_namespace = "/#{@route_namespace}/"
138
+ @matches = []
139
+ end
140
+
141
+ def matches
142
+ @matches.map do |route|
143
+ route[:path].sub(/\(.*\)\Z/, "")
144
+ end
145
+ end
146
+
147
+ def section(routes)
148
+ @matches += routes.select do |route|
149
+ next false unless route[:verb] == "GET" || route[:verb] == ""
150
+ next false unless route[:path].start_with?(@route_namespace)
151
+ next false if route[:path].include?("/:")
152
+ next false if route[:reqs].end_with?("#new")
153
+
154
+ true
155
+ end
156
+ end
157
+
158
+ def header(routes); end
159
+ def no_routes(routes, filter); end
160
+ def result; end
161
+ def section_title(title); end
162
+ end
163
+ end
164
+ end
@@ -76,52 +76,10 @@ module Super
76
76
  module ControllerMethods
77
77
  def index
78
78
  super
79
- @pagination = controls.initialize_pagination(action: action_inquirer, records: @records, query_params: request.GET)
80
- @records = controls.paginate_records(action: action_inquirer, records: @records, pagination: @pagination)
79
+ @pagination = initialize_pagination
80
+ @records = paginate_records
81
81
  @view.mains.first.parts.push(:@pagination)
82
82
  end
83
83
  end
84
84
  end
85
-
86
- class Controls
87
- module Optional
88
- # Specifies how many records to show per page
89
- #
90
- # @param action [ActionInquirer]
91
- # @param query_params [Hash]
92
- # @return [ActiveRecord::Relation]
93
- def records_per_page(action:, query_params:)
94
- Super.configuration.index_records_per_page
95
- end
96
- end
97
-
98
- module Steps
99
- # Sets up pagination
100
- #
101
- # @param action [ActionInquirer]
102
- # @param records [ActiveRecord::Relation]
103
- # @param query_params [Hash]
104
- # @return [Pagination]
105
- def initialize_pagination(action:, records:, query_params:)
106
- Pagination.new(
107
- total_count: records.size,
108
- limit: records_per_page(action: action, query_params: query_params),
109
- query_params: query_params,
110
- page_query_param: :page
111
- )
112
- end
113
-
114
- # Paginates
115
- #
116
- # @param action [ActionInquirer]
117
- # @param records [ActiveRecord::Relation]
118
- # @param pagination [Pagination]
119
- # @return [ActiveRecord::Relation]
120
- def paginate_records(action:, records:, pagination:)
121
- records
122
- .limit(pagination.limit)
123
- .offset(pagination.offset)
124
- end
125
- end
126
- end
127
85
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ module Reset
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ undef_method :index
9
+ undef_method :show
10
+ undef_method :new
11
+ undef_method :create
12
+ undef_method :edit
13
+ undef_method :update
14
+ undef_method :destroy
15
+
16
+ Super::SubstructureController.private_instance_methods(false).each do |imethod|
17
+ next if imethod == :navigation
18
+ undef_method imethod
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/super/schema.rb CHANGED
@@ -42,6 +42,10 @@ module Super
42
42
  enum_for(:each)
43
43
  end
44
44
 
45
+ def delete(key)
46
+ @backing.delete(key)
47
+ end
48
+
45
49
  def replace(other)
46
50
  @backing = other
47
51
  end
@@ -6,8 +6,8 @@ module Super
6
6
  def builder(method_name)
7
7
  alias_method("original_#{method_name}", method_name)
8
8
 
9
- define_method(method_name) do
10
- send("original_#{method_name}")
9
+ define_method(method_name) do |*args|
10
+ send("original_#{method_name}", *args)
11
11
  self
12
12
  end
13
13
  end
@@ -15,8 +15,8 @@ module Super
15
15
  def builder_with_block(method_name)
16
16
  alias_method("original_#{method_name}", method_name)
17
17
 
18
- define_method(method_name) do |&block|
19
- send("original_#{method_name}", &block)
18
+ define_method(method_name) do |*args, &block|
19
+ send("original_#{method_name}", *args, &block)
20
20
  self
21
21
  end
22
22
  end
data/lib/super/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Super
4
- VERSION = "0.0.12"
4
+ VERSION = "0.17.0"
5
5
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :super do
4
+ task :cheat do
5
+ require "super/cheat"
6
+ cheat = Super::Cheat.new
7
+ cheat.controller
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-04 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -220,14 +220,13 @@ extensions: []
220
220
  extra_rdoc_files: []
221
221
  files:
222
222
  - ".yardopts"
223
- - CONTRIBUTING.md
224
223
  - LICENSE
225
224
  - README.md
226
- - Rakefile
227
225
  - app/assets/config/super_manifest.js
228
226
  - app/assets/javascripts/super/application.js
229
227
  - app/assets/stylesheets/super/application.css
230
228
  - app/controllers/super/application_controller.rb
229
+ - app/controllers/super/substructure_controller.rb
231
230
  - app/helpers/super/form_builder_helper.rb
232
231
  - app/views/layouts/super/application.html.erb
233
232
  - app/views/super/application/_collection_header.html.erb
@@ -236,16 +235,10 @@ files:
236
235
  - app/views/super/application/_display_rich_text.html.erb
237
236
  - app/views/super/application/_display_show.html.erb
238
237
  - app/views/super/application/_filter.html.erb
239
- - app/views/super/application/_filter_type_select.html.erb
240
- - app/views/super/application/_filter_type_text.html.erb
241
- - app/views/super/application/_filter_type_timestamp.html.erb
242
238
  - app/views/super/application/_flash.html.erb
243
239
  - app/views/super/application/_form.html.erb
240
+ - app/views/super/application/_form_field.html.erb
244
241
  - app/views/super/application/_form_field__destroy.html.erb
245
- - app/views/super/application/_form_field_checkbox.html.erb
246
- - app/views/super/application/_form_field_rich_text_area.html.erb
247
- - app/views/super/application/_form_field_select.html.erb
248
- - app/views/super/application/_form_field_text.html.erb
249
242
  - app/views/super/application/_form_fieldset.html.erb
250
243
  - app/views/super/application/_form_has_many.html.erb
251
244
  - app/views/super/application/_form_has_one.html.erb
@@ -254,6 +247,8 @@ files:
254
247
  - app/views/super/application/_pagination.html.erb
255
248
  - app/views/super/application/_panel.html.erb
256
249
  - app/views/super/application/_query.html.erb
250
+ - app/views/super/application/_site_footer.html.erb
251
+ - app/views/super/application/_site_header.html.erb
257
252
  - app/views/super/application/_sort.html.erb
258
253
  - app/views/super/application/_sort_expression.html.erb
259
254
  - app/views/super/application/edit.html.erb
@@ -262,11 +257,9 @@ files:
262
257
  - app/views/super/application/nothing.html.erb
263
258
  - app/views/super/application/show.html.erb
264
259
  - app/views/super/feather/README.md
265
- - app/views/super/feather/_chevron_down.html
266
260
  - app/views/super/feather/_x.html
267
261
  - config/locales/en.yml
268
262
  - config/routes.rb
269
- - docs/cheat.md
270
263
  - frontend/super-frontend/dist/application.css
271
264
  - frontend/super-frontend/dist/application.js
272
265
  - lib/generators/super/action_text/USAGE
@@ -286,13 +279,11 @@ files:
286
279
  - lib/super.rb
287
280
  - lib/super/action_inquirer.rb
288
281
  - lib/super/assets.rb
282
+ - lib/super/badge.rb
283
+ - lib/super/cheat.rb
289
284
  - lib/super/client_error.rb
290
285
  - lib/super/compatibility.rb
291
286
  - lib/super/configuration.rb
292
- - lib/super/controls.rb
293
- - lib/super/controls/optional.rb
294
- - lib/super/controls/steps.rb
295
- - lib/super/controls/view.rb
296
287
  - lib/super/display.rb
297
288
  - lib/super/display/guesser.rb
298
289
  - lib/super/display/schema_types.rb
@@ -305,19 +296,22 @@ files:
305
296
  - lib/super/filter/schema_types.rb
306
297
  - lib/super/form.rb
307
298
  - lib/super/form/builder.rb
299
+ - lib/super/form/field_transcript.rb
308
300
  - lib/super/form/guesser.rb
309
301
  - lib/super/form/inline_errors.rb
310
302
  - lib/super/form/schema_types.rb
311
303
  - lib/super/form/strong_params.rb
312
304
  - lib/super/layout.rb
313
305
  - lib/super/link.rb
314
- - lib/super/navigation/automatic.rb
306
+ - lib/super/link_builder.rb
307
+ - lib/super/navigation.rb
315
308
  - lib/super/pagination.rb
316
309
  - lib/super/panel.rb
317
310
  - lib/super/partial.rb
318
311
  - lib/super/partial/resolving.rb
319
312
  - lib/super/plugin.rb
320
313
  - lib/super/query/form_object.rb
314
+ - lib/super/reset.rb
321
315
  - lib/super/schema.rb
322
316
  - lib/super/schema/common.rb
323
317
  - lib/super/schema/guesser.rb
@@ -326,6 +320,7 @@ files:
326
320
  - lib/super/useful/enum.rb
327
321
  - lib/super/version.rb
328
322
  - lib/super/view_helper.rb
323
+ - lib/tasks/super/cheat.rake
329
324
  homepage:
330
325
  licenses:
331
326
  - LGPL-3.0-only
@@ -350,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
345
  - !ruby/object:Gem::Version
351
346
  version: '0'
352
347
  requirements: []
353
- rubygems_version: 3.2.4
348
+ rubygems_version: 3.0.3.1
354
349
  signing_key:
355
350
  specification_version: 4
356
351
  summary: A simple, powerful, zero dependency Rails admin framework