super 0.18.0 → 0.19.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/super/application.js +1260 -117
  3. data/app/assets/stylesheets/super/application.css +90711 -90034
  4. data/app/controllers/super/application_controller.rb +32 -2
  5. data/app/controllers/super/substructure_controller.rb +65 -29
  6. data/app/views/super/application/_batch_button.html.erb +12 -0
  7. data/app/views/super/application/_batch_checkbox.csv.erb +1 -0
  8. data/app/views/super/application/_batch_checkbox.html.erb +5 -0
  9. data/app/views/super/application/_batch_form.html.erb +3 -0
  10. data/app/views/super/application/_collection_header.html.erb +7 -6
  11. data/app/views/super/application/_csv_button.html.erb +25 -0
  12. data/app/views/super/application/_display_actions.html.erb +2 -2
  13. data/app/views/super/application/_layout.html.erb +13 -14
  14. data/app/views/super/application/_link.html.erb +8 -0
  15. data/app/views/super/application/_member_header.html.erb +7 -7
  16. data/app/views/super/application/_pagination.html.erb +1 -0
  17. data/app/views/super/application/_site_header.html.erb +4 -4
  18. data/app/views/super/application/_view_chain.html.erb +5 -0
  19. data/config/locales/en.yml +8 -0
  20. data/frontend/super-frontend/dist/application.css +90711 -90034
  21. data/frontend/super-frontend/dist/application.js +1260 -117
  22. data/frontend/super-frontend/dist/package.json +13 -0
  23. data/lib/generators/super/webpacker/USAGE +1 -7
  24. data/lib/generators/super/webpacker/templates/pack_super_application.js.tt +2 -0
  25. data/lib/generators/super/webpacker/webpacker_generator.rb +10 -6
  26. data/lib/super/cheat.rb +1 -0
  27. data/lib/super/display/schema_types.rb +6 -0
  28. data/lib/super/engine.rb +5 -0
  29. data/lib/super/error.rb +9 -0
  30. data/lib/super/layout.rb +9 -33
  31. data/lib/super/link.rb +2 -7
  32. data/lib/super/link_builder.rb +0 -4
  33. data/lib/super/packaged_asset.rb +49 -0
  34. data/lib/super/pagination.rb +2 -1
  35. data/lib/super/reorderable_hash.rb +88 -0
  36. data/lib/super/reset.rb +20 -4
  37. data/lib/super/version.rb +1 -1
  38. data/lib/super/view_chain.rb +25 -0
  39. data/lib/super.rb +3 -0
  40. metadata +31 -6
  41. data/lib/generators/super/webpacker/templates/pack_super_application.js.erb.tt +0 -2
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@superadministration/super",
3
+ "description": "The frontend code for Super, a Rails admin framework",
4
+ "homepage": "https://github.com/zachahn/super",
5
+ "license": "LGPL-3.0-only",
6
+ "main": "application.js",
7
+ "files": [
8
+ "application.js",
9
+ "application.css",
10
+ "package.json"
11
+ ],
12
+ "version": "0.19.0-rc1"
13
+ }
@@ -1,15 +1,9 @@
1
1
  Description:
2
2
  Creates the necessary files for assets to be served under Webpacker
3
3
 
4
- Webpacker support requires that you install ERB support for Webpacker.
5
-
6
- Installing ERB on webpacker is usually done by running the command:
7
- `rails webpacker:install:erb`
8
-
9
4
  Example:
10
- rails webpacker:install:erb # if you hadn't set up ERB already
11
5
  rails generate super:webpacker
12
6
 
13
7
  This will:
14
- Create app/javascript/packs/super/application.js.erb
8
+ Create app/javascript/packs/super/application.js
15
9
  Modify config/initializers/super.rb
@@ -0,0 +1,2 @@
1
+ import Super from "@superadministration/super";
2
+ import "@superadministration/super/application.css";
@@ -7,12 +7,12 @@ module Super
7
7
  def copy_the_pack_file
8
8
  path =
9
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"
10
+ "app/packs/entrypoints/super/application.js"
11
11
  else
12
- "app/javascript/packs/super/application.js.erb"
12
+ "app/javascript/packs/super/application.js"
13
13
  end
14
14
 
15
- template("pack_super_application.js.erb", path)
15
+ template("pack_super_application.js", path)
16
16
  end
17
17
 
