super 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/README.md +55 -23
  4. data/app/assets/javascripts/super/application.js +1062 -261
  5. data/app/assets/stylesheets/super/application.css +72775 -50711
  6. data/app/controllers/super/application_controller.rb +39 -50
  7. data/app/helpers/super/application_helper.rb +24 -17
  8. data/app/views/layouts/super/application.html.erb +4 -0
  9. data/app/views/super/application/{_resources_header.html.erb → _collection_header.html.erb} +5 -6
  10. data/app/views/super/application/_flash.html.erb +13 -13
  11. data/app/views/super/application/_form_field_select.html.erb +1 -1
  12. data/app/views/super/application/_form_has_many.html.erb +1 -1
  13. data/app/views/super/application/{_resource_header.html.erb → _member_header.html.erb} +6 -6
  14. data/app/views/super/application/_super_layout.html.erb +7 -12
  15. data/app/views/super/application/_super_panel.html.erb +2 -6
  16. data/app/views/super/application/_super_schema_display_actions.html.erb +5 -0
  17. data/app/views/super/application/_super_schema_display_index.html.erb +39 -0
  18. data/app/views/super/application/_super_schema_display_show.html.erb +8 -0
  19. data/app/views/super/application/{_form.html.erb → _super_schema_form.html.erb} +2 -4
  20. data/app/views/super/application/edit.html.erb +2 -2
  21. data/app/views/super/application/index.html.erb +2 -2
  22. data/app/views/super/application/new.html.erb +2 -2
  23. data/app/views/super/application/show.html.erb +2 -2
  24. data/app/views/super/feather/{_chevron_down.svg → _chevron_down.html} +0 -0
  25. data/config/locales/en.yml +5 -0
  26. data/docs/cheat.md +41 -0
  27. data/docs/webpacker.md +1 -1
  28. data/frontend/super-frontend/dist/application.css +72775 -50711
  29. data/frontend/super-frontend/dist/application.js +1062 -261
  30. data/frontend/super-frontend/package.json +1 -1
  31. data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +6 -8
  32. data/frontend/super-frontend/tailwind.config.js +7 -1
  33. data/frontend/super-frontend/yarn.lock +1103 -1195
  34. data/lib/generators/super/install/install_generator.rb +16 -0
  35. data/lib/super.rb +2 -2
  36. data/lib/super/action_inquirer.rb +2 -2
  37. data/lib/super/client_error.rb +43 -0
  38. data/lib/super/configuration.rb +1 -1
  39. data/lib/super/controls.rb +17 -101
  40. data/lib/super/controls/optional.rb +65 -0
  41. data/lib/super/controls/required.rb +41 -0
  42. data/lib/super/controls/steps.rb +115 -0
  43. data/lib/super/display/schema_types.rb +45 -2
  44. data/lib/super/error.rb +8 -9
  45. data/lib/super/form.rb +48 -0
  46. data/lib/super/form/schema_types.rb +8 -1
  47. data/lib/super/layout.rb +28 -0
  48. data/lib/super/link.rb +55 -32
  49. data/lib/super/panel.rb +13 -0
  50. data/lib/super/partial/resolving.rb +24 -0
  51. data/lib/super/schema.rb +19 -5
  52. data/lib/super/version.rb +1 -1
  53. data/lib/super/view_helper.rb +1 -1
  54. metadata +40 -15
  55. data/app/views/super/application/_index.html.erb +0 -45
  56. data/app/views/super/application/_show.html.erb +0 -10
  57. data/docs/controls.md +0 -39
  58. data/lib/super/display.rb +0 -9
  59. data/lib/super/step.rb +0 -36
  60. data/lib/tasks/super_tasks.rake +0 -4
@@ -27,14 +27,57 @@ module Super
27
27
  @transform_block = transform_block
28
28
  end
29
29
 
30
- def present(field)
31
- @transform_block.call(field)
30
+ def present(value)
31
+ @transform_block.call(value)
32
+ end
33
+
34
+ def real?
35
+ true
36
+ end
37
+ end
38
+
39
+ class Bypass
40
+ def initialize(partial:, real:)
41
+ @partial = partial
42
+ @real = real
43
+ end
44
+
45
+ def present
46
+ Partial.new(@partial)
47
+ end
48
+
49
+ def real?
50
+ @real
32
51
  end
