super 0.0.11 → 0.0.12
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 -8
- data/README.md +4 -8
- data/app/controllers/super/application_controller.rb +5 -5
- data/app/views/layouts/super/application.html.erb +1 -3
- data/app/views/super/application/{_super_schema_display_actions.html.erb → _display_actions.html.erb} +0 -0
- data/app/views/super/application/{_super_schema_display_index.html.erb → _display_index.html.erb} +3 -3
- data/app/views/super/application/_display_show.html.erb +8 -0
- data/app/views/super/application/{_super_schema_form.html.erb → _form.html.erb} +2 -2
- data/app/views/super/application/{_super_layout.html.erb → _layout.html.erb} +7 -7
- data/app/views/super/application/{_super_pagination.html.erb → _pagination.html.erb} +1 -1
- data/app/views/super/application/{_super_panel.html.erb → _panel.html.erb} +2 -2
- data/lib/generators/super/install/install_generator.rb +16 -7
- data/lib/generators/super/install/templates/base_controller.rb.tt +9 -1
- data/lib/generators/super/install/templates/initializer.rb.tt +9 -2
- data/lib/generators/super/resource/resource_generator.rb +105 -30
- data/lib/generators/super/resource/templates/resources_controller.rb.tt +3 -9
- data/lib/super.rb +2 -0
- data/lib/super/configuration.rb +14 -23
- data/lib/super/controls.rb +7 -2
- data/lib/super/controls/optional.rb +1 -0
- data/lib/super/display.rb +16 -8
- data/lib/super/display/schema_types.rb +70 -33
- data/lib/super/error.rb +7 -0
- data/lib/super/form.rb +1 -1
- data/lib/super/layout.rb +1 -1
- data/lib/super/link.rb +5 -0
- data/lib/super/navigation/automatic.rb +2 -2
- data/lib/super/pagination.rb +1 -1
- data/lib/super/panel.rb +1 -1
- data/lib/super/useful/builder.rb +25 -0
- data/lib/super/useful/enum.rb +63 -0
- data/lib/super/version.rb +1 -1
- metadata +17 -19
- data/STABILITY.md +0 -50
- data/app/views/super/application/_super_schema_display_show.html.erb +0 -8
- data/docs/README.md +0 -8
- data/docs/action_text.md +0 -48
- data/docs/faq.md +0 -44
- data/docs/installation.md +0 -21
- data/docs/quick_start.md +0 -30
- data/docs/webpacker.md +0 -25
- data/docs/yard_customizations.rb +0 -43
- data/lib/super/controls/required.rb +0 -15
data/lib/super.rb
CHANGED
data/lib/super/configuration.rb
CHANGED
@@ -21,36 +21,27 @@ module Super
|
|
21
21
|
# end
|
22
22
|
# ```
|
23
23
|
class Configuration
|
24
|
-
|
25
|
-
self.title = "Super Admin"
|
26
|
-
self.index_records_per_page = 20
|
27
|
-
self.controller_namespace = "admin"
|
28
|
-
self.route_namespace = :admin
|
29
|
-
|
30
|
-
controller_plugins.use(prepend: Super::Pagination::ControllerMethods)
|
24
|
+
include ActiveSupport::Configurable
|
31
25
|
|
32
|
-
|
33
|
-
|
26
|
+
config_accessor(:title) { "Super Admin" }
|
27
|
+
config_accessor(:index_records_per_page) { 100 }
|
28
|
+
config_accessor(:javascripts) do
|
29
|
+
[Super::Assets.auto("super/application")]
|
34
30
|
end
|
35
|
-
|
36
|
-
|
37
|
-
attr_accessor :index_records_per_page
|
38
|
-
attr_accessor :controller_namespace
|
39
|
-
attr_writer :route_namespace
|
40
|
-
def route_namespace
|
41
|
-
[@route_namespace].flatten
|
31
|
+
config_accessor(:stylesheets) do
|
32
|
+
[Super::Assets.auto("super/application")]
|
42
33
|
end
|
43
34
|
|
44
|
-
|
45
|
-
|
35
|
+
config_accessor(:path) { "/admin" }
|
36
|
+
config_accessor(:generator_module) { "admin" }
|
37
|
+
config_accessor(:generator_as) { "admin" }
|
46
38
|
|
47
|
-
def
|
48
|
-
|
39
|
+
def initialize
|
40
|
+
controller_plugins.use(prepend: Super::Pagination::ControllerMethods)
|
49
41
|
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
route_namespace + parts
|
43
|
+
def controller_plugins
|
44
|
+
Plugin::Registry.controller
|
54
45
|
end
|
55
46
|
end
|
56
47
|
end
|
data/lib/super/controls.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "super/controls/optional"
|
4
|
-
require "super/controls/required"
|
5
4
|
require "super/controls/steps"
|
6
5
|
require "super/controls/view"
|
7
6
|
|
@@ -9,9 +8,15 @@ module Super
|
|
9
8
|
# The base Controls class. Most parts of Super can be configured by
|
10
9
|
# customizing its methods.
|
11
10
|
class Controls
|
12
|
-
include Required
|
13
11
|
include Optional
|
14
12
|
include Steps
|
15
13
|
include View
|
14
|
+
|
15
|
+
# Specifies the model. This is a required method
|
16
|
+
#
|
17
|
+
# @return [ActiveRecord::Base]
|
18
|
+
def model
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/super/display.rb
CHANGED
@@ -45,25 +45,33 @@ module Super
|
|
45
45
|
raise Super::Error::Initalization,
|
46
46
|
"You must call the `#apply` method after instantiating Super::Display"
|
47
47
|
elsif @action_inquirer.index?
|
48
|
-
"
|
48
|
+
"display_index"
|
49
49
|
elsif @action_inquirer.show?
|
50
|
-
"
|
50
|
+
"display_show"
|
51
51
|
else
|
52
|
-
"
|
52
|
+
"display_#{@action_inquirer.action}"
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
# @private
|
57
|
-
def
|
57
|
+
def render_attribute(template:, record:, column:)
|
58
58
|
formatter = @fields[column]
|
59
|
+
formatter = formatter.build if formatter.respond_to?(:build)
|
59
60
|
|
60
61
|
formatted =
|
61
|
-
|
62
|
+
SchemaTypes::TYPES
|
63
|
+
.case(formatter.type)
|
64
|
+
.when(:record) do
|
65
|
+
formatter.present(column, record)
|
66
|
+
end
|
67
|
+
.when(:column) do
|
62
68
|
value = record.public_send(column)
|
63
|
-
formatter.present(value)
|
64
|
-
|
65
|
-
|
69
|
+
formatter.present(column, value)
|
70
|
+
end
|
71
|
+
.when(:none) do
|
72
|
+
formatter.present(column)
|
66
73
|
end
|
74
|
+
.result
|
67
75
|
|
68
76
|
if formatted.respond_to?(:to_partial_path)
|
69
77
|
if formatted.respond_to?(:locals)
|
@@ -3,35 +3,61 @@
|
|
3
3
|
module Super
|
4
4
|
class Display
|
5
5
|
class SchemaTypes
|
6
|
-
|
7
|
-
def initialize(ignore_nil: true, &transform_block)
|
8
|
-
@transform_block = transform_block
|
9
|
-
@ignore_nil = ignore_nil
|
10
|
-
end
|
6
|
+
TYPES = Useful::Enum.new(:column, :record, :none)
|
11
7
|
|
12
|
-
|
13
|
-
|
8
|
+
class Builder
|
9
|
+
extend Useful::Builder
|
14
10
|
|
15
|
-
|
11
|
+
builder_with_block def transform(&block)
|
12
|
+
@transform_block = block
|
16
13
|
end
|
17
14
|
|
18
|
-
def real
|
19
|
-
|
15
|
+
builder def real; @real = true; end
|
16
|
+
builder def computed; @real = false; end
|
17
|
+
|
18
|
+
builder def column; @type = :column; end
|
19
|
+
builder def record; @type = :record; end
|
20
|
+
builder def none; @type = :none; end
|
21
|
+
|
22
|
+
builder def ignore_nil; @ignore_nil = true; end
|
23
|
+
|
24
|
+
def build
|
25
|
+
Built.new(
|
26
|
+
real: @real,
|
27
|
+
type: @type,
|
28
|
+
ignore_nil: !!@ignore_nil,
|
29
|
+
&@transform_block
|
30
|
+
)
|
20
31
|
end
|
21
32
|
end
|
22
33
|
|
23
|
-
class
|
24
|
-
def initialize(
|
25
|
-
@partial = partial
|
34
|
+
class Built
|
35
|
+
def initialize(real:, type:, ignore_nil:, &transform_block)
|
26
36
|
@real = real
|
37
|
+
@type = type
|
38
|
+
@ignore_nil = ignore_nil
|
39
|
+
@transform_block = transform_block
|
27
40
|
end
|
28
41
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
42
|
+
def real?; @real; end
|
43
|
+
attr_reader :type
|
44
|
+
|
45
|
+
def present(attribute_name, value = nil)
|
46
|
+
if @transform_block.nil?
|
47
|
+
if attribute_name
|
48
|
+
raise Error::ArgumentError, "Transformation block is not set for column: #{attribute_name}"
|
49
|
+
else
|
50
|
+
raise Error::ArgumentError, "Transformation block is not set!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
return nil if value.nil? && @ignore_nil
|
32
55
|
|
33
|
-
|
34
|
-
|
56
|
+
if @type == :none
|
57
|
+
@transform_block.call
|
58
|
+
else
|
59
|
+
@transform_block.call(value)
|
60
|
+
end
|
35
61
|
end
|
36
62
|
end
|
37
63
|
|
@@ -40,33 +66,44 @@ module Super
|
|
40
66
|
@fields = fields
|
41
67
|
end
|
42
68
|
|
43
|
-
def
|
44
|
-
|
69
|
+
def real(type = :column, &transform_block)
|
70
|
+
TYPES
|
71
|
+
.case(type)
|
72
|
+
.when(:column) { Builder.new.real.ignore_nil.column.transform(&transform_block) }
|
73
|
+
.when(:record) { Builder.new.real.ignore_nil.record.transform(&transform_block) }
|
74
|
+
.when(:none) { Builder.new.real.ignore_nil.none.transform(&transform_block) }
|
75
|
+
.result
|
45
76
|
end
|
46
77
|
|
47
|
-
|
78
|
+
def computed(type = :column, &transform_block)
|
79
|
+
TYPES
|
80
|
+
.case(type)
|
81
|
+
.when(:column) { Builder.new.computed.ignore_nil.column.transform(&transform_block) }
|
82
|
+
.when(:record) { Builder.new.computed.ignore_nil.record.transform(&transform_block) }
|
83
|
+
.when(:none) { Builder.new.computed.ignore_nil.none.transform(&transform_block) }
|
84
|
+
.result
|
85
|
+
end
|
48
86
|
|
49
|
-
def
|
50
|
-
|
87
|
+
def manual(&transform_block)
|
88
|
+
real(:column, &transform_block)
|
51
89
|
end
|
52
90
|
|
91
|
+
def string; real(&:to_s); end
|
92
|
+
alias text string
|
93
|
+
|
94
|
+
def timestamp; real(&:to_s); end
|
95
|
+
|
53
96
|
def rich_text
|
54
|
-
|
97
|
+
real do |value|
|
55
98
|
Partial.new("display_rich_text", locals: { rich_text: value })
|
56
99
|
end
|
57
100
|
end
|
58
101
|
|
59
|
-
def manual(&transform_block)
|
60
|
-
Dynamic.new(&transform_block)
|
61
|
-
end
|
62
|
-
|
63
|
-
def dynamic(&transform_block)
|
64
|
-
Dynamic.new(&transform_block)
|
65
|
-
end
|
66
|
-
|
67
102
|
def actions
|
68
103
|
@actions_called = true
|
69
|
-
|
104
|
+
Builder.new.computed.none.transform do
|
105
|
+
Partial.new("display_actions")
|
106
|
+
end
|
70
107
|
end
|
71
108
|
|
72
109
|
# @private
|
data/lib/super/error.rb
CHANGED
@@ -27,5 +27,12 @@ module Super
|
|
27
27
|
# Error raised when something wasn't initalized correctly, and if there isn't
|
28
28
|
# a more specific error
|
29
29
|
class Initalization < Error; end
|
30
|
+
class ArgumentError < Error; end
|
31
|
+
|
32
|
+
class Enum < Error
|
33
|
+
class ImpossibleValue < Enum; end
|
34
|
+
class ArgumentError < Enum; end
|
35
|
+
class UndefinedCase < Enum; end
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
data/lib/super/form.rb
CHANGED
data/lib/super/layout.rb
CHANGED
data/lib/super/link.rb
CHANGED
@@ -80,6 +80,11 @@ module Super
|
|
80
80
|
}
|
81
81
|
end
|
82
82
|
|
83
|
+
def self.polymorphic_parts(*parts_tail)
|
84
|
+
parts_head = Super.configuration.path.strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip.split("/")
|
85
|
+
parts_head + parts_tail
|
86
|
+
end
|
87
|
+
|
83
88
|
def initialize(text, href, **options)
|
84
89
|
@text = text
|
85
90
|
@href = href
|
@@ -5,8 +5,8 @@ module Super
|
|
5
5
|
# Traverses the defined Rails Routes and attempts to build a list of links.
|
6
6
|
# This is used for building the nav bar on each admin page.
|
7
7
|
class Automatic
|
8
|
-
def initialize(route_namespace:)
|
9
|
-
route_namespace = route_namespace.
|
8
|
+
def initialize(route_namespace: Super.configuration.path)
|
9
|
+
route_namespace = route_namespace.strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip
|
10
10
|
|
11
11
|
if route_namespace.include?("/")
|
12
12
|
raise "Can't be nested namespace"
|
data/lib/super/pagination.rb
CHANGED
data/lib/super/panel.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
module Useful
|
5
|
+
module Builder
|
6
|
+
def builder(method_name)
|
7
|
+
alias_method("original_#{method_name}", method_name)
|
8
|
+
|
9
|
+
define_method(method_name) do
|
10
|
+
send("original_#{method_name}")
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def builder_with_block(method_name)
|
16
|
+
alias_method("original_#{method_name}", method_name)
|
17
|
+
|
18
|
+
define_method(method_name) do |&block|
|
19
|
+
send("original_#{method_name}", &block)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
module Useful
|
5
|
+
class Enum
|
6
|
+
def initialize(*choices)
|
7
|
+
@choices = choices.flatten.map { |choice| [choice, nil] }.to_h
|
8
|
+
end
|
9
|
+
|
10
|
+
def case(chosen)
|
11
|
+
Case.new(@choices, chosen)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Case
|
15
|
+
def initialize(choices, chosen)
|
16
|
+
if !choices.key?(chosen)
|
17
|
+
raise Error::Enum::ImpossibleValue,
|
18
|
+
"`#{chosen}` isn't in: #{choices.keys.map(&:inspect).join(", ")}"
|
19
|
+
end
|
20
|
+
|
21
|
+
@choices = choices
|
22
|
+
@chosen = chosen
|
23
|
+
@whens = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def when(*keys, &block)
|
27
|
+
if !block_given?
|
28
|
+
raise Error::ArgumentError, "must receive block"
|
29
|
+
end
|
30
|
+
|
31
|
+
keys.each do |key|
|
32
|
+
if !@choices.key?(key)
|
33
|
+
raise Error::Enum::ImpossibleValue, "`#{key.inspect}` is not a possibility"
|
34
|
+
end
|
35
|
+
|
36
|
+
@whens[key] = block
|
37
|
+
end
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def result
|
43
|
+
if @choices.size != @whens.size
|
44
|
+
missing_keys = @choices.keys - @whens.keys
|
45
|
+
raise Error::Enum::UndefinedCase, "Unset cases: #{missing_keys.join(", ")}"
|
46
|
+
end
|
47
|
+
|
48
|
+
@whens[@chosen].call(@value)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def matching_possibilities_and_checks?
|
54
|
+
if @whens.size == @choices.size
|
55
|
+
return true
|
56
|
+
end
|
57
|
+
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|