super 0.0.3 → 0.0.4
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/app/assets/javascripts/super/application.js +60 -10831
- data/app/assets/stylesheets/super/application.css +38267 -22475
- data/app/controllers/super/application_controller.rb +34 -30
- data/app/helpers/super/application_helper.rb +32 -0
- data/app/views/layouts/super/application.html.erb +6 -8
- data/app/views/super/application/_form.html.erb +13 -10
- data/app/views/super/application/_form_field__destroy.html.erb +2 -2
- data/app/views/super/application/_form_field_select.html.erb +6 -6
- data/app/views/super/application/_form_field_text.html.erb +3 -3
- data/app/views/super/application/_form_fieldset.html.erb +1 -1
- data/app/views/super/application/_form_has_many.html.erb +4 -4
- data/app/views/super/application/_index.html.erb +38 -53
- data/app/views/super/application/_resource_header.html.erb +16 -0
- data/app/views/super/application/_resources_header.html.erb +16 -0
- data/app/views/super/application/_show.html.erb +0 -2
- data/app/views/super/application/_super_layout.html.erb +34 -0
- data/app/views/super/application/_super_panel.html.erb +11 -0
- data/app/views/super/application/edit.html.erb +1 -6
- data/app/views/super/application/index.html.erb +1 -1
- data/app/views/super/application/new.html.erb +1 -6
- data/app/views/super/application/show.html.erb +1 -1
- data/frontend/super-frontend/build.js +12 -12
- data/frontend/super-frontend/dist/application.css +38267 -22475
- data/frontend/super-frontend/dist/application.js +60 -10831
- data/frontend/super-frontend/package.json +7 -3
- data/frontend/super-frontend/postcss.config.js +4 -4
- data/frontend/super-frontend/src/javascripts/super/application.ts +10 -5
- data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +21 -0
- data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +1 -1
- data/frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts +15 -0
- data/frontend/super-frontend/src/stylesheets/super/application.css +63 -0
- data/frontend/super-frontend/tailwind.config.js +6 -4
- data/frontend/super-frontend/yarn.lock +115 -40
- data/lib/super.rb +6 -2
- data/lib/super/action.rb +22 -0
- data/lib/super/action/step.rb +36 -0
- data/lib/super/controls.rb +222 -2
- data/lib/super/error.rb +1 -0
- data/lib/super/form/schema_types.rb +1 -1
- data/lib/super/layout.rb +19 -0
- data/lib/super/link.rb +87 -0
- data/lib/super/pagination.rb +19 -8
- data/lib/super/panel.rb +17 -0
- data/lib/super/partial.rb +11 -0
- data/lib/super/test_support/copy_app_templates/controllers/members_controller.rb +17 -0
- data/lib/super/test_support/copy_app_templates/views/members/_favorite_things.html.erb +11 -0
- data/lib/super/test_support/generate_copy_app.rb +1 -0
- data/lib/super/version.rb +1 -1
- metadata +16 -5
- data/frontend/super-frontend/src/javascripts/super/nested_attributes_controller.ts +0 -33
- data/lib/super/inline_callback.rb +0 -82
- data/lib/super/view.rb +0 -25
data/lib/super.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "tsort"
|
2
2
|
require "active_support/concern"
|
3
3
|
|
4
|
+
require "super/action"
|
5
|
+
require "super/action/step"
|
4
6
|
require "super/action_inquirer"
|
5
7
|
require "super/assets"
|
6
8
|
require "super/configuration"
|
@@ -10,10 +12,12 @@ require "super/error"
|
|
10
12
|
require "super/display"
|
11
13
|
require "super/display/schema_types"
|
12
14
|
require "super/form/schema_types"
|
13
|
-
require "super/
|
15
|
+
require "super/layout"
|
16
|
+
require "super/link"
|
14
17
|
require "super/navigation/automatic"
|
15
18
|
require "super/pagination"
|
19
|
+
require "super/panel"
|
20
|
+
require "super/partial"
|
16
21
|
require "super/plugin"
|
17
22
|
require "super/schema"
|
18
23
|
require "super/version"
|
19
|
-
require "super/view"
|
data/lib/super/action.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Super
|
2
|
+
class Action
|
3
|
+
def initialize(steps:, page:)
|
4
|
+
@steps = steps
|
5
|
+
@page = page
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :page
|
9
|
+
|
10
|
+
def steps
|
11
|
+
resolved_steps = @steps.map do |step|
|
12
|
+
if step.respond_to?(:call)
|
13
|
+
step
|
14
|
+
elsif self.class.steps.key?(step)
|
15
|
+
self.class.steps[step]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
resolved_steps.compact
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Super
|
2
|
+
class Action
|
3
|
+
def self.steps
|
4
|
+
@steps ||= {}
|
5
|
+
end
|
6
|
+
|
7
|
+
steps[:new_resource] = proc do
|
8
|
+
@resource = controls.scope(action: action_inquirer).build
|
9
|
+
end
|
10
|
+
|
11
|
+
steps[:create_resource] = proc do
|
12
|
+
@resource = controls.scope(action: action_inquirer).build(create_permitted_params)
|
13
|
+
end
|
14
|
+
|
15
|
+
steps[:load_resource] = proc do
|
16
|
+
@resource = controls.scope(action: action_inquirer).find(params[:id])
|
17
|
+
end
|
18
|
+
|
19
|
+
steps[:load_resources] = proc do
|
20
|
+
@resources = controls.scope(action: action_inquirer)
|
21
|
+
end
|
22
|
+
|
23
|
+
steps[:paginate] = proc do
|
24
|
+
@pagination = Pagination.new(
|
25
|
+
total_count: @resources.size,
|
26
|
+
limit: Super.configuration.index_resources_per_page,
|
27
|
+
query_params: request.GET,
|
28
|
+
page_query_param: :page
|
29
|
+
)
|
30
|
+
|
31
|
+
@resources = @resources
|
32
|
+
.limit(@pagination.limit)
|
33
|
+
.offset(@pagination.offset)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/super/controls.rb
CHANGED
@@ -9,33 +9,253 @@ module Super
|
|
9
9
|
|
10
10
|
attr_reader :actual
|
11
11
|
|
12
|
+
# This is an optional method
|
13
|
+
#
|
14
|
+
# @return [String]
|
12
15
|
def title
|
13
|
-
@actual.title
|
16
|
+
if @actual.respond_to?(:title)
|
17
|
+
return @actual.title
|
18
|
+
end
|
19
|
+
|
20
|
+
model.name.pluralize
|
14
21
|
end
|
15
22
|
|
23
|
+
# Specifies the model. This is a required method
|
24
|
+
#
|
25
|
+
# @return [ActiveRecord::Base]
|
16
26
|
def model
|
17
27
|
@actual.model
|
18
28
|
end
|
19
29
|
|
30
|
+
# Configures the actions linked to on the index page. This is an optional
|
31
|
+
# method
|
32
|
+
#
|
33
|
+
# @param params [ActionController::Parameters]
|
34
|
+
# @param action [ActionInquirer]
|
35
|
+
# @return [Array<Link>]
|
36
|
+
def resources_actions(params:, action:)
|
37
|
+
actions =
|
38
|
+
if @actual.respond_to?(:resources_actions)
|
39
|
+
@actual.resources_actions(params: params, action: action)
|
40
|
+
else
|
41
|
+
[:new]
|
42
|
+
end
|
43
|
+
|
44
|
+
actions.map do |link|
|
45
|
+
link = Link.resolve(link)
|
46
|
+
|
47
|
+
link.call(params: params)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Configures the actions linked to on the show page as well as each row of
|
52
|
+
# the table on the index page. This is an optional method
|
53
|
+
#
|
54
|
+
# @param resource [ActiveRecord::Base]
|
55
|
+
# @param params [ActionController::Parameters]
|
56
|
+
# @param action [ActionInquirer]
|
57
|
+
# @return [Array<Link>]
|
58
|
+
def resource_actions(resource, params:, action:)
|
59
|
+
actions =
|
60
|
+
if @actual.respond_to?(:resource_actions)
|
61
|
+
@actual.resource_actions(resource, params: params, action: action)
|
62
|
+
else
|
63
|
+
if action.show?
|
64
|
+
[:edit, :destroy]
|
65
|
+
elsif action.edit?
|
66
|
+
[:show, :destroy]
|
67
|
+
else
|
68
|
+
[:show, :edit, :destroy]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
actions.map do |link|
|
73
|
+
link = Link.resolve(link)
|
74
|
+
|
75
|
+
link.call(resource, params: params)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Configures what database records are visible on load. This is an optional
|
80
|
+
# method, it defaults to "`all`" methods
|
81
|
+
#
|
20
82
|
# @param action [ActionInquirer]
|
83
|
+
# @return [ActiveRecord::Relation]
|
21
84
|
def scope(action:)
|
22
|
-
@actual.
|
85
|
+
if @actual.respond_to?(:scope)
|
86
|
+
return @actual.scope(action: action)
|
87
|
+
end
|
88
|
+
|
89
|
+
model.all
|
23
90
|
end
|
24
91
|
|
92
|
+
# Configures which parameters could be written to the database. This is a
|
93
|
+
# required method
|
94
|
+
#
|
25
95
|
# @param params [ActionController::Parameters]
|
26
96
|
# @param action [ActionInquirer]
|
97
|
+
# @return [ActionController::Parameters]
|
27
98
|
def permitted_params(params, action:)
|
28
99
|
@actual.permitted_params(params, action: action)
|
29
100
|
end
|
30
101
|
|
102
|
+
# Configures the fields that are displayed on the index and show actions.
|
103
|
+
# This is a required method
|
104
|
+
#
|
31
105
|
# @param action [ActionInquirer]
|
106
|
+
# @return [Schema]
|
32
107
|
def display_schema(action:)
|
33
108
|
@actual.display_schema(action: action)
|
34
109
|
end
|
35
110
|
|
111
|
+
# Configures the editable fields on the new and edit actions. This is a
|
112
|
+
# required method
|
113
|
+
#
|
36
114
|
# @param action [ActionInquirer]
|
115
|
+
# @return [Schema]
|
37
116
|
def form_schema(action:)
|
38
117
|
@actual.form_schema(action: action)
|
39
118
|
end
|
119
|
+
|
120
|
+
# @return [Action]
|
121
|
+
def index
|
122
|
+
if @actual.respond_to?(:index)
|
123
|
+
return @actual.index
|
124
|
+
end
|
125
|
+
|
126
|
+
Super::Action.new(
|
127
|
+
steps: [
|
128
|
+
:load_resources,
|
129
|
+
:paginate,
|
130
|
+
],
|
131
|
+
page: Super::Layout.new(
|
132
|
+
mains: [
|
133
|
+
Super::Panel.new(
|
134
|
+
Super::Partial.new("resources_header"),
|
135
|
+
Super::Partial.new("index")
|
136
|
+
)
|
137
|
+
]
|
138
|
+
)
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
# @return [Action]
|
143
|
+
def show
|
144
|
+
if @actual.respond_to?(:show)
|
145
|
+
return @actual.show
|
146
|
+
end
|
147
|
+
|
148
|
+
Super::Action.new(
|
149
|
+
steps: [
|
150
|
+
:load_resource,
|
151
|
+
],
|
152
|
+
page: Super::Layout.new(
|
153
|
+
mains: [
|
154
|
+
Super::Panel.new(
|
155
|
+
Super::Partial.new("resource_header"),
|
156
|
+
Super::Partial.new("show")
|
157
|
+
)
|
158
|
+
]
|
159
|
+
)
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
# @return [Action]
|
164
|
+
def new
|
165
|
+
if @actual.respond_to?(:new)
|
166
|
+
return @actual.new
|
167
|
+
end
|
168
|
+
|
169
|
+
Super::Action.new(
|
170
|
+
steps: [
|
171
|
+
:new_resource,
|
172
|
+
],
|
173
|
+
page: Super::Layout.new(
|
174
|
+
mains: [
|
175
|
+
Super::Panel.new(
|
176
|
+
Super::Partial.new("resources_header"),
|
177
|
+
Super::Partial.new("form")
|
178
|
+
)
|
179
|
+
]
|
180
|
+
)
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
# @return [Action]
|
185
|
+
def create
|
186
|
+
if @actual.respond_to?(:create)
|
187
|
+
return @actual.create
|
188
|
+
end
|
189
|
+
|
190
|
+
Super::Action.new(
|
191
|
+
steps: [
|
192
|
+
:create_resource,
|
193
|
+
],
|
194
|
+
page: Super::Layout.new(
|
195
|
+
mains: [
|
196
|
+
Super::Panel.new(
|
197
|
+
Super::Partial.new("resources_header"),
|
198
|
+
Super::Partial.new("form")
|
199
|
+
)
|
200
|
+
]
|
201
|
+
)
|
202
|
+
)
|
203
|
+
end
|
204
|
+
|
205
|
+
# @return [Action]
|
206
|
+
def edit
|
207
|
+
if @actual.respond_to?(:edit)
|
208
|
+
return @actual.edit
|
209
|
+
end
|
210
|
+
|
211
|
+
Super::Action.new(
|
212
|
+
steps: [
|
213
|
+
:load_resource,
|
214
|
+
],
|
215
|
+
page: Super::Layout.new(
|
216
|
+
mains: [
|
217
|
+
Super::Panel.new(
|
218
|
+
Super::Partial.new("resource_header"),
|
219
|
+
Super::Partial.new("form")
|
220
|
+
)
|
221
|
+
]
|
222
|
+
)
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
# @return [Action]
|
227
|
+
def update
|
228
|
+
if @actual.respond_to?(:update)
|
229
|
+
return @actual.update
|
230
|
+
end
|
231
|
+
|
232
|
+
Super::Action.new(
|
233
|
+
steps: [
|
234
|
+
:load_resource,
|
235
|
+
],
|
236
|
+
page: Super::Layout.new(
|
237
|
+
mains: [
|
238
|
+
Super::Panel.new(
|
239
|
+
Super::Partial.new("resource_header"),
|
240
|
+
Super::Partial.new("form")
|
241
|
+
)
|
242
|
+
]
|
243
|
+
)
|
244
|
+
)
|
245
|
+
end
|
246
|
+
|
247
|
+
# @return [Action]
|
248
|
+
def destroy
|
249
|
+
if @actual.respond_to?(:destroy)
|
250
|
+
return @actual.destroy
|
251
|
+
end
|
252
|
+
|
253
|
+
Super::Action.new(
|
254
|
+
steps: [
|
255
|
+
:load_resource,
|
256
|
+
],
|
257
|
+
page: Super::Layout.new
|
258
|
+
)
|
259
|
+
end
|
40
260
|
end
|
41
261
|
end
|
data/lib/super/error.rb
CHANGED
@@ -63,7 +63,7 @@ module Super
|
|
63
63
|
return false if other.class != self.class
|
64
64
|
return false if other.instance_variable_get(:@partial_path) != @partial_path
|
65
65
|
return false if other.instance_variable_get(:@extras) != @extras
|
66
|
-
return false if other.instance_variable_get(:@
|
66
|
+
return false if other.instance_variable_get(:@nested_fields) != @nested_fields
|
67
67
|
|
68
68
|
true
|
69
69
|
end
|
data/lib/super/layout.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Super
|
2
|
+
class Layout
|
3
|
+
def initialize(headers: nil, asides: nil, mains: nil, footers: nil)
|
4
|
+
@headers = Array(headers).compact
|
5
|
+
@asides = Array(asides).compact
|
6
|
+
@mains = Array(mains).compact
|
7
|
+
@footers = Array(footers).compact
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :headers
|
11
|
+
attr_reader :asides
|
12
|
+
attr_reader :mains
|
13
|
+
attr_reader :footers
|
14
|
+
|
15
|
+
def to_partial_path
|
16
|
+
"super_layout"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/super/link.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
module Super
|
2
|
+
# Links have three required attributes that are passed directly into Rails'
|
3
|
+
# `link_to` helper
|
4
|
+
class Link
|
5
|
+
def self.resolve(link)
|
6
|
+
if link.kind_of?(self)
|
7
|
+
return link
|
8
|
+
end
|
9
|
+
|
10
|
+
if registry.key?(link)
|
11
|
+
return registry[link]
|
12
|
+
end
|
13
|
+
|
14
|
+
raise Error::LinkNotRegistered, "Unknown link `#{link}`"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.registry
|
18
|
+
@registry ||= {
|
19
|
+
new: -> (params:) {
|
20
|
+
new(
|
21
|
+
"New",
|
22
|
+
Rails.application.routes.url_for(
|
23
|
+
controller: params[:controller],
|
24
|
+
action: :new,
|
25
|
+
only_path: true
|
26
|
+
)
|
27
|
+
)
|
28
|
+
},
|
29
|
+
index: -> (params:) {
|
30
|
+
new(
|
31
|
+
"Index",
|
32
|
+
Rails.application.routes.url_for(
|
33
|
+
controller: params[:controller],
|
34
|
+
action: :index,
|
35
|
+
only_path: true
|
36
|
+
)
|
37
|
+
)
|
38
|
+
},
|
39
|
+
show: -> (resource, params:) {
|
40
|
+
new(
|
41
|
+
"View",
|
42
|
+
Rails.application.routes.url_for(
|
43
|
+
controller: params[:controller],
|
44
|
+
action: :show,
|
45
|
+
id: resource,
|
46
|
+
only_path: true
|
47
|
+
)
|
48
|
+
)
|
49
|
+
},
|
50
|
+
edit: -> (resource, params:) {
|
51
|
+
new(
|
52
|
+
"Edit",
|
53
|
+
Rails.application.routes.url_for(
|
54
|
+
controller: params[:controller],
|
55
|
+
action: :edit,
|
56
|
+
id: resource,
|
57
|
+
only_path: true
|
58
|
+
)
|
59
|
+
)
|
60
|
+
},
|
61
|
+
destroy: -> (resource, params:) {
|
62
|
+
new(
|
63
|
+
"Delete",
|
64
|
+
Rails.application.routes.url_for(
|
65
|
+
controller: params[:controller],
|
66
|
+
action: :destroy,
|
67
|
+
id: resource,
|
68
|
+
only_path: true
|
69
|
+
),
|
70
|
+
method: :delete,
|
71
|
+
data: { confirm: "Really delete?" }
|
72
|
+
)
|
73
|
+
},
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def initialize(text, href, **options)
|
78
|
+
@text = text
|
79
|
+
@href = href
|
80
|
+
@options = options
|
81
|
+
end
|
82
|
+
|
83
|
+
attr_reader :text
|
84
|
+
attr_reader :href
|
85
|
+
attr_reader :options
|
86
|
+
end
|
87
|
+
end
|