super 0.19.0.rc1 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/app/controllers/super/application_controller.rb +10 -19
- data/app/controllers/super/sitewide_controller.rb +33 -0
- data/app/controllers/super/substructure_controller.rb +63 -85
- data/app/controllers/super/view_controller.rb +55 -0
- data/app/views/super/application/_batch_checkbox.html.erb +4 -0
- data/app/views/super/application/_display_index.html.erb +8 -2
- data/app/views/super/application/_display_show.html.erb +10 -2
- data/app/views/super/application/_filter.html.erb +63 -59
- data/app/views/super/application/_form.html.erb +1 -1
- data/app/views/super/application/_layout.html.erb +0 -2
- data/app/views/super/application/_pagination.html.erb +1 -4
- data/app/views/super/application/_query.html.erb +13 -12
- data/app/views/super/application/_site_footer.html.erb +1 -1
- data/app/views/super/application/_sort.html.erb +18 -14
- data/app/views/super/application/_view_chain.html.erb +23 -4
- data/config/locales/en.yml +10 -1
- data/frontend/super-frontend/dist/application.js +6276 -6286
- data/frontend/super-frontend/dist/package.json +2 -2
- data/lib/super/action_inquirer.rb +3 -0
- data/lib/super/badge.rb +11 -2
- data/lib/super/cheat.rb +6 -1
- data/lib/super/display/schema_types.rb +37 -14
- data/lib/super/display.rb +5 -4
- data/lib/super/error.rb +3 -2
- data/lib/super/form/schema_types.rb +8 -36
- data/lib/super/form_builder/action_text_methods.rb +16 -0
- data/lib/super/form_builder/base_methods.rb +73 -0
- data/lib/super/form_builder/flatpickr_methods.rb +75 -0
- data/lib/super/form_builder/option_methods.rb +73 -0
- data/lib/super/form_builder.rb +143 -0
- data/{app/helpers → lib}/super/form_builder_helper.rb +15 -4
- data/lib/super/link.rb +47 -63
- data/lib/super/link_builder.rb +24 -43
- data/lib/super/navigation.rb +40 -40
- data/lib/super/query.rb +61 -0
- data/lib/super/{engine.rb → railtie.rb} +7 -1
- data/lib/super/reset.rb +7 -0
- data/lib/super/schema.rb +8 -2
- data/lib/super/sort.rb +1 -3
- data/lib/super/useful/deprecations.rb +18 -0
- data/lib/super/useful/i19.rb +35 -0
- data/lib/super/version.rb +1 -1
- data/lib/super/view_chain.rb +14 -4
- data/lib/super.rb +14 -3
- metadata +21 -56
- data/config/routes.rb +0 -4
- data/lib/super/form/builder.rb +0 -289
- data/lib/super/query/form_object.rb +0 -48
@@ -10,9 +10,9 @@ module Super
|
|
10
10
|
# Super's version of `#form_for`
|
11
11
|
def super_form_for(record, options = {}, &block)
|
12
12
|
original = ActionView::Base.field_error_proc
|
13
|
-
ActionView::Base.field_error_proc =
|
13
|
+
ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
|
14
14
|
|
15
|
-
options[:builder] ||=
|
15
|
+
options[:builder] ||= FormBuilder
|
16
16
|
return form_for(record, options, &block)
|
17
17
|
ensure
|
18
18
|
ActionView::Base.field_error_proc = original
|
@@ -21,12 +21,23 @@ module Super
|
|
21
21
|
# Super's version of `#form_with`
|
22
22
|
def super_form_with(**options, &block)
|
23
23
|
original = ActionView::Base.field_error_proc
|
24
|
-
ActionView::Base.field_error_proc =
|
24
|
+
ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
|
25
25
|
|
26
|
-
options[:builder] ||=
|
26
|
+
options[:builder] ||= FormBuilder
|
27
27
|
return form_with(**options, &block)
|
28
28
|
ensure
|
29
29
|
ActionView::Base.field_error_proc = original
|
30
30
|
end
|
31
|
+
|
32
|
+
# Super's version of `#fields_for`
|
33
|
+
def super_fields_for(*args, **options, &block)
|
34
|
+
original = ActionView::Base.field_error_proc
|
35
|
+
ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
|
36
|
+
|
37
|
+
options[:builder] ||= FormBuilder
|
38
|
+
return fields_for(*args, **options, &block)
|
39
|
+
ensure
|
40
|
+
ActionView::Base.field_error_proc = original
|
41
|
+
end
|
31
42
|
end
|
32
43
|
end
|
data/lib/super/link.rb
CHANGED
@@ -9,75 +9,43 @@ module Super
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.find(link)
|
12
|
-
if link.kind_of?(self)
|
13
|
-
return link
|
14
|
-
end
|
15
|
-
|
16
12
|
if registry.key?(link)
|
17
|
-
|
13
|
+
found = registry[link]
|
14
|
+
|
15
|
+
if found.is_a?(LinkBuilder)
|
16
|
+
return found.dup
|
17
|
+
else
|
18
|
+
return found
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
raise Error::LinkNotRegistered, "Unknown link `#{link}`"
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.registry
|
24
|
-
@registry ||= {
|
25
|
-
new
|
26
|
-
"
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
-> (record:, params:) {
|
48
|
-
{
|
49
|
-
controller: params[:controller],
|
50
|
-
action: :show,
|
51
|
-
id: record,
|
52
|
-
only_path: true
|
53
|
-
}
|
54
|
-
}
|
55
|
-
),
|
56
|
-
edit: LinkBuilder.new(
|
57
|
-
"Edit",
|
58
|
-
-> (record:, params:) {
|
59
|
-
{
|
60
|
-
controller: params[:controller],
|
61
|
-
action: :edit,
|
62
|
-
id: record,
|
63
|
-
only_path: true
|
64
|
-
}
|
65
|
-
}
|
66
|
-
),
|
67
|
-
destroy: LinkBuilder.new(
|
68
|
-
"Delete",
|
69
|
-
-> (record:, params:) {
|
70
|
-
{
|
71
|
-
controller: params[:controller],
|
72
|
-
action: :destroy,
|
73
|
-
id: record,
|
74
|
-
only_path: true
|
75
|
-
}
|
76
|
-
},
|
77
|
-
method: :delete,
|
78
|
-
data: { confirm: "Really delete?" }
|
79
|
-
),
|
80
|
-
}
|
26
|
+
@registry ||= {}.tap do |reg|
|
27
|
+
reg[:new] = LinkBuilder.new
|
28
|
+
.text { |params:| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.new") }
|
29
|
+
.href { |params:| { controller: params[:controller], action: :new, only_path: true } }
|
30
|
+
.freeze
|
31
|
+
reg[:index] = LinkBuilder.new
|
32
|
+
.text { |params:| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.index") }
|
33
|
+
.href { |params:| { controller: params[:controller], action: :index, only_path: true } }
|
34
|
+
.freeze
|
35
|
+
reg[:show] = LinkBuilder.new
|
36
|
+
.text { |params:, **| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.show") }
|
37
|
+
.href { |params:, record:| { controller: params[:controller], action: :show, id: record, only_path: true } }
|
38
|
+
.freeze
|
39
|
+
reg[:edit] = LinkBuilder.new
|
40
|
+
.text { |params:, **| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.edit") }
|
41
|
+
.href { |params:, record:| { controller: params[:controller], action: :edit, id: record, only_path: true } }
|
42
|
+
.freeze
|
43
|
+
reg[:destroy] = LinkBuilder.new
|
44
|
+
.text { |params:, **| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.destroy") }
|
45
|
+
.href { |params:, record:| { controller: params[:controller], action: :destroy, id: record, only_path: true } }
|
46
|
+
.options { |**| { method: :delete, data: { confirm: "Really delete?" } } }
|
47
|
+
.freeze
|
48
|
+
end
|
81
49
|
end
|
82
50
|
|
83
51
|
def self.polymorphic_parts(*parts_tail)
|
@@ -85,15 +53,31 @@ module Super
|
|
85
53
|
parts_head.map { |part| part.is_a?(String) ? part.to_sym : part } + parts_tail
|
86
54
|
end
|
87
55
|
|
56
|
+
# The first argument should be the text of the link. If it's an array,
|
57
|
+
# it'll send it directly into `I18n.t`
|
88
58
|
def initialize(text, href, **options)
|
89
59
|
@text = text
|
90
60
|
@href = href
|
91
61
|
@options = options
|
92
62
|
end
|
93
63
|
|
94
|
-
attr_reader :text
|
95
64
|
attr_reader :options
|
96
65
|
|
66
|
+
def text
|
67
|
+
if @text.is_a?(Array)
|
68
|
+
*head, tail = @text
|
69
|
+
if !tail.is_a?(Hash)
|
70
|
+
head.push(tail)
|
71
|
+
tail = {}
|
72
|
+
end
|
73
|
+
|
74
|
+
@text = I18n.t(*head, **tail)
|
75
|
+
return @text
|
76
|
+
end
|
77
|
+
|
78
|
+
@text
|
79
|
+
end
|
80
|
+
|
97
81
|
def href
|
98
82
|
if @href.is_a?(String)
|
99
83
|
return @href
|
data/lib/super/link_builder.rb
CHANGED
@@ -2,53 +2,34 @@
|
|
2
2
|
|
3
3
|
module Super
|
4
4
|
class LinkBuilder
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
5
|
+
%i[text href options].each do |method_name|
|
6
|
+
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
7
|
+
def #{method_name}(&block)
|
8
|
+
@#{method_name} = block
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def process_#{method_name}(&block)
|
13
|
+
@process_#{method_name} = block
|
14
|
+
self
|
15
|
+
end
|
16
|
+
RUBY
|
18
17
|
end
|
19
18
|
|
20
|
-
attr_reader :requirements
|
21
|
-
|
22
19
|
def resolve(**kwargs)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
raise Super::Error::IncompleteBuilder, "LinkBuilder requires that #text is set" if @text.nil?
|
21
|
+
raise Super::Error::IncompleteBuilder, "LinkBuilder requires that #href is set" if @href.nil?
|
22
|
+
|
23
|
+
@options ||= -> (**) { {} }
|
24
|
+
@process_text ||= -> (t) { t }
|
25
|
+
@process_href ||= -> (h) { h }
|
26
|
+
@process_options ||= -> (o) { o }
|
27
|
+
|
28
|
+
Super::Link.new(
|
29
|
+
@process_text.call(@text.call(**kwargs)),
|
30
|
+
@process_href.call(@href.call(**kwargs)),
|
31
|
+
**@process_options.call(@options.call(**kwargs))
|
27
32
|
)
|
28
33
|
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def known_requirements
|
33
|
-
%i[params record].freeze
|
34
|
-
end
|
35
|
-
|
36
|
-
def gather_requirements(value_or_proc)
|
37
|
-
return [] if !value_or_proc.is_a?(Proc)
|
38
|
-
|
39
|
-
requirements =
|
40
|
-
value_or_proc
|
41
|
-
.parameters
|
42
|
-
.select { |(kind, name)| kind = :keyreq }
|
43
|
-
.map(&:last)
|
44
|
-
end
|
45
|
-
|
46
|
-
def into_value(value_or_proc, kwargs)
|
47
|
-
if value_or_proc.kind_of?(Proc)
|
48
|
-
value_or_proc.call(**kwargs)
|
49
|
-
else
|
50
|
-
value_or_proc
|
51
|
-
end
|
52
|
-
end
|
53
34
|
end
|
54
35
|
end
|
data/lib/super/navigation.rb
CHANGED
@@ -4,14 +4,14 @@ module Super
|
|
4
4
|
class Navigation
|
5
5
|
def initialize
|
6
6
|
@builder = Builder.new
|
7
|
-
|
8
|
-
if
|
9
|
-
|
7
|
+
result = yield @builder
|
8
|
+
if result.is_a?(Array)
|
9
|
+
Useful::Deprecation["0.22"].deprecation_warning("returning an array", "calling a Super::Navigation builder method defines the navigation")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def definition
|
14
|
-
return @
|
14
|
+
return @definition if instance_variable_defined?(:@definition)
|
15
15
|
|
16
16
|
searcher = RouteFormatterButReallySearcher.new
|
17
17
|
inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
|
@@ -19,37 +19,12 @@ module Super
|
|
19
19
|
all_matches = searcher.matches
|
20
20
|
unused_matches = all_matches.each_with_object({}) { |match, hash| hash[match] = true }
|
21
21
|
|
22
|
-
defs =
|
23
|
-
|
24
|
-
@defs = expand_directives(defs, all_matches, unused_matches.keys)
|
22
|
+
defs = validate_and_determine_explicit_links(@builder.build, unused_matches)
|
23
|
+
@definition = expand_directives(defs, all_matches, unused_matches.keys)
|
25
24
|
end
|
26
25
|
|
27
26
|
private
|
28
27
|
|
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
28
|
def validate_and_determine_explicit_links(definition, unused_links)
|
54
29
|
definition.each do |link_or_menu_or_rest|
|
55
30
|
if link_or_menu_or_rest.is_a?(Super::Link)
|
@@ -103,31 +78,56 @@ module Super
|
|
103
78
|
Menu = Struct.new(:title, :links)
|
104
79
|
|
105
80
|
class Builder
|
81
|
+
def initialize
|
82
|
+
@links = []
|
83
|
+
@menu_level = 0
|
84
|
+
end
|
85
|
+
|
86
|
+
def build
|
87
|
+
@links
|
88
|
+
end
|
89
|
+
|
106
90
|
def link(model, **kwargs)
|
107
91
|
text = model.model_name.human.pluralize
|
108
92
|
parts = Super::Link.polymorphic_parts(model)
|
109
93
|
|
110
|
-
Super::Link.new(text, parts, **kwargs)
|
94
|
+
@links.push(Super::Link.new(text, parts, **kwargs))
|
95
|
+
self
|
111
96
|
end
|
112
97
|
|
113
98
|
def link_to(*args, **kwargs)
|
114
|
-
Super::Link.new(*args, **kwargs)
|
99
|
+
@links.push(Super::Link.new(*args, **kwargs))
|
100
|
+
self
|
115
101
|
end
|
116
102
|
|
117
|
-
def menu(title
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
103
|
+
def menu(title)
|
104
|
+
if @menu_level > 0
|
105
|
+
raise Super::Error::ArgumentError, "Navigation menus can't be nested"
|
106
|
+
end
|
107
|
+
|
108
|
+
begin
|
109
|
+
@menu_level += 1
|
110
|
+
original_links = @links
|
111
|
+
@links = []
|
112
|
+
yield
|
113
|
+
menu_links = @links
|
114
|
+
ensure
|
115
|
+
@links = original_links
|
116
|
+
@menu_level -= 1
|
122
117
|
end
|
118
|
+
|
119
|
+
@links.push(Menu.new(title, menu_links))
|
120
|
+
self
|
123
121
|
end
|
124
122
|
|
125
123
|
def rest
|
126
|
-
REST
|
124
|
+
@links.push(REST)
|
125
|
+
self
|
127
126
|
end
|
128
127
|
|
129
128
|
def all
|
130
|
-
ALL
|
129
|
+
@links.push(ALL)
|
130
|
+
self
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
data/lib/super/query.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
class Query
|
5
|
+
def initialize(model:, params:, current_path:)
|
6
|
+
@model = model
|
7
|
+
@params = params
|
8
|
+
@path = current_path
|
9
|
+
@addons = {}
|
10
|
+
@backwards_addons = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :addons
|
14
|
+
attr_reader :model
|
15
|
+
attr_reader :params
|
16
|
+
attr_reader :path
|
17
|
+
attr_reader :backwards_addons
|
18
|
+
|
19
|
+
private :model
|
20
|
+
private :params
|
21
|
+
private :backwards_addons
|
22
|
+
|
23
|
+
def build(klass, namespace:, **additional_initialization_arguments)
|
24
|
+
params_for_querier =
|
25
|
+
params.fetch(namespace) { ActiveSupport::HashWithIndifferentAccess.new }
|
26
|
+
|
27
|
+
instance = klass.new(
|
28
|
+
model: model,
|
29
|
+
params: params_for_querier,
|
30
|
+
**additional_initialization_arguments
|
31
|
+
)
|
32
|
+
|
33
|
+
addons[namespace] = instance
|
34
|
+
backwards_addons[instance] = namespace
|
35
|
+
instance
|
36
|
+
end
|
37
|
+
|
38
|
+
def namespace_for(query_form_object)
|
39
|
+
backwards_addons.fetch(query_form_object)
|
40
|
+
end
|
41
|
+
|
42
|
+
def form_options
|
43
|
+
{
|
44
|
+
url: path,
|
45
|
+
method: :get
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def apply_changes(records)
|
50
|
+
addons.each_value do |addon|
|
51
|
+
records = addon.apply_changes(records)
|
52
|
+
end
|
53
|
+
|
54
|
+
records
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_partial_path
|
58
|
+
"query"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Super
|
4
4
|
# Configures the host Rails app to work with Super
|
5
|
-
class
|
5
|
+
class Railtie < ::Rails::Engine
|
6
6
|
isolate_namespace Super
|
7
7
|
|
8
8
|
initializer "super.assets.precompile" do |app|
|
@@ -11,6 +11,12 @@ module Super
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
initializer "super.inclusion" do
|
15
|
+
ActiveSupport.on_load(:action_view) do
|
16
|
+
include Super::FormBuilderHelper
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
config.to_prepare do
|
15
21
|
Super::Plugin::Registry.controller.ordered do |klass, method_name|
|
16
22
|
Super::ApplicationController.public_send(method_name, klass)
|
data/lib/super/reset.rb
CHANGED
@@ -16,6 +16,8 @@ module Super
|
|
16
16
|
# Defined in Super::ApplicationController
|
17
17
|
current_action: true,
|
18
18
|
with_current_action: true,
|
19
|
+
|
20
|
+
# Keep all of the ones in Super::SitewideController
|
19
21
|
}
|
20
22
|
|
21
23
|
included do
|
@@ -27,6 +29,11 @@ module Super
|
|
27
29
|
undef_method :update
|
28
30
|
undef_method :destroy
|
29
31
|
|
32
|
+
Super::ViewController.private_instance_methods(false).each do |imethod|
|
33
|
+
next if KEEP.key?(imethod)
|
34
|
+
undef_method imethod
|
35
|
+
end
|
36
|
+
|
30
37
|
Super::SubstructureController.private_instance_methods(false).each do |imethod|
|
31
38
|
next if KEEP.key?(imethod)
|
32
39
|
undef_method imethod
|
data/lib/super/schema.rb
CHANGED
@@ -14,8 +14,9 @@ module Super
|
|
14
14
|
class Fields
|
15
15
|
include Enumerable
|
16
16
|
|
17
|
-
def initialize
|
17
|
+
def initialize(transform_value_on_set: nil)
|
18
18
|
@backing = {}
|
19
|
+
@transform_value_on_set = transform_value_on_set
|
19
20
|
end
|
20
21
|
|
21
22
|
def [](key)
|
@@ -23,7 +24,12 @@ module Super
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def []=(key, value)
|
26
|
-
@backing[key] =
|
27
|
+
@backing[key] =
|
28
|
+
if @transform_value_on_set
|
29
|
+
@transform_value_on_set.call(value)
|
30
|
+
else
|
31
|
+
value
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
def keys
|
data/lib/super/sort.rb
CHANGED
@@ -7,11 +7,9 @@ module Super
|
|
7
7
|
|
8
8
|
def initialize(model:, params:, default:, sortable_columns:)
|
9
9
|
@model = model
|
10
|
-
@params = params
|
10
|
+
@params = params
|
11
11
|
@default = default
|
12
12
|
@sortable_columns = sortable_columns.map(&:to_s)
|
13
|
-
|
14
|
-
@params.permit!
|
15
13
|
end
|
16
14
|
|
17
15
|
attr_reader :sortable_columns
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/deprecation"
|
4
|
+
|
5
|
+
module Super
|
6
|
+
module Useful
|
7
|
+
class Deprecation
|
8
|
+
VERSIONS = {
|
9
|
+
"0.22" => ActiveSupport::Deprecation.new("0.22", "Super")
|
10
|
+
}
|
11
|
+
private_constant :VERSIONS
|
12
|
+
|
13
|
+
def self.[](version)
|
14
|
+
VERSIONS.fetch(version)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
module Useful
|
5
|
+
module I19
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def build_chain(prefix, optional, suffix)
|
9
|
+
prefix = Array(prefix)
|
10
|
+
optional = Array(optional)
|
11
|
+
suffix = Array(suffix)
|
12
|
+
|
13
|
+
result = []
|
14
|
+
|
15
|
+
(optional.size + 1).times do
|
16
|
+
lookup = [prefix, optional, suffix].flatten.join(".").to_sym
|
17
|
+
result.push(lookup)
|
18
|
+
optional.pop
|
19
|
+
end
|
20
|
+
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
def chain_to_i18n(chain)
|
25
|
+
head, *tail = chain
|
26
|
+
|
27
|
+
[head, { default: tail }]
|
28
|
+
end
|
29
|
+
|
30
|
+
def i18n_with_fallback(prefix, optional, suffix)
|
31
|
+
chain_to_i18n(build_chain(prefix, optional, suffix))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/super/version.rb
CHANGED
data/lib/super/view_chain.rb
CHANGED
@@ -6,10 +6,6 @@ module Super
|
|
6
6
|
@data = ReorderableHash.new(chain)
|
7
7
|
end
|
8
8
|
|
9
|
-
def chain
|
10
|
-
@chain ||= @data.values
|
11
|
-
end
|
12
|
-
|
13
9
|
def insert(*args, **kwargs)
|
14
10
|
if instance_variable_defined?(:@chain)
|
15
11
|
raise Error::ViewChain::ChainAlreadyStarted
|
@@ -21,5 +17,19 @@ module Super
|
|
21
17
|
def to_partial_path
|
22
18
|
"view_chain"
|
23
19
|
end
|
20
|
+
|
21
|
+
def shift
|
22
|
+
chain.shift
|
23
|
+
end
|
24
|
+
|
25
|
+
def empty?
|
26
|
+
chain.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def chain
|
32
|
+
@chain ||= @data.to_h
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
data/lib/super.rb
CHANGED
@@ -2,11 +2,17 @@
|
|
2
2
|
|
3
3
|
require "tsort"
|
4
4
|
|
5
|
+
if !ENV["SUPER_SKIP_REQUIRE_CSV"]
|
6
|
+
require "csv"
|
7
|
+
end
|
8
|
+
|
5
9
|
require "rails/engine"
|
6
10
|
|
7
11
|
require "super/schema/common"
|
8
12
|
require "super/useful/builder"
|
13
|
+
require "super/useful/deprecations"
|
9
14
|
require "super/useful/enum"
|
15
|
+
require "super/useful/i19"
|
10
16
|
|
11
17
|
require "super/action_inquirer"
|
12
18
|
require "super/assets"
|
@@ -24,12 +30,17 @@ require "super/filter/guesser"
|
|
24
30
|
require "super/filter/operator"
|
25
31
|
require "super/filter/schema_types"
|
26
32
|
require "super/form"
|
27
|
-
require "super/form/builder"
|
28
33
|
require "super/form/field_transcript"
|
29
34
|
require "super/form/guesser"
|
30
35
|
require "super/form/inline_errors"
|
31
36
|
require "super/form/schema_types"
|
32
37
|
require "super/form/strong_params"
|
38
|
+
require "super/form_builder"
|
39
|
+
require "super/form_builder/action_text_methods"
|
40
|
+
require "super/form_builder/base_methods"
|
41
|
+
require "super/form_builder/flatpickr_methods"
|
42
|
+
require "super/form_builder/option_methods"
|
43
|
+
require "super/form_builder_helper"
|
33
44
|
require "super/layout"
|
34
45
|
require "super/link"
|
35
46
|
require "super/link_builder"
|
@@ -39,7 +50,7 @@ require "super/pagination"
|
|
39
50
|
require "super/panel"
|
40
51
|
require "super/partial"
|
41
52
|
require "super/plugin"
|
42
|
-
require "super/query
|
53
|
+
require "super/query"
|
43
54
|
require "super/reorderable_hash"
|
44
55
|
require "super/reset"
|
45
56
|
require "super/schema"
|
@@ -49,4 +60,4 @@ require "super/version"
|
|
49
60
|
require "super/view_chain"
|
50
61
|
require "super/view_helper"
|
51
62
|
|
52
|
-
require "super/
|
63
|
+
require "super/railtie"
|