super 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +10 -0
  3. data/README.md +9 -64
  4. data/app/assets/stylesheets/super/application.css +53890 -25613
  5. data/app/controllers/super/application_controller.rb +9 -28
  6. data/app/views/super/application/_form_field__destroy.html.erb +6 -2
  7. data/app/views/super/application/_form_field_select.html.erb +10 -4
  8. data/app/views/super/application/_form_field_text.html.erb +13 -5
  9. data/app/views/super/application/_form_has_many.html.erb +2 -2
  10. data/app/views/super/application/_form_inline_errors.html.erb +1 -1
  11. data/app/views/super/application/_index.html.erb +2 -2
  12. data/app/views/super/application/edit.html.erb +6 -1
  13. data/app/views/super/application/index.html.erb +6 -1
  14. data/app/views/super/application/new.html.erb +6 -1
  15. data/app/views/super/application/show.html.erb +6 -1
  16. data/docs/README.md +6 -0
  17. data/docs/controls.md +39 -0
  18. data/docs/faq.md +44 -0
  19. data/docs/quick_start.md +45 -0
  20. data/docs/webpacker.md +17 -0
  21. data/docs/yard_customizations.rb +41 -0
  22. data/frontend/super-frontend/dist/application.css +53890 -25613
  23. data/frontend/super-frontend/tailwind.config.js +1 -1
  24. data/frontend/super-frontend/yarn.lock +1048 -974
  25. data/lib/generators/super/webpacker/webpacker_generator.rb +8 -0
  26. data/lib/super.rb +5 -5
  27. data/lib/super/compatibility.rb +13 -0
  28. data/lib/super/controls.rb +0 -141
  29. data/lib/super/step.rb +36 -0
  30. data/lib/super/version.rb +1 -1
  31. data/lib/super/view_helper.rb +43 -0
  32. metadata +56 -25
  33. data/lib/super/action.rb +0 -22
  34. data/lib/super/action/step.rb +0 -36
  35. data/lib/super/test_support/copy_app_templates/controllers/favorite_things_controller.rb +0 -50
  36. data/lib/super/test_support/copy_app_templates/controllers/members_controller.rb +0 -74
  37. data/lib/super/test_support/copy_app_templates/controllers/ships_controller.rb +0 -47
  38. data/lib/super/test_support/copy_app_templates/migrations/20190216224956_create_members.rb +0 -11
  39. data/lib/super/test_support/copy_app_templates/migrations/20190803143320_create_ships.rb +0 -11
  40. data/lib/super/test_support/copy_app_templates/migrations/20190806014121_add_ship_to_members.rb +0 -5
  41. data/lib/super/test_support/copy_app_templates/migrations/20191126050453_create_favorite_things.rb +0 -10
  42. data/lib/super/test_support/copy_app_templates/models/favorite_thing.rb +0 -7
  43. data/lib/super/test_support/copy_app_templates/models/member.rb +0 -23
  44. data/lib/super/test_support/copy_app_templates/models/ship.rb +0 -3
  45. data/lib/super/test_support/copy_app_templates/routes.rb +0 -11
  46. data/lib/super/test_support/copy_app_templates/seeds.rb +0 -2
  47. data/lib/super/test_support/copy_app_templates/views/members/_favorite_things.html.erb +0 -11
  48. data/lib/super/test_support/fixtures/favorite_things.yml +0 -9
  49. data/lib/super/test_support/fixtures/members.yml +0 -336
  50. data/lib/super/test_support/fixtures/ships.yml +0 -10
  51. data/lib/super/test_support/generate_copy_app.rb +0 -42
  52. data/lib/super/test_support/generate_dummy.rb +0 -93
  53. data/lib/super/test_support/starfleet_seeder.rb +0 -50
@@ -9,6 +9,14 @@ module Super
9
9
  )
10
10
  end
11
11
 
12
+ def set_asset_handler_to_webpacker
13
+ insert_into_file(
14
+ "config/initializers/super.rb",
15
+ " c.asset_handler = Super::Assets.webpacker\n",
16
+ before: /\bend\b/
17
+ )
18
+ end
19
+
12
20
  def remind_about_erb