33
52
  end
34
53
 
54
+ def initialize(action_inquirer)
55
+ @action_inquirer = action_inquirer
56
+ @actions_called = false
57
+ end
58
+
59
+ def before_yield(fields:)
60
+ @fields = fields
61
+ end
62
+
63
+ def after_yield
64
+ return if !@action_inquirer.index?
65
+ return if @actions_called
66
+ @fields[:actions] = actions
67
+ end
68
+
35
69
  def dynamic(&transform_block)
36
70
  Dynamic.new(transform_block)
37
71
  end
72
+
73
+ def actions
74
+ @actions_called = true
75
+ Bypass.new(partial: "super_schema_display_actions", real: false)
76
+ end
77
+
78
+ def to_partial_path
79
+ "super_schema_display_#{@action_inquirer.action}"
80
+ end
38
81
  end
39
82
  end
40
83
  end
@@ -1,18 +1,17 @@
1
1
  module Super
2
- # A container class for all custom errors thrown by this library
2
+ # A container class for all internal errors thrown by this library
3
+ #
4
+ # See also `Super::ClientError`
3
5
  class Error < StandardError
6
+ # Error raised when some configuration is not set
4
7
  class UnconfiguredConfiguration < Error; end
8
+ # Error raised when a configuration is set to a invalid value
5
9
  class InvalidConfiguration < Error; end
6
- class InvalidStyle < Error; end
10
+ # Error raised on problematic plugins, see `Super::Plugin`
7
11
  class InvalidPluginArgument < Error; end
12
+ # Error raised on problematic ActionInquirer settings, see `Super::ActionInquirer`
8
13
  class ActionInquirerError < Error; end
14
+ # Error raised when a `Super::Link` couldn't be found
9
15
  class LinkNotRegistered < Error; end
10
-
11
- class ClientError < Error; end
12
- class BadRequest < ClientError; end
13
- class Unauthorized < ClientError; end
14
- class Forbidden < ClientError; end
15
- class NotFound < ClientError; end
16
- class UnprocessableEntity < ClientError; end
17
16
  end
18
17
  end
@@ -0,0 +1,48 @@
1
+ module Super
2
+ class Form
3
+ module FieldErrorProc
4
+ def error_wrapping(html_tag)
5
+ if Thread.current[:super_form_builder]
6
+ return html_tag
7
+ end
8
+
9
+ super
10
+ end
11
+ end
12
+
13
+ class Builder < ActionView::Helpers::FormBuilder
14
+ # These methods were originally defined in the following files
15
+ #
16
+ # * actionview/lib/action_view/helpers/form_helper.rb
17
+ # * actionview/lib/action_view/helpers/form_options_helper.rb
18
+ # * actionview/lib/action_view/helpers/date_helper.rb
19
+ %w[
20
+ label text_field password_field hidden_field file_field text_area
21
+ check_box radio_button color_field search_field telephone_field
22
+ date_field time_field datetime_field month_field week_field url_field
23
+ email_field number_field range_field
24
+
25
+ select collection_select grouped_collection_select time_zone_select
26
+ collection_radio_buttons collection_check_boxes
27
+
28
+ time_select datetime_select date_select
29
+ ].each do |field_type_method|
30
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
31
+ def #{field_type_method}(*)
32
+ Thread.current[:super_form_builder] = true
33
+ super
34
+ ensure
35
+ Thread.current[:super_form_builder] = nil
36
+ end
37
+ RUBY
38
+ end
39
+
40
+ alias datetime_local_field datetime_field
41
+ alias phone_field telephone_field
42
+ end
43
+ end
44
+ end
45
+
46
+ ActionView::Helpers::Tags::Base.class_eval do
47
+ prepend Super::Form::FieldErrorProc
48
+ end
@@ -69,10 +69,13 @@ module Super
69
69
  end
70
70
  end
71
71
 
72
- def setup(fields:)
72
+ def before_yield(fields:)
73
73
  @fields = fields
74
74
  end
75
75
 
76
+ def after_yield
77
+ end
78
+
76
79
  def generic(partial_path, **extras)
