super 0.0.12 → 0.17.0
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.
- checksums.yaml +4 -4
- data/.yardopts +0 -1
- data/README.md +38 -46
- data/app/assets/javascripts/super/application.js +5747 -3803
- data/app/assets/stylesheets/super/application.css +114686 -71486
- data/app/controllers/super/application_controller.rb +44 -37
- data/app/controllers/super/substructure_controller.rb +276 -0
- data/app/helpers/super/form_builder_helper.rb +7 -0
- data/app/views/layouts/super/application.html.erb +4 -19
- data/app/views/super/application/_collection_header.html.erb +2 -2
- data/app/views/super/application/_display_actions.html.erb +1 -1
- data/app/views/super/application/_display_index.html.erb +2 -2
- data/app/views/super/application/_display_show.html.erb +1 -1
- data/app/views/super/application/_filter.html.erb +62 -2
- data/app/views/super/application/_form_field.html.erb +5 -0
- data/app/views/super/application/_layout.html.erb +1 -1
- data/app/views/super/application/_member_header.html.erb +2 -2
- data/app/views/super/application/_pagination.html.erb +1 -1
- data/app/views/super/application/_site_footer.html.erb +3 -0
- data/app/views/super/application/_site_header.html.erb +17 -0
- data/app/views/super/application/_sort_expression.html.erb +2 -2
- data/app/views/super/feather/README.md +0 -1
- data/frontend/super-frontend/dist/application.css +114686 -71486
- data/frontend/super-frontend/dist/application.js +5747 -3803
- data/lib/generators/super/install/install_generator.rb +0 -16
- data/lib/generators/super/install/templates/base_controller.rb.tt +0 -8
- data/lib/generators/super/resource/templates/resources_controller.rb.tt +4 -4
- data/lib/generators/super/webpacker/webpacker_generator.rb +9 -5
- data/lib/super.rb +5 -2
- data/lib/super/action_inquirer.rb +18 -3
- data/lib/super/assets.rb +44 -23
- data/lib/super/badge.rb +60 -0
- data/lib/super/cheat.rb +17 -0
- data/lib/super/compatibility.rb +19 -0
- data/lib/super/display/guesser.rb +3 -1
- data/lib/super/display/schema_types.rb +51 -2
- data/lib/super/error.rb +2 -0
- data/lib/super/filter.rb +1 -1
- data/lib/super/filter/form_object.rb +74 -48
- data/lib/super/filter/guesser.rb +2 -0
- data/lib/super/filter/operator.rb +90 -64
- data/lib/super/filter/schema_types.rb +63 -80
- data/lib/super/form/builder.rb +110 -27
- data/lib/super/form/field_transcript.rb +43 -0
- data/lib/super/form/guesser.rb +10 -1
- data/lib/super/form/schema_types.rb +73 -16
- data/lib/super/link.rb +38 -32
- data/lib/super/link_builder.rb +58 -0
- data/lib/super/navigation.rb +164 -0
- data/lib/super/pagination.rb +2 -44
- data/lib/super/reset.rb +22 -0
- data/lib/super/schema.rb +4 -0
- data/lib/super/useful/builder.rb +4 -4
- data/lib/super/version.rb +1 -1
- data/lib/tasks/super/cheat.rake +9 -0
- metadata +14 -19
- data/CONTRIBUTING.md +0 -56
- data/Rakefile +0 -36
- data/app/views/super/application/_filter_type_select.html.erb +0 -21
- data/app/views/super/application/_filter_type_text.html.erb +0 -18
- data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
- data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
- data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
- data/app/views/super/application/_form_field_select.html.erb +0 -1
- data/app/views/super/application/_form_field_text.html.erb +0 -1
- data/app/views/super/feather/_chevron_down.html +0 -1
- data/docs/cheat.md +0 -41
- data/lib/super/controls.rb +0 -22
- data/lib/super/controls/optional.rb +0 -113
- data/lib/super/controls/steps.rb +0 -106
- data/lib/super/controls/view.rb +0 -55
- data/lib/super/navigation/automatic.rb +0 -73
@@ -36,22 +36,6 @@ module Super
|
|
36
36
|
create_file("app/controllers/#{controller_namespace}/.keep", "")
|
37
37
|
end
|
38
38
|
|
39
|
-
def copy_cheatsheet
|
40
|
-
super_path = Pathname.new(Gem.loaded_specs["super"].full_gem_path).expand_path
|
41
|
-
super_cheat_path = super_path.join("docs", "cheat.md")
|
42
|
-
|
43
|
-
path =
|
44
|
-
if options["controller_namespace"].present?
|
45
|
-
"app/controllers/#{controller_namespace}/README.md"
|
46
|
-
else
|
47
|
-
"app/controllers/README.md"
|
48
|
-
end
|
49
|
-
|
50
|
-
create_file(path) do
|
51
|
-
super_cheat_path.read.sub(%r{<!--.*?-->}m, "").strip + "\n"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
39
|
def setup_sprockets4_manifest
|
56
40
|
append_to_file "app/assets/config/manifest.js", "//= link super_manifest.js\n"
|
57
41
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= controller_class_name %>Controller < <%= parent_controller_name.classify %>Controller
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
private
|
4
|
+
|
5
|
+
def model
|
6
|
+
<%= class_name %>
|
7
7
|
end
|
8
8
|
end
|
9
9
|
<% end -%>
|
@@ -5,10 +5,14 @@ module Super
|
|
5
5
|
source_root File.expand_path("templates", __dir__)
|
6
6
|
|
7
7
|
def copy_the_pack_file
|
8
|
-
|
9
|
-
"
|
10
|
-
|
11
|
-
|
8
|
+
path =
|
9
|
+
if Gem::Dependency.new("webpacker", ">= 6.0.0.beta2", "!= 6.0.0.pre1", "!= 6.0.0.pre2").matching_specs.any?
|
10
|
+
"app/packs/entrypoints/super/application.js.erb"
|
11
|
+
else
|
12
|
+
"app/javascript/packs/super/application.js.erb"
|
13
|
+
end
|
14
|
+
|
15
|
+
template("pack_super_application.js.erb", path)
|
12
16
|
end
|
13
17
|
|
14
18
|
def set_asset_handler_to_webpacker
|
@@ -16,7 +20,7 @@ module Super
|
|
16
20
|
"config/initializers/super.rb",
|
17
21
|
" c.javascripts = Super::Assets.use_webpacker(c.javascripts)\n" \
|
18
22
|
" c.stylesheets = Super::Assets.use_webpacker(c.stylesheets)\n",
|
19
|
-
before:
|
23
|
+
before: /^end\b/
|
20
24
|
)
|
21
25
|
end
|
22
26
|
|
data/lib/super.rb
CHANGED
@@ -10,10 +10,10 @@ require "super/useful/enum"
|
|
10
10
|
|
11
11
|
require "super/action_inquirer"
|
12
12
|
require "super/assets"
|
13
|
+
require "super/badge"
|
13
14
|
require "super/client_error"
|
14
15
|
require "super/compatibility"
|
15
16
|
require "super/configuration"
|
16
|
-
require "super/controls"
|
17
17
|
require "super/display"
|
18
18
|
require "super/display/guesser"
|
19
19
|
require "super/display/schema_types"
|
@@ -25,18 +25,21 @@ require "super/filter/operator"
|
|
25
25
|
require "super/filter/schema_types"
|
26
26
|
require "super/form"
|
27
27
|
require "super/form/builder"
|
28
|
+
require "super/form/field_transcript"
|
28
29
|
require "super/form/guesser"
|
29
30
|
require "super/form/inline_errors"
|
30
31
|
require "super/form/schema_types"
|
31
32
|
require "super/form/strong_params"
|
32
33
|
require "super/layout"
|
33
34
|
require "super/link"
|
34
|
-
require "super/
|
35
|
+
require "super/link_builder"
|
36
|
+
require "super/navigation"
|
35
37
|
require "super/pagination"
|
36
38
|
require "super/panel"
|
37
39
|
require "super/partial"
|
38
40
|
require "super/plugin"
|
39
41
|
require "super/query/form_object"
|
42
|
+
require "super/reset"
|
40
43
|
require "super/schema"
|
41
44
|
require "super/schema/guesser"
|
42
45
|
require "super/sort"
|
@@ -19,12 +19,27 @@ module Super
|
|
19
19
|
#
|
20
20
|
def self.default_for_resources
|
21
21
|
{
|
22
|
-
read
|
23
|
-
write
|
24
|
-
delete
|
22
|
+
"read" => %w[index show new edit],
|
23
|
+
"write" => %w[create update destroy],
|
24
|
+
"delete" => %w[destroy],
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
+
# @return [ActionInquirer]
|
29
|
+
def self.index!; new(default_for_resources, "index"); end
|
30
|
+
# @return [ActionInquirer]
|
31
|
+
def self.show!; new(default_for_resources, "show"); end
|
32
|
+
# @return [ActionInquirer]
|
33
|
+
def self.new!; new(default_for_resources, "new"); end
|
34
|
+
# @return [ActionInquirer]
|
35
|
+
def self.edit!; new(default_for_resources, "edit"); end
|
36
|
+
# @return [ActionInquirer]
|
37
|
+
def self.create!; new(default_for_resources, "create"); end
|
38
|
+
# @return [ActionInquirer]
|
39
|
+
def self.update!; new(default_for_resources, "update"); end
|
40
|
+
# @return [ActionInquirer]
|
41
|
+
def self.destroy!; new(default_for_resources, "destroy"); end
|
42
|
+
|
28
43
|
def initialize(categories_and_their_actions, action)
|
29
44
|
@categories = categories_and_their_actions.keys.map(&:to_s)
|
30
45
|
@actions = categories_and_their_actions.values.flatten.uniq.map(&:to_s)
|
data/lib/super/assets.rb
CHANGED
@@ -21,7 +21,7 @@ module Super
|
|
21
21
|
assets.map do |asset|
|
22
22
|
grep_matches = grep && asset === grep
|
23
23
|
if grep_matches || !grep
|
24
|
-
asset.
|
24
|
+
asset.send(:handler=, Handler.webpacker)
|
25
25
|
end
|
26
26
|
|
27
27
|
asset
|
@@ -34,7 +34,7 @@ module Super
|
|
34
34
|
assets.map do |asset|
|
35
35
|
grep_matches = grep && asset === grep
|
36
36
|
if grep_matches || !grep
|
37
|
-
asset.
|
37
|
+
asset.send(:handler=, Handler.sprockets)
|
38
38
|
end
|
39
39
|
|
40
40
|
asset
|
@@ -52,6 +52,14 @@ module Super
|
|
52
52
|
attr_reader :path
|
53
53
|
attr_reader :arguments
|
54
54
|
|
55
|
+
def ==(other)
|
56
|
+
return false if handler != other.handler
|
57
|
+
return false if path != other.path
|
58
|
+
return false if arguments != other.arguments
|
59
|
+
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
55
63
|
def ===(other)
|
56
64
|
return true if path == other
|
57
65
|
return true if other.is_a?(Regexp) && path.match?(other)
|
@@ -61,6 +69,10 @@ module Super
|
|
61
69
|
|
62
70
|
false
|
63
71
|
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
attr_writer :handler
|
64
76
|
end
|
65
77
|
|
66
78
|
def self.dist(gem_name, package_name)
|
@@ -74,29 +86,34 @@ module Super
|
|
74
86
|
end
|
75
87
|
|
76
88
|
class Handler
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
else
|
94
|
-
none
|
89
|
+
class << self
|
90
|
+
def auto
|
91
|
+
sprockets_spec = gem_specification("sprockets")
|
92
|
+
if sprockets_spec
|
93
|
+
major = sprockets_spec.version.segments.first
|
94
|
+
if major >= 2
|
95
|
+
return sprockets
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
webpacker_spec = gem_specification("webpacker")
|
100
|
+
if webpacker_spec
|
101
|
+
major = webpacker_spec.version.segments.first
|
102
|
+
if major >= 4
|
103
|
+
return webpacker
|
104
|
+
end
|
95
105
|
end
|
96
|
-
end
|
97
106
|
|
98
|
-
|
99
|
-
|
107
|
+
none
|
108
|
+
end
|
109
|
+
|
110
|
+
def sprockets_available?
|
111
|
+
!gem_specification("sprockets").nil? && defined?(Sprockets)
|
112
|
+
end
|
113
|
+
|
114
|
+
def gem_specification(gem_name)
|
115
|
+
Gem::Dependency.new(gem_name).matching_specs&.sort_by(&:version)&.first
|
116
|
+
end
|
100
117
|
end
|
101
118
|
|
102
119
|
def self.sprockets
|
@@ -115,6 +132,10 @@ module Super
|
|
115
132
|
@asset_handler = asset_handler
|
116
133
|
end
|
117
134
|
|
135
|
+
def ==(other)
|
136
|
+
to_sym == other.to_sym
|
137
|
+
end
|
138
|
+
|
118
139
|
def sprockets?
|
119
140
|
@asset_handler == :sprockets
|
120
141
|
end
|
data/lib/super/badge.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
class Badge
|
5
|
+
STYLES = {
|
6
|
+
light: "bg-gray-100 text-black",
|
7
|
+
dark: "bg-gray-900 text-white",
|
8
|
+
red: "bg-red-700 text-white",
|
9
|
+
yellow: "bg-yellow-400 text-black",
|
10
|
+
green: "bg-green-700 text-white",
|
11
|
+
blue: "bg-blue-700 text-white",
|
12
|
+
purple: "bg-purple-800 text-white",
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(text, styles: nil)
|
16
|
+
@text = text
|
17
|
+
@requested_styles = Array(styles.presence).flatten
|
18
|
+
end
|
19
|
+
|
20
|
+
def styles
|
21
|
+
return @styles if instance_variable_defined?(:@styles)
|
22
|
+
@styles =
|
23
|
+
if requested_styles.delete(:reset)
|
24
|
+
[]
|
25
|
+
else
|
26
|
+
COMMON_STYLES
|
27
|
+
end
|
28
|
+
|
29
|
+
if requested_styles.empty?
|
30
|
+
@styles += [STYLES[:light]]
|
31
|
+
else
|
32
|
+
requested_styles.each do |style|
|
33
|
+
@styles +=
|
34
|
+
if STYLES.key?(style)
|
35
|
+
[STYLES[style]]
|
36
|
+
else
|
37
|
+
[style]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@styles
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
ActionController::Base.helpers.content_tag(
|
47
|
+
:span,
|
48
|
+
@text,
|
49
|
+
class: styles.join(" ")
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
COMMON_STYLES = %w[rounded px-2 py-1 text-xs leading-none font-bold]
|
56
|
+
private_constant :COMMON_STYLES
|
57
|
+
|
58
|
+
attr_reader :requested_styles
|
59
|
+
end
|
60
|
+
end
|
data/lib/super/cheat.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
class Cheat
|
5
|
+
def controller
|
6
|
+
paths = %w[../../app/controllers/super/substructure_controller.rb]
|
7
|
+
methods =
|
8
|
+
paths
|
9
|
+
.map { |f| File.read(File.expand_path(f, __dir__)) }
|
10
|
+
.flat_map { |content| content.scan(/^\s+(?:helper_method )?def .*$/) }
|
11
|
+
.map { |method| method.strip.sub(/^(?:helper_method )?def /, "#") }
|
12
|
+
|
13
|
+
puts "== Super::ApplicationController"
|
14
|
+
puts methods.join("\n")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/super/compatibility.rb
CHANGED
@@ -23,5 +23,24 @@ module Super
|
|
23
23
|
ActiveRecord::Base.sanitize_sql_like(query)
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
def polymorphic_path_container
|
28
|
+
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 0
|
29
|
+
@polymorphic_path_container ||=
|
30
|
+
begin
|
31
|
+
klass = Class.new do
|
32
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
33
|
+
|
34
|
+
def method_missing(method_name)
|
35
|
+
Rails.application.routes.url_helpers.public_send(method_name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
klass.new
|
40
|
+
end
|
41
|
+
else
|
42
|
+
Rails.application.routes.url_helpers
|
43
|
+
end
|
44
|
+
end
|
26
45
|
end
|
27
46
|
end
|
@@ -61,6 +61,47 @@ module Super
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
class Badge
|
65
|
+
extend Useful::Builder
|
66
|
+
|
67
|
+
def initialize(builder)
|
68
|
+
@builder = builder
|
69
|
+
@whens = {}
|
70
|
+
format_for_lookup(&:itself)
|
71
|
+
format_for_display(&:itself)
|
72
|
+
end
|
73
|
+
|
74
|
+
builder_with_block def when(*patterns, &block)
|
75
|
+
patterns.each do |pattern|
|
76
|
+
@whens[pattern] = block
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
builder_with_block def else(&block)
|
81
|
+
@else = block
|
82
|
+
end
|
83
|
+
|
84
|
+
builder_with_block def format_for_lookup(&block)
|
85
|
+
@format_for_lookup = block
|
86
|
+
end
|
87
|
+
|
88
|
+
builder_with_block def format_for_display(&block)
|
89
|
+
@format_for_display = block
|
90
|
+
end
|
91
|
+
|
92
|
+
def build
|
93
|
+
@builder.transform do |value|
|
94
|
+
lookup_value = @format_for_lookup.call(value)
|
95
|
+
block = @whens[lookup_value] || @else
|
96
|
+
Super::Badge.new(
|
97
|
+
@format_for_display.call(value),
|
98
|
+
styles: block&.call
|
99
|
+
)
|
100
|
+
end
|
101
|
+
@builder.build
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
64
105
|
def initialize(fields:)
|
65
106
|
@actions_called = false
|
66
107
|
@fields = fields
|
@@ -89,16 +130,24 @@ module Super
|
|
89
130
|
end
|
90
131
|
|
91
132
|
def string; real(&:to_s); end
|
92
|
-
alias text string
|
93
133
|
|
94
134
|
def timestamp; real(&:to_s); end
|
135
|
+
def time; real { |value| value.strftime("%H:%M:%S") }; end
|
95
136
|
|
96
137
|
def rich_text
|
97
|
-
|
138
|
+
computed do |value|
|
98
139
|
Partial.new("display_rich_text", locals: { rich_text: value })
|
99
140
|
end
|
100
141
|
end
|
101
142
|
|
143
|
+
def badge(*builder_methods)
|
144
|
+
builder_methods = %i[real ignore_nil column] if builder_methods.empty?
|
145
|
+
builder = builder_methods.each_with_object(Builder.new) do |builder_method, builder|
|
146
|
+
builder.public_send(builder_method)
|
147
|
+
end
|
148
|
+
Badge.new(builder)
|
149
|
+
end
|
150
|
+
|
102
151
|
def actions
|
103
152
|
@actions_called = true
|
104
153
|
Builder.new.computed.none.transform do
|