13
21
  say "Make sure ERB is set up for Webpacker!", :bold
14
22
  say "Run if needed: rails webpacker:install:erb", :bold
@@ -1,16 +1,14 @@
1
- require "tsort"
2
1
  require "active_support/concern"
3
2
 
4
- require "super/action"
5
- require "super/action/step"
6
3
  require "super/action_inquirer"
7
4
  require "super/assets"
5
+ require "super/compatibility"
8
6
  require "super/configuration"
9
7
  require "super/controls"
10
- require "super/engine"
11
- require "super/error"
12
8
  require "super/display"
13
9
  require "super/display/schema_types"
10
+ require "super/engine"
11
+ require "super/error"
14
12
  require "super/form/schema_types"
15
13
  require "super/layout"
16
14
  require "super/link"
@@ -20,4 +18,6 @@ require "super/panel"
20
18
  require "super/partial"
21
19
  require "super/plugin"
22
20
  require "super/schema"
21
+ require "super/step"
23
22
  require "super/version"
23
+ require "super/view_helper"
@@ -0,0 +1,13 @@
1
+ module Super
2
+ module Compatability
3
+ module_function
4
+
5
+ def rails_50_errable_fields(field)
6
+ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 0
7
+ [field.to_s, field.to_sym]
8
+ else
9
+ field
10
+ end
11
+ end
12
+ end
13
+ end
@@ -116,146 +116,5 @@ module Super
116
116
  def form_schema(action:)
117
117
  @actual.form_schema(action: action)
118
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
260
119
  end
261
120
  end