77
80
  Generic.new(partial_path: partial_path, extras: extras, nested: {})
78
81
  end
@@ -110,6 +113,10 @@ module Super
110
113
  nested: {}
111
114
  )
112
115
  end
116
+
117
+ def to_partial_path
118
+ "super_schema_form"
119
+ end
113
120
  end
114
121
  end
115
122
  end
@@ -1,5 +1,9 @@
1
+ require "super/partial/resolving"
2
+
1
3
  module Super
2
4
  class Layout
5
+ include Super::Partial::Resolving
6
+
3
7
  def initialize(headers: nil, asides: nil, mains: nil, footers: nil)
4
8
  @headers = Array(headers).compact
5
9
  @asides = Array(asides).compact
@@ -15,5 +19,29 @@ module Super
15
19
  def to_partial_path
16
20
  "super_layout"
17
21
  end
22
+
23
+ def resolve(template)
24
+ @resolved_headers = resolve_for_rendering(template, headers, nil)
25
+ @resolved_asides = resolve_for_rendering(template, asides, nil)
26
+ @resolved_mains = resolve_for_rendering(template, mains, nil)
27
+ @resolved_footers = resolve_for_rendering(template, footers, nil)
28
+ self
29
+ end
30
+
31
+ def resolved_headers
32
+ @resolved_headers || []
33
+ end
34
+
35
+ def resolved_asides
36
+ @resolved_asides || []
37
+ end
38
+
39
+ def resolved_mains
40
+ @resolved_mains || []
41
+ end
42
+
43
+ def resolved_footers
44
+ @resolved_footers || []
45
+ end
18
46
  end
19
47
  end
@@ -2,7 +2,11 @@ module Super
2
2
  # Links have three required attributes that are passed directly into Rails'
3
3
  # `link_to` helper
4
4
  class Link
5
- def self.resolve(link)
5
+ def self.find_all(*links)
6
+ links.map { |link| find(link) }
7
+ end
8
+
9
+ def self.find(link)
6
10
  if link.kind_of?(self)
7
11
  return link
8
12
  end
@@ -16,61 +20,61 @@ module Super
16
20
 
17
21
  def self.registry
18
22
  @registry ||= {
19
- new: -> (params:) {
20
- new(
21
- "New",
23
+ new: new(
24
+ "New",
25
+ -> (params:) {
22
26
  Rails.application.routes.url_for(
23
27
  controller: params[:controller],
24
28
  action: :new,
25
29
  only_path: true
26
30
  )
27
- )
28
- },
29
- index: -> (params:) {
30
- new(
31
- "Index",
31
+ }
32
+ ),
33
+ index: new(
34
+ "Index",
35
+ -> (params:) {
32
36
  Rails.application.routes.url_for(
33
37
  controller: params[:controller],
34
38
  action: :index,
35
39
  only_path: true
36
40
  )
37
- )
38
- },
39
- show: -> (resource, params:) {
40
- new(
41
- "View",
41
+ }
42
+ ),
43
+ show: new(
44
+ "View",
45
+ -> (record:, params:) {
42
46
  Rails.application.routes.url_for(
43
47
  controller: params[:controller],
44
48
  action: :show,
45
- id: resource,
49
+ id: record,
46
50
  only_path: true
47
51
  )
48
- )
49
- },
50
- edit: -> (resource, params:) {
51
- new(
52
- "Edit",
52
+ }
53
+ ),
54
+ edit: new(
55
+ "Edit",
56
+ -> (record:, params:) {
53
57
  Rails.application.routes.url_for(
54
58
  controller: params[:controller],
55
59
  action: :edit,
56
- id: resource,
60
+ id: record,
57
61
  only_path: true
58
62
  )
59
- )
60
- },
61
- destroy: -> (resource, params:) {
62
- new(
63
- "Delete",
63
+ }
64
+ ),
65
+ destroy: new(
66
+ "Delete",
67
+ -> (record:, params:) {
64
68
  Rails.application.routes.url_for(
65
69
  controller: params[:controller],
66
70
  action: :destroy,
67
- id: resource,
71
+ id: record,
68
72
  only_path: true
69
- ),
70
- method: :delete,
71
- data: { confirm: "Really delete?" }
72
- )
73
- },
73
+ )
74
+ },
75
+ method: :delete,
76
+ data: { confirm: "Really delete?" }
77
+ ),
74
78
  }