18
18
  def set_asset_handler_to_webpacker
@@ -24,9 +24,13 @@ module Super
24
24
  )
25
25
  end
26
26
 
27
- def remind_about_erb
28
- say "Make sure ERB is set up for Webpacker!", :bold
29
- say "Run if needed: bundle exec rails webpacker:install:erb"
27
+ def install_via_yarn
28
+ super_root = Pathname.new(__dir__).join("../../../..")
29
+ if super_root.join("dummy_path.rb").file?
30
+ run "yarn add file:#{super_root.join("frontend/super-frontend/dist")}"
31
+ else
32
+ run "yarn add @superadministration/super@#{Super::VERSION} --exact"
33
+ end
30
34
  end
31
35
  end
32
36
  end
data/lib/super/cheat.rb CHANGED
@@ -8,6 +8,7 @@ module Super
8
8
  paths
9
9
  .map { |f| File.read(File.expand_path(f, __dir__)) }
10
10
  .flat_map { |content| content.scan(/^\s+(?:helper_method )?def .*$/) }
11
+ .reject { |method| method =~ /\bdef self\./ }
11
12
  .map { |method| method.strip.sub(/^(?:helper_method )?def /, "#") }
12
13
 
13
14
  puts "== Super::ApplicationController"
@@ -129,6 +129,12 @@ module Super
129
129
  real(:column, &transform_block)
130
130
  end
131
131
 
132
+ def batch
133
+ real do |value|
134
+ Partial.new("batch_checkbox", locals: { value: value })
135
+ end
136
+ end
137
+
132
138
  def string; real(&:to_s); end
133
139
 
134
140
  def timestamp; real(&:to_s); end
data/lib/super/engine.rb CHANGED
@@ -15,6 +15,11 @@ module Super
15
15
  Super::Plugin::Registry.controller.ordered do |klass, method_name|
16
16
  Super::ApplicationController.public_send(method_name, klass)
17
17
  end
18
+
19
+ Super::PackagedAsset.warning_message =
20
+ if !Super::PackagedAsset.version_matches_gem?(Rails.root.join("package.json"))
21
+ I18n.t("super.mismatching_package_json_gemfile_versions")
22
+ end
18
23
  end
19
24
  end
20
25
  end
data/lib/super/error.rb CHANGED
@@ -37,5 +37,14 @@ module Super
37
37
  class ArgumentError < Enum; end
38
38
  class UndefinedCase < Enum; end
39
39
  end
40
+
41
+ class ReorderableHash < Error
42
+ class DuplicateKey < ReorderableHash; end
43
+ class KeyError < ReorderableHash; end
44
+ end
45
+
46
+ class ViewChain < Error
47
+ class ChainAlreadyStarted < ViewChain; end
48
+ end
40
49
  end
41
50
  end
data/lib/super/layout.rb CHANGED
@@ -6,44 +6,20 @@ module Super
6
6
  class Layout
7
7
  include Super::Partial::Resolving
8
8
 
9
- def initialize(headers: nil, asides: nil, mains: nil, footers: nil)
10
- @headers = Array(headers).compact
11
- @asides = Array(asides).compact
12
- @mains = Array(mains).compact
13
- @footers = Array(footers).compact
9
+ def initialize(header: nil, aside: nil, main: nil, footer: nil)
10
+ @header = header
11
+ @aside = aside
12
+ @main = main
13
+ @footer = footer
14
14
  end
15
15
 
16
- attr_reader :headers
17
- attr_reader :asides
18
- attr_reader :mains
19
- attr_reader :footers
16
+ attr_reader :header
17
+ attr_reader :aside
18
+ attr_reader :main
19
+ attr_reader :footer
20
20
 
21
21
  def to_partial_path
22
22
  "layout"
23
23
  end
24
-
25
- def resolve(template)
26
- @resolved_headers = resolve_for_rendering(template, headers, nil)
27
- @resolved_asides = resolve_for_rendering(template, asides, nil)
28
- @resolved_mains = resolve_for_rendering(template, mains, nil)
29
- @resolved_footers = resolve_for_rendering(template, footers, nil)
30
- self
31
- end
32
-
33
- def resolved_headers
34
- @resolved_headers || []
35
- end
36
-
37
- def resolved_asides
38
- @resolved_asides || []
39
- end
40
-
41
- def resolved_mains
42
- @resolved_mains || []
43
- end
44
-
45
- def resolved_footers
46
- @resolved_footers || []
47
- end
48
24
  end