@@ -0,0 +1,36 @@
1
+ module Super
2
+ module Step
3
+ module_function
4
+
5
+ def load_resources(controls, _params, action_inquirer)
6
+ controls.scope(action: action_inquirer)
7
+ end
8
+
9
+ def initialize_pagination(resources, query_params, limit: Super.configuration.index_resources_per_page)
10
+ Pagination.new(
11
+ total_count: resources.size,
12
+ limit: limit,
13
+ query_params: query_params,
14
+ page_query_param: :page
15
+ )
16
+ end
17
+
18
+ def paginate_resources(resources, pagination)
19
+ resources
20
+ .limit(pagination.limit)
21
+ .offset(pagination.offset)
22
+ end
23
+
24
+ def load_resource(controls, params, action_inquirer)
25
+ controls.scope(action: action_inquirer).find(params[:id])
26
+ end
27
+
28
+ def build_resource(controls, action_inquirer)
29
+ controls.scope(action: action_inquirer).build
30
+ end
31
+
32
+ def build_resource_with_params(controls, action_inquirer, create_permitted_params)
33
+ controls.scope(action: action_inquirer).build(create_permitted_params)
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Super
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,43 @@
1
+ module Super
2
+ module ViewHelper
3
+ module_function
4
+
5
+ # For example, calling `classes("always", ["sometimes", condition])` would
6
+ # return the string "always sometimes" or "always"
7
+ def classes(*list)
8
+ result = list.map do |c|
9
+ case c
10
+ when String
11
+ c
12
+ when Array
13
+ if c.size != 2
14
+ raise %(Expected exactly two elements (["class", some_condition]), got: #{c.inspect})
15
+ end
16
+
17
+ c if c.last
18
+ end
19
+ end
20
+
21
+ result.compact.join(" ")
22
+ end
23
+
24
+ def errors_accounting_for_reflections(model_instance, column_or_association)
25
+ errable_fields(model_instance, column_or_association)
26
+ .flat_map { |field| Compatability.rails_50_errable_fields(field) }
27
+ .flat_map { |field| model_instance.errors.full_messages_for(field) }
28
+ .uniq
29
+ end
30
+
31
+ def errable_fields(model_instance, column_or_association)
32
+ column_or_association = column_or_association.to_s
33
+ reflection = model_instance.class.reflect_on_association(column_or_association)
34
+ reflection ||= model_instance.class.reflections.values.find { |r| r.foreign_key == column_or_association }
35
+
36
+ if reflection
37
+ [reflection.name.to_s, reflection.foreign_key.to_s]
38
+ else
39
+ [column_or_association]
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -26,6 +26,48 @@ dependencies:
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.18'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.18'
41
+ - !ruby/object:Gem::Dependency
42
+ name: selenium-webdriver
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.142'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.142'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webdrivers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: puma
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
73
  - - ">="
@@ -129,6 +171,7 @@ executables: []
129
171
  extensions: []
130
172
  extra_rdoc_files: []
131
173
  files:
174
+ - ".yardopts"
132
175
  - LICENSE
133
176
  - README.md
134
177
  - Rakefile
@@ -161,6 +204,12 @@ files:
161
204
  - app/views/super/feather/README.md
162
205
  - app/views/super/feather/_chevron_down.svg
163
206
  - config/routes.rb
207
+ - docs/README.md
208
+ - docs/controls.md
209
+ - docs/faq.md
210
+ - docs/quick_start.md
211
+ - docs/webpacker.md
212
+ - docs/yard_customizations.rb
164
213
  - frontend/super-frontend/build.js
165
214
  - frontend/super-frontend/dist/application.css
166
215
  - frontend/super-frontend/dist/application.js
@@ -185,10 +234,9 @@ files:
185
234
  - lib/generators/super/webpacker/templates/pack_super_application.js.erb.tt
186
235
  - lib/generators/super/webpacker/webpacker_generator.rb
187
236
  - lib/super.rb
188
- - lib/super/action.rb
189
- - lib/super/action/step.rb
190
237
  - lib/super/action_inquirer.rb
191
238
  - lib/super/assets.rb
239
+ - lib/super/compatibility.rb
192
240
  - lib/super/configuration.rb
193
241
  - lib/super/controls.rb
194
242
  - lib/super/display.rb
@@ -204,26 +252,9 @@ files:
204
252
  - lib/super/partial.rb
205
253
  - lib/super/plugin.rb
206
254
  - lib/super/schema.rb
207
- - lib/super/test_support/copy_app_templates/controllers/favorite_things_controller.rb
208
- - lib/super/test_support/copy_app_templates/controllers/members_controller.rb
209
- - lib/super/test_support/copy_app_templates/controllers/ships_controller.rb
210
- - lib/super/test_support/copy_app_templates/migrations/20190216224956_create_members.rb
211
- - lib/super/test_support/copy_app_templates/migrations/20190803143320_create_ships.rb
212
- - lib/super/test_support/copy_app_templates/migrations/20190806014121_add_ship_to_members.rb
213
- - lib/super/test_support/copy_app_templates/migrations/20191126050453_create_favorite_things.rb
214
- - lib/super/test_support/copy_app_templates/models/favorite_thing.rb
215
- - lib/super/test_support/copy_app_templates/models/member.rb
216
- - lib/super/test_support/copy_app_templates/models/ship.rb
217
- - lib/super/test_support/copy_app_templates/routes.rb
218
- - lib/super/test_support/copy_app_templates/seeds.rb
219
- - lib/super/test_support/copy_app_templates/views/members/_favorite_things.html.erb
220
- - lib/super/test_support/fixtures/favorite_things.yml
221
- - lib/super/test_support/fixtures/members.yml
222
- - lib/super/test_support/fixtures/ships.yml
223
- - lib/super/test_support/generate_copy_app.rb
224
- - lib/super/test_support/generate_dummy.rb
225
- - lib/super/test_support/starfleet_seeder.rb
255
+ - lib/super/step.rb
226
256
  - lib/super/version.rb
257
+ - lib/super/view_helper.rb
227
258
  - lib/tasks/super_tasks.rake
228
259
  homepage:
229
260
  licenses:
@@ -244,8 +275,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
275
  - !ruby/object:Gem::Version
245
276
  version: '0'
246
277
  requirements: []
247
- rubygems_version: 3.0.3
278
+ rubygems_version: 3.1.3
248
279
  signing_key:
249
280
  specification_version: 4
250
- summary: A simple, powerful, zero* dependency Rails admin framework
281
+ summary: A simple, powerful, zero dependency Rails admin framework
251
282
  test_files: []
@@ -1,22 +0,0 @@
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