75
79
  end
76
80
 
@@ -80,8 +84,27 @@ module Super
80
84
  @options = options
81
85
  end
82
86
 
87
+ def to_s(default_options: nil, **proc_arguments)
88
+ default_options ||= {}
89
+ ActionController::Base.helpers.link_to(
90
+ value(text, proc_arguments),
91
+ value(href, proc_arguments),
92
+ default_options.deep_merge(value(options, proc_arguments))
93
+ )
94
+ end
95
+
96
+ private
97
+
83
98
  attr_reader :text
84
99
  attr_reader :href
85
100
  attr_reader :options
101
+
102
+ def value(proc_or_value, proc_arguments)
103
+ if proc_or_value.kind_of?(Proc)
104
+ proc_or_value.call(**proc_arguments)
105
+ else
106
+ proc_or_value
107
+ end
108
+ end
86
109
  end
87
110
  end
@@ -1,5 +1,9 @@
1
+ require "super/partial/resolving"
2
+
1
3
  module Super
2
4
  class Panel
5
+ include Super::Partial::Resolving
6
+
3
7
  def initialize(*parts)
4
8
  if block_given?
5
9
  @parts = Array.new(yield)
@@ -10,6 +14,15 @@ module Super
10
14
 
11
15
  attr_reader :parts
12
16
 
17
+ def resolve(template, block)
18
+ @resolved_parts ||= resolve_for_rendering(template, parts, block)
19
+ self
20
+ end
21
+
22
+ def resolved_parts
23
+ @resolved_parts || []
24
+ end
25
+
13
26
  def to_partial_path
14
27
  "super_panel"
15
28
  end
@@ -0,0 +1,24 @@
1
+ module Super
2
+ class Partial
3
+ module Resolving
4
+ module_function
5
+
6
+ def resolve_for_rendering(template, partials, block)
7
+ if block
8
+ partials = [block.call, *parts]
9
+ end
10
+
11
+ partials =
12
+ partials.map do |partial|
13
+ if partial.is_a?(Symbol)
14
+ template.instance_variable_get(partial)
15
+ else
16
+ partial
17
+ end
18
+ end
19
+
20
+ partials.compact
21
+ end
22
+ end
23
+ end
24
+ end
@@ -10,13 +10,13 @@ module Super
10
10
  @schema_type = schema_type
11
11
  @fields = Fields.new
12
12
 
13
- if @schema_type.respond_to?(:setup)
14
- @schema_type.setup(fields: @fields)
15
- end
13
+ @schema_type.before_yield(fields: @fields)
16
14
 
17
15
  if block_given?
18
16
  yield(@fields, @schema_type)
19
17
  end
18
+
19
+ @schema_type.after_yield
20
20
  end
21
21
 
22
22
  attr_reader :fields
@@ -25,6 +25,14 @@ module Super
25
25
  fields.keys
26
26
  end
27
27
 
28
+ def to_partial_path
29
+ @schema_type.to_partial_path
30
+ end
31
+
32
+ # This class can be thought of as a Hash, where the keys usually refer to
33
+ # the model's column name and the value refers to the column type. Note
34
+ # though that this isn't always the case—different `SchemaTypes` can do
35
+ # whatever makes sense in their context
28
36
  class Fields
29
37
  include Enumerable
30
38
 
@@ -44,9 +52,13 @@ module Super
44
52
  @backing.keys
45
53
  end
46
54
 
47
- def each
55
+ def values
56
+ @backing.values
57
+ end
58
+
59
+ def each(&block)
48
60
  if block_given?
49
- return @backing.each(&Proc.new)
61
+ return @backing.each(&block)
50
62
  end
51
63
 
52
64
  enum_for(:each)
@@ -65,6 +77,8 @@ module Super
65
77
  inside = {}
66
78
  @backing = inside
67
79
  yield
80
+ return inside
81
+ ensure
68
82
  @backing = outside
69
83
  inside
70
84
  end
@@ -1,3 +1,3 @@
1
1
  module Super
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end