49
25
  end
data/lib/super/link.rb CHANGED
@@ -107,13 +107,8 @@ module Super
107
107
  @href = Super::Compatability.polymorphic_path_container.polymorphic_path(@href)
108
108
  end
109
109
 
110
- def to_s(default_options: nil, **)
111
- default_options ||= {}
112
- ActionController::Base.helpers.link_to(
113
- text,
114
- href,
115
- default_options.deep_merge(options)
116
- )
110
+ def to_partial_path
111
+ "link"
117
112
  end
118
113
 
119
114
  def ==(other)
@@ -19,10 +19,6 @@ module Super
19
19
 
20
20
  attr_reader :requirements
21
21
 
22
- def to_s(default_options: nil, **kwargs)
23
- resolve(**kwargs).to_s(default_options: default_options)
24
- end
25
-
26
22
  def resolve(**kwargs)
27
23
  Link.new(
28
24
  into_value(@text, kwargs),
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class PackagedAsset
5
+ VERSION_BEGINNING = /\A\d+\.\d+.\d+/.freeze
6
+
7
+ class << self
8
+ attr_accessor :warning_message
9
+ end
10
+
11
+ def self.comparable_super_version
12
+ ::Super::VERSION[VERSION_BEGINNING]
13
+ end
14
+
15
+ def self.version_matches_gem?(package_json_path)
16
+ return true if ENV.key?("SUPER_IGNORE_PACKAGE_JSON_VERSION")
17
+
18
+ asset = new(package_json_path)
19
+
20
+ return true if !asset.comparable_version
21
+
22
+ asset.comparable_version == comparable_super_version
23
+ end
24
+
25
+ def initialize(package_json_path)
26
+ @package_json_path = package_json_path
27
+ end
28
+
29
+ def full_version
30
+ if instance_variable_defined?(:@full_version)
31
+ return @full_version
32
+ end
33
+
34
+ @full_version = JSON.parse(@package_json_path.read).dig("dependencies", "@superadministration/super")
35
+ rescue
36
+ @full_version = nil
37
+ end
38
+
39
+ def comparable_version
40
+ if instance_variable_defined?(:@asset_version)
41
+ return @asset_version
42
+ end
43
+
44
+ @asset_version = full_version[VERSION_BEGINNING]
45
+ rescue
46
+ @asset_version = nil
47
+ end
48
+ end
49
+ end
@@ -76,9 +76,10 @@ module Super
76
76
  module ControllerMethods
77
77
  def index
78
78
  super
79
+ return if !@records
79
80
  @pagination = initialize_pagination
80
81
  @records = paginate_records
81
- @view.mains.first.parts.push(:@pagination)
82
+ @view.main.insert(:pagination, @pagination, before: :main)
82
83
  end
83
84
  end
84
85
  end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class ReorderableHash
5
+ include TSort
6
+ include Enumerable
7
+
8
+ UNDEFINED = BasicObject.new
9
+
10
+ def initialize(data = {})
11
+ @data = data
12
+ @ordering = {}
13
+ keys = @data.keys
14
+ dependencies = []
15
+ keys.each do |key|
16
+ @ordering[key] = dependencies.dup
17
+ dependencies.push(key)
18
+ end
19
+ end
20
+
21
+ def insert(key, value, before: UNDEFINED, after: UNDEFINED)
22
+ if @ordering.key?(key) || @data.key?(key)
23
+ raise Super::Error::ReorderableHash::DuplicateKey, "Duplicate key: #{key}"
24
+ end
25
+ @ordering[key] = []
26
+ @data[key] = value
27
+
28
+ order(key, before: before, after: after)
29
+
30
+ nil
31
+ end
32
+
33
+ def order(key, before: UNDEFINED, after: UNDEFINED)
34
+ if before != UNDEFINED
35
+ if !@ordering.key?(before)
36
+ raise KeyError, "Before key not found. Have: #{@data.keys} Requested: #{before}"
37
+ end
38
+ @ordering[before].push(key)
39
+ end
40
+
41
+ if after != UNDEFINED
42
+ if !@ordering.key?(after)
43
+ raise KeyError, "After key not found. Have: #{@data.keys} Requested: #{after}"
44
+ end
45
+ @ordering[key].push(after)
46
+ end
47
+ end
48
+
49
+ def tsort_each_node(&block)
50
+ @ordering.each_key(&block)
51
+ end
52
+
53
+ def tsort_each_child(node, &block)
54
+ dependencies = @ordering.fetch(node) { [] }
55
+ dependencies.each(&block)
56
+ end
57
+
58
+ def []=(key, where, value)
59
+ insert(key, value, **where)
60
+ end
61
+
62
+ def keys
63
+ tsort
64
+ end
65
+
66
+ def values
67
+ keys.each_with_object([]) do |key, array|
68
+ array.push(@data[key])
69
+ end
70
+ end
71
+
72
+ def to_h
73
+ keys.each_with_object({}) do |key, hash|
74
+ hash[key] = @data[key]
75
+ end
76
+ end
77
+
78
+ def each
79
+ if !block_given?
80
+ return enum_for(:each)
81
+ end
82
+
83
+ tsort_each do |key|
84
+ yield key, @data[key]
85
+ end
86
+ end
87
+ end
88
+ end
data/lib/super/reset.rb CHANGED
@@ -4,6 +4,20 @@ module Super
4
4
  module Reset
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ KEEP = {
8
+ # Defined by Rails
9
+ _layout: true,
10
+ _generate_paths_by_default: true,
11
+
12
+ # Defined in Super::SubstructureController
13
+ navigation: true,
14
+ page_title: true,
15
+
16
+ # Defined in Super::ApplicationController
17
+ current_action: true,
18
+ with_current_action: true,
19
+ }
20
+
7
21
  included do
8
22
  undef_method :index
9
23
  undef_method :show
@@ -14,10 +28,12 @@ module Super
14
28
  undef_method :destroy
15
29
 
16
30
  Super::SubstructureController.private_instance_methods(false).each do |imethod|
17
- next if imethod == :_layout
18
- next if imethod == :_generate_paths_by_default
19
- next if imethod == :navigation
20
- next if imethod == :page_title
31
+ next if KEEP.key?(imethod)
32
+ undef_method imethod
33
+ end
34
+
35
+ Super::ApplicationController.private_instance_methods(false).each do |imethod|
36
+ next if KEEP.key?(imethod)
21
37
  undef_method imethod
22
38
  end
23
39
  end
data/lib/super/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Super
4
- VERSION = "0.18.0"
4
+ VERSION = "0.19.0.rc1"
5
5
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class ViewChain
5
+ def initialize(chain)
6
+ @data = ReorderableHash.new(chain)
7
+ end
8
+
9
+ def chain
10
+ @chain ||= @data.values
11
+ end
12
+
13
+ def insert(*args, **kwargs)
14
+ if instance_variable_defined?(:@chain)
15
+ raise Error::ViewChain::ChainAlreadyStarted
16
+ end
17
+
18
+ @data.insert(*args, **kwargs)
19
+ end
20
+
21
+ def to_partial_path
22
+ "view_chain"
23
+ end
24
+ end
25
+ end
data/lib/super.rb CHANGED
@@ -34,16 +34,19 @@ require "super/layout"
34
34
  require "super/link"
35
35
  require "super/link_builder"
36
36
  require "super/navigation"
37
+ require "super/packaged_asset"
37
38
  require "super/pagination"
38
39
  require "super/panel"
39
40
  require "super/partial"
40
41
  require "super/plugin"
41
42
  require "super/query/form_object"
43
+ require "super/reorderable_hash"
42
44
  require "super/reset"
43
45
  require "super/schema"
44
46
  require "super/schema/guesser"
45
47
  require "super/sort"
46
48
  require "super/version"
49
+ require "super/view_chain"
47
50
  require "super/view_helper"
48
51
 
49
52
  require "super/engine"
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.18.0
4
+ version: 0.19.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -226,6 +226,20 @@ dependencies:
226
226
  - - ">="
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
+ - !ruby/object:Gem::Dependency
230
+ name: minitest-bisect
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
229
243
  description:
230
244
  email:
231
245
  - engineering@zachahn.com
@@ -243,7 +257,12 @@ files:
243
257
  - app/controllers/super/substructure_controller.rb
244
258
  - app/helpers/super/form_builder_helper.rb
245
259
  - app/views/layouts/super/application.html.erb
260
+ - app/views/super/application/_batch_button.html.erb
261
+ - app/views/super/application/_batch_checkbox.csv.erb
262
+ - app/views/super/application/_batch_checkbox.html.erb
263
+ - app/views/super/application/_batch_form.html.erb
246
264
  - app/views/super/application/_collection_header.html.erb
265
+ - app/views/super/application/_csv_button.html.erb
247
266
  - app/views/super/application/_display_actions.html.erb
248
267
  - app/views/super/application/_display_index.html.erb
249
268
  - app/views/super/application/_display_rich_text.html.erb
@@ -257,6 +276,7 @@ files:
257
276
  - app/views/super/application/_form_has_many.html.erb
258
277
  - app/views/super/application/_form_has_one.html.erb
259
278
  - app/views/super/application/_layout.html.erb
279
+ - app/views/super/application/_link.html.erb
260
280
  - app/views/super/application/_member_header.html.erb
261
281
  - app/views/super/application/_pagination.html.erb
262
282
  - app/views/super/application/_panel.html.erb
@@ -265,6 +285,7 @@ files:
265
285
  - app/views/super/application/_site_header.html.erb
266
286
  - app/views/super/application/_sort.html.erb
267
287
  - app/views/super/application/_sort_expression.html.erb
288
+ - app/views/super/application/_view_chain.html.erb
268
289
  - app/views/super/application/edit.html.erb
269
290
  - app/views/super/application/index.csv.erb
270
291
  - app/views/super/application/index.html.erb
@@ -277,6 +298,7 @@ files:
277
298
  - config/routes.rb
278
299
  - frontend/super-frontend/dist/application.css
279
300
  - frontend/super-frontend/dist/application.js
301
+ - frontend/super-frontend/dist/package.json
280
302
  - lib/generators/super/action_text/USAGE
281
303
  - lib/generators/super/action_text/action_text_generator.rb
282
304
  - lib/generators/super/action_text/templates/pack_super_action_text.css
@@ -289,7 +311,7 @@ files:
289
311
  - lib/generators/super/resource/resource_generator.rb
290
312
  - lib/generators/super/resource/templates/resources_controller.rb.tt
291
313
  - lib/generators/super/webpacker/USAGE
292
- - lib/generators/super/webpacker/templates/pack_super_application.js.erb.tt
314
+ - lib/generators/super/webpacker/templates/pack_super_application.js.tt
293
315
  - lib/generators/super/webpacker/webpacker_generator.rb
294
316
  - lib/super.rb
295
317
  - lib/super/action_inquirer.rb
@@ -320,12 +342,14 @@ files:
320
342
  - lib/super/link.rb
321
343
  - lib/super/link_builder.rb
322
344
  - lib/super/navigation.rb
345
+ - lib/super/packaged_asset.rb
323
346
  - lib/super/pagination.rb
324
347
  - lib/super/panel.rb
325
348
  - lib/super/partial.rb
326
349
  - lib/super/partial/resolving.rb
327
350
  - lib/super/plugin.rb
328
351
  - lib/super/query/form_object.rb
352
+ - lib/super/reorderable_hash.rb
329
353
  - lib/super/reset.rb
330
354
  - lib/super/schema.rb
331
355
  - lib/super/schema/common.rb
@@ -334,6 +358,7 @@ files:
334
358
  - lib/super/useful/builder.rb
335
359
  - lib/super/useful/enum.rb
336
360
  - lib/super/version.rb
361
+ - lib/super/view_chain.rb
337
362
  - lib/super/view_helper.rb
338
363
  - lib/tasks/super/cheat.rake
339
364
  homepage:
@@ -356,11 +381,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
356
381
  version: 2.3.0
357
382
  required_rubygems_version: !ruby/object:Gem::Requirement
358
383
  requirements:
359
- - - ">="
384
+ - - ">"
360
385
  - !ruby/object:Gem::Version
361
- version: '0'
386
+ version: 1.3.1
362
387
  requirements: []
363
- rubygems_version: 3.2.4
388
+ rubygems_version: 3.0.3.1
364
389
  signing_key:
365
390
  specification_version: 4
366
391
  summary: A simple, powerful, zero dependency Rails admin framework
@@ -1,2 +0,0 @@
1
- import Super from "<%%= Super::Assets.dist("super", "super-frontend").join("application") %>";
2
- import "<%%= Super::Assets.dist("super", "super-frontend").join("application.css") %>";