super 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +56 -0
- data/README.md +6 -0
- data/STABILITY.md +50 -0
- data/app/assets/javascripts/super/application.js +12 -7
- data/app/controllers/super/application_controller.rb +1 -1
- data/app/views/layouts/super/application.html.erb +14 -6
- data/app/views/super/application/_super_panel.html.erb +1 -1
- data/app/views/super/application/_super_schema_display_index.html.erb +4 -4
- data/app/views/super/application/_super_schema_display_show.html.erb +3 -3
- data/app/views/super/application/_super_schema_form.html.erb +1 -1
- data/frontend/super-frontend/dist/application.js +12 -7
- data/frontend/super-frontend/src/javascripts/super/application.ts +5 -8
- data/lib/generators/super/resource/templates/resources_controller.rb.tt +1 -31
- data/lib/generators/super/webpacker/webpacker_generator.rb +3 -2
- data/lib/super.rb +11 -0
- data/lib/super/assets.rb +108 -38
- data/lib/super/configuration.rb +18 -73
- data/lib/super/controls.rb +2 -25
- data/lib/super/controls/optional.rb +41 -16
- data/lib/super/controls/required.rb +1 -29
- data/lib/super/controls/steps.rb +9 -23
- data/lib/super/display.rb +72 -0
- data/lib/super/display/guesser.rb +34 -0
- data/lib/super/display/schema_types.rb +19 -62
- data/lib/super/engine.rb +1 -1
- data/lib/super/filter.rb +5 -130
- data/lib/super/filter/form_object.rb +97 -0
- data/lib/super/filter/guesser.rb +30 -0
- data/lib/super/filter/plugin.rb +47 -0
- data/lib/super/filter/schema_types.rb +1 -7
- data/lib/super/form.rb +27 -40
- data/lib/super/form/builder.rb +48 -0
- data/lib/super/form/guesser.rb +27 -0
- data/lib/super/form/schema_types.rb +19 -29
- data/lib/super/form/strong_params.rb +29 -0
- data/lib/super/pagination.rb +10 -16
- data/lib/super/schema.rb +0 -25
- data/lib/super/schema/common.rb +25 -0
- data/lib/super/schema/guesser.rb +77 -0
- data/lib/super/version.rb +1 -1
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c7f47bcff0941f86aa7bdb0fa79fec029120128728fdcff3c4b8944dae7bf91
|
4
|
+
data.tar.gz: 58e5532e0d911cbbe859be53912f86967b29e1d77b9d9b221744114b84d1a5be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc95583d9a8926a105a48515c695b9546d61eb9a8043c22741759b40620c85038affecaee527fce0356e635a2a9ef4327ff33dc5772469dcbd75cc4cf90eddc
|
7
|
+
data.tar.gz: b9539c0e2b57adc6ea1c78398ea5240291de73b7922dd42d8f8049f822c08be24dab24652c475273990c9392f7a3a58e1f277ea41e9db322358dcf653141c221
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Thank you for thinking about contributing to Super!
|
4
|
+
|
5
|
+
|
6
|
+
## General guidelines
|
7
|
+
|
8
|
+
There are a few ground rules that to adhere to:
|
9
|
+
|
10
|
+
* be friendly and patient,
|
11
|
+
* be welcoming,
|
12
|
+
* be considerate,
|
13
|
+
* be respectful,
|
14
|
+
* be careful in the words that you choose and be kind to others,
|
15
|
+
* when we disagree, try to understand why.
|
16
|
+
|
17
|
+
This isn't an exhaustive list of things that you can't do. Rather, take it in
|
18
|
+
the spirit in which it's intended - a guide to make it easier to communicate and
|
19
|
+
participate in the community.
|
20
|
+
|
21
|
+
This applies to all spaces managed by the Super project.
|
22
|
+
|
23
|
+
If you believe someone is violating the code of conduct, we ask that you report
|
24
|
+
it by emailing: super+conduct at zachahn.com
|
25
|
+
|
26
|
+
Offenders may be banned, asked to apologize, etc.
|
27
|
+
|
28
|
+
(These guidelines are based on the [FreeBSD CoC][FreeBSD CoC], which in turn is
|
29
|
+
based on [LLVM Project's draft CoC][LLVM CoC], which in turn is based on the
|
30
|
+
[Django Project Code of Conduct][Django CoC], which is in turn based on wording
|
31
|
+
from the Speak Up! project.)
|
32
|
+
|
33
|
+
|
34
|
+
## Bug reports / issues
|
35
|
+
|
36
|
+
1. Please tell us what version of Super, Ruby, and Rails you are using
|
37
|
+
1. Please search the issues before posting your problem
|
38
|
+
1. Please ask questions in a public place to benefit all Super users
|
39
|
+
1. Please email security-related problems to super+security [at] zachahn.com
|
40
|
+
|
41
|
+
|
42
|
+
## Feature requests / pull requests
|
43
|
+
|
44
|
+
Contributors will need to sign a CLA. This isn't set up yet, so I won't be able
|
45
|
+
to accept contributions.
|
46
|
+
|
47
|
+
1. Please note that pull requests may be closed/denied for any reason.
|
48
|
+
Your feature may be better as its own repository. If so, I will link to your
|
49
|
+
project from the README!
|
50
|
+
1. Please allow Super's contributors to modify your PR before merging.
|
51
|
+
It might make the process a bit smoother, but this isn't a necessity.
|
52
|
+
|
53
|
+
|
54
|
+
[FreeBSD CoC]: https://www.freebsd.org/internal/code-of-conduct.html
|
55
|
+
[LLVM CoC]: https://llvm.org/docs/CodeOfConduct.html
|
56
|
+
[Django CoC]: https://www.djangoproject.com/conduct/
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Super
|
2
2
|
|
3
|
+
![Unit tests status](https://github.com/zachahn/super/workflows/Unit%20tests/badge.svg?branch=master)
|
4
|
+
[![Gem](https://img.shields.io/gem/v/super)][gem]
|
5
|
+
[![Try the demo](https://img.shields.io/badge/try-demo-blue)][super_demo]
|
6
|
+
|
7
|
+
|
3
8
|
Super is an admin framework for Ruby on Rails applications. Super helps you make
|
4
9
|
powerful admin pages quickly so that you can concentrate on the parts of your
|
5
10
|
app that make it great.
|
@@ -103,6 +108,7 @@ See [CONTRIBUTING](./CONTRIBUTING.md)
|
|
103
108
|
The gem is available under the terms of the [GNU LGPLv3](./LICENSE).
|
104
109
|
|
105
110
|
|
111
|
+
[gem]: https://rubygems.org/gems/super
|
106
112
|
[Administrate]: https://github.com/thoughtbot/administrate
|
107
113
|
[ActiveAdmin]: https://github.com/activeadmin/activeadmin
|
108
114
|
[RailsAdmin]: https://github.com/sferik/rails_admin
|
data/STABILITY.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Stability
|
2
|
+
|
3
|
+
The table below shows the current progress towards API stability and the release
|
4
|
+
of version 1.0.
|
5
|
+
|
6
|
+
Note though that it is neither a comprehensive list nor a guarantee of
|
7
|
+
stability.
|
8
|
+
|
9
|
+
|
10
|
+
<table>
|
11
|
+
<thead>
|
12
|
+
<tr><th>Feature</th><th>Status</th></tr>
|
13
|
+
</thead>
|
14
|
+
<tbody>
|
15
|
+
<tr><td>UI</td> <td>❌</td></tr>
|
16
|
+
<tr><td>Frontend JS</td> <td>❌</td></tr>
|
17
|
+
<tr><td><code>Super::ActionInquirer</code></td> <td>✅</td></tr>
|
18
|
+
<tr><td><code>Super::ApplicationController</code></td> <td>✅</td></tr>
|
19
|
+
<tr><td><code>Super::Assets</code></td> <td>🚧</td></tr>
|
20
|
+
<tr><td><code>Super::ClientError</code></td> <td>✅</td></tr>
|
21
|
+
<tr><td><code>Super::Compatability</code></td> <td>🙈</td></tr>
|
22
|
+
<tr><td><code>Super::Configuration</code></td> <td>❌</td></tr>
|
23
|
+
<tr><td><code>Super::Controls::Optional</code></td> <td>✅</td></tr>
|
24
|
+
<tr><td><code>Super::Controls::Required</code></td> <td>✅</td></tr>
|
25
|
+
<tr><td><code>Super::Controls::Steps</code></td> <td>🤔</td></tr>
|
26
|
+
<tr><td><code>Super::Controls</code></td> <td>✅</td></tr>
|
27
|
+
<tr><td><code>Super::Display</code></td> <td>🤔</td></tr>
|
28
|
+
<tr><td><code>Super::Engine</code></td> <td>🙈</td></tr>
|
29
|
+
<tr><td><code>Super::Error</code></td> <td>✅</td></tr>
|
30
|
+
<tr><td><code>Super::Filter</code></td> <td>❌</td></tr>
|
31
|
+
<tr><td><code>Super::Form</code></td> <td>🤔</td></tr>
|
32
|
+
<tr><td><code>Super::Layout</code></td> <td>🤔</td></tr>
|
33
|
+
<tr><td><code>Super::Link</code></td> <td>✅</td></tr>
|
34
|
+
<tr><td><code>Super::Navigation</code></td> <td>🤔</td></tr>
|
35
|
+
<tr><td><code>Super::Pagination</code></td> <td>🤔</td></tr>
|
36
|
+
<tr><td><code>Super::Panel</code></td> <td>🤔</td></tr>
|
37
|
+
<tr><td><code>Super::Partial</code></td> <td>🤔</td></tr>
|
38
|
+
<tr><td><code>Super::Plugin</code></td> <td>✅</td></tr>
|
39
|
+
<tr><td><code>Super::ViewHelper</code></td> <td>❌</td></tr>
|
40
|
+
</tbody>
|
41
|
+
</table>
|
42
|
+
|
43
|
+
|
44
|
+
### Legend
|
45
|
+
|
46
|
+
* ✅ Tentatively stable. Further changes will probably be additive
|
47
|
+
* 🚧 Likely upcoming breaking changes
|
48
|
+
* ❌ Planned upcoming breaking changes
|
49
|
+
* 🤔 Undecided
|
50
|
+
* 🙈 Private API
|
@@ -4399,21 +4399,26 @@ var __importDefault = this && this.__importDefault || function (mod) {
|
|
4399
4399
|
Object.defineProperty(exports, "__esModule", {
|
4400
4400
|
value: true
|
4401
4401
|
});
|
4402
|
+
exports.StimulusController = exports.StimulusApplication = void 0;
|
4402
4403
|
|
4403
4404
|
var ujs_1 = __importDefault(require("@rails/ujs"));
|
4404
4405
|
|
4405
4406
|
var stimulus_1 = require("stimulus");
|
4406
4407
|
|
4408
|
+
Object.defineProperty(exports, "StimulusController", {
|
4409
|
+
enumerable: true,
|
4410
|
+
get: function get() {
|
4411
|
+
return stimulus_1.Controller;
|
4412
|
+
}
|
4413
|
+
});
|
4414
|
+
|
4407
4415
|
var apply_template_controller_1 = __importDefault(require("./apply_template_controller"));
|
4408
4416
|
|
4409
4417
|
var toggle_pending_destruction_controller_1 = __importDefault(require("./toggle_pending_destruction_controller"));
|
4410
4418
|
|
4411
4419
|
ujs_1.default.start();
|
4412
|
-
var
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
StimulusApplication: application,
|
4417
|
-
StimulusController: stimulus_1.Controller
|
4418
|
-
};
|
4420
|
+
var StimulusApplication = stimulus_1.Application.start();
|
4421
|
+
exports.StimulusApplication = StimulusApplication;
|
4422
|
+
StimulusApplication.register("apply-template", apply_template_controller_1.default);
|
4423
|
+
StimulusApplication.register("toggle-pending-destruction", toggle_pending_destruction_controller_1.default);
|
4419
4424
|
},{"@rails/ujs":"../node_modules/@rails/ujs/lib/assets/compiled/rails-ujs.js","stimulus":"../node_modules/stimulus/index.js","./apply_template_controller":"javascripts/super/apply_template_controller.ts","./toggle_pending_destruction_controller":"javascripts/super/toggle_pending_destruction_controller.ts"}]},{},["javascripts/super/application.ts"], "Super")
|
@@ -9,12 +9,20 @@
|
|
9
9
|
|
10
10
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
11
11
|
|
12
|
-
<%
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
<% Super.configuration.stylesheets.each do |stylesheet| %>
|
13
|
+
<% if stylesheet.handler.sprockets? %>
|
14
|
+
<%= stylesheet_link_tag(stylesheet.path, **stylesheet.arguments) %>
|
15
|
+
<% elsif stylesheet.handler.webpacker? %>
|
16
|
+
<%= stylesheet_pack_tag(stylesheet.path, **stylesheet.arguments) %>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% Super.configuration.javascripts.each do |javascript| %>
|
21
|
+
<% if javascript.handler.sprockets? %>
|
22
|
+
<%= javascript_include_tag(javascript.path) %>
|
23
|
+
<% elsif javascript.handler.webpacker? %>
|
24
|
+
<%= javascript_pack_tag(javascript.path) %>
|
25
|
+
<% end %>
|
18
26
|
<% end %>
|
19
27
|
</head>
|
20
28
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% if super_panel.resolve(self, block_given? ? Proc.new : nil).resolved_parts.any? %>
|
1
|
+
<% if super_panel.resolve(self, block_given? ? Proc.new { yield } : nil).resolved_parts.any? %>
|
2
2
|
<div class="border rounded shadow border-gray-400 bg-white px-5 pt-4 pb-8 mt-6">
|
3
3
|
<% super_panel.resolved_parts.each do |partial| %>
|
4
4
|
<%= Super::Partial.render(partial, template: self) %>
|
@@ -2,9 +2,9 @@
|
|
2
2
|
<table class="w-full border-separate relative" cellspacing="0" cellpadding="0">
|
3
3
|
<thead class="">
|
4
4
|
<tr class="">
|
5
|
-
<% super_schema_display_index.
|
5
|
+
<% super_schema_display_index.each_attribute_name do |attribute_name| %>
|
6
6
|
<th class="p-2 first:pl-6 border-b border-b-2 border-gray-400 text-gray-600 text-left text-sm font-normal bg-white sticky top-0 z-10">
|
7
|
-
<%= controls.model.human_attribute_name(
|
7
|
+
<%= controls.model.human_attribute_name(attribute_name) %>
|
8
8
|
</th>
|
9
9
|
<% end %>
|
10
10
|
</tr>
|
@@ -12,9 +12,9 @@
|
|
12
12
|
<tbody class="">
|
13
13
|
<% @records.each.with_index do |record, row_index| %>
|
14
14
|
<tr id="record-pk-<%= record.id %>" class="group">
|
15
|
-
<% super_schema_display_index.
|
15
|
+
<% super_schema_display_index.each_attribute_name do |attribute_name| %>
|
16
16
|
<td class="py-1 px-2 first:pl-5 border-transparent border-t border-b group-hover:bg-blue-200 first:border-l first:rounded-l-lg last:border-r last:rounded-r-lg bg-white <%= Super::ViewHelper.classes(["bg-gray-100", row_index.odd?]) %>">
|
17
|
-
<%= super_schema_display_index.
|
17
|
+
<%= super_schema_display_index.render_field(template: self, record: record, column: attribute_name) %>
|
18
18
|
</td>
|
19
19
|
<% end %>
|
20
20
|
</tr>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<table class="max-w-full leading-loose mt-4">
|
2
|
-
<% super_schema_display_show.
|
2
|
+
<% super_schema_display_show.each_attribute_name do |attribute_name| %>
|
3
3
|
<tr>
|
4
|
-
<th class="text-right px-4"><%=
|
5
|
-
<td><%= super_schema_display_show.
|
4
|
+
<th class="text-right px-4"><%= controls.model.human_attribute_name(attribute_name) %></th>
|
5
|
+
<td><%= super_schema_display_show.render_field(template: self, record: @record, column: attribute_name) %></td>
|
6
6
|
</tr>
|
7
7
|
<% end %>
|
8
8
|
</table>
|
@@ -4399,21 +4399,26 @@ var __importDefault = this && this.__importDefault || function (mod) {
|
|
4399
4399
|
Object.defineProperty(exports, "__esModule", {
|
4400
4400
|
value: true
|
4401
4401
|
});
|
4402
|
+
exports.StimulusController = exports.StimulusApplication = void 0;
|
4402
4403
|
|
4403
4404
|
var ujs_1 = __importDefault(require("@rails/ujs"));
|
4404
4405
|
|
4405
4406
|
var stimulus_1 = require("stimulus");
|
4406
4407
|
|
4408
|
+
Object.defineProperty(exports, "StimulusController", {
|
4409
|
+
enumerable: true,
|
4410
|
+
get: function get() {
|
4411
|
+
return stimulus_1.Controller;
|
4412
|
+
}
|
4413
|
+
});
|
4414
|
+
|
4407
4415
|
var apply_template_controller_1 = __importDefault(require("./apply_template_controller"));
|
4408
4416
|
|
4409
4417
|
var toggle_pending_destruction_controller_1 = __importDefault(require("./toggle_pending_destruction_controller"));
|
4410
4418
|
|
4411
4419
|
ujs_1.default.start();
|
4412
|
-
var
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
StimulusApplication: application,
|
4417
|
-
StimulusController: stimulus_1.Controller
|
4418
|
-
};
|
4420
|
+
var StimulusApplication = stimulus_1.Application.start();
|
4421
|
+
exports.StimulusApplication = StimulusApplication;
|
4422
|
+
StimulusApplication.register("apply-template", apply_template_controller_1.default);
|
4423
|
+
StimulusApplication.register("toggle-pending-destruction", toggle_pending_destruction_controller_1.default);
|
4419
4424
|
},{"@rails/ujs":"../node_modules/@rails/ujs/lib/assets/compiled/rails-ujs.js","stimulus":"../node_modules/stimulus/index.js","./apply_template_controller":"javascripts/super/apply_template_controller.ts","./toggle_pending_destruction_controller":"javascripts/super/toggle_pending_destruction_controller.ts"}]},{},["javascripts/super/application.ts"], "Super")
|
@@ -1,18 +1,15 @@
|
|
1
1
|
import RailsUjs from "@rails/ujs";
|
2
|
-
import { Application, Controller } from "stimulus";
|
2
|
+
import { Application, Controller as StimulusController } from "stimulus";
|
3
3
|
import ApplyTemplateController from "./apply_template_controller";
|
4
4
|
import TogglePendingDestructionController from "./toggle_pending_destruction_controller";
|
5
5
|
|
6
6
|
RailsUjs.start();
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
let StimulusApplication = Application.start();
|
9
|
+
StimulusApplication.register("apply-template", ApplyTemplateController);
|
10
|
+
StimulusApplication.register(
|
11
11
|
"toggle-pending-destruction",
|
12
12
|
TogglePendingDestructionController
|
13
13
|
);
|
14
14
|
|
15
|
-
export
|
16
|
-
StimulusApplication: application,
|
17
|
-
StimulusController: Controller,
|
18
|
-
};
|
15
|
+
export { StimulusApplication, StimulusController };
|
@@ -6,40 +6,10 @@ class <%= class_name.pluralize %>Controller < <%= parent_controller_name %>
|
|
6
6
|
Controls.new
|
7
7
|
end
|
8
8
|
|
9
|
-
class Controls
|
10
|
-
def title
|
11
|
-
<%= class_name %>.name.pluralize
|
12
|
-
end
|
13
|
-
|
9
|
+
class Controls < Super::Controls
|
14
10
|
def model
|
15
11
|
<%= class_name %>
|
16
12
|
end
|
17
|
-
|
18
|
-
def scope(action:)
|
19
|
-
if action.read?
|
20
|
-
<%= class_name %>.all
|
21
|
-
else
|
22
|
-
<%= class_name %>.all
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def permitted_params(params, action:)
|
27
|
-
if action.create?
|
28
|
-
params.require(:<%= file_name %>).permit()
|
29
|
-
else
|
30
|
-
params.require(:<%= file_name %>).permit()
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def display_schema(action:)
|
35
|
-
Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def form_schema(action:)
|
40
|
-
Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
|
41
|
-
end
|
42
|
-
end
|
43
13
|
end
|
44
14
|
end
|
45
15
|
<% end -%>
|
@@ -12,14 +12,15 @@ module Super
|
|
12
12
|
def set_asset_handler_to_webpacker
|
13
13
|
insert_into_file(
|
14
14
|
"config/initializers/super.rb",
|
15
|
-
" c.
|
15
|
+
" c.javascripts = Super::Assets.use_webpacker(c.javascripts)\n" \
|
16
|
+
" c.stylesheets = Super::Assets.use_webpacker(c.stylesheets)\n",
|
16
17
|
before: /\bend\b/
|
17
18
|
)
|
18
19
|
end
|
19
20
|
|
20
21
|
def remind_about_erb
|
21
22
|
say "Make sure ERB is set up for Webpacker!", :bold
|
22
|
-
say "Run if needed: rails webpacker:install:erb"
|
23
|
+
say "Run if needed: bundle exec rails webpacker:install:erb"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/super.rb
CHANGED
@@ -2,19 +2,29 @@ require "tsort"
|
|
2
2
|
|
3
3
|
require "rails/engine"
|
4
4
|
|
5
|
+
require "super/schema/common"
|
6
|
+
|
5
7
|
require "super/action_inquirer"
|
6
8
|
require "super/assets"
|
7
9
|
require "super/client_error"
|
8
10
|
require "super/compatibility"
|
9
11
|
require "super/configuration"
|
10
12
|
require "super/controls"
|
13
|
+
require "super/display"
|
14
|
+
require "super/display/guesser"
|
11
15
|
require "super/display/schema_types"
|
12
16
|
require "super/error"
|
13
17
|
require "super/filter"
|
18
|
+
require "super/filter/form_object"
|
19
|
+
require "super/filter/guesser"
|
14
20
|
require "super/filter/operator"
|
21
|
+
require "super/filter/plugin"
|
15
22
|
require "super/filter/schema_types"
|
16
23
|
require "super/form"
|
24
|
+
require "super/form/builder"
|
25
|
+
require "super/form/guesser"
|
17
26
|
require "super/form/schema_types"
|
27
|
+
require "super/form/strong_params"
|
18
28
|
require "super/layout"
|
19
29
|
require "super/link"
|
20
30
|
require "super/navigation/automatic"
|
@@ -23,6 +33,7 @@ require "super/panel"
|
|
23
33
|
require "super/partial"
|
24
34
|
require "super/plugin"
|
25
35
|
require "super/schema"
|
36
|
+
require "super/schema/guesser"
|
26
37
|
require "super/version"
|
27
38
|
require "super/view_helper"
|
28
39
|
|
data/lib/super/assets.rb
CHANGED
@@ -1,8 +1,64 @@
|
|
1
1
|
module Super
|
2
2
|
# Utilities for determining whether to use Sprockets or Webpacker
|
3
3
|
class Assets
|
4
|
-
def self.
|
5
|
-
|
4
|
+
def self.webpacker(path, **arguments)
|
5
|
+
Asset.new(handler: Handler.webpacker, path: path, arguments: arguments)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.sprockets(path, **arguments)
|
9
|
+
Asset.new(handler: Handler.sprockets, path: path, arguments: arguments)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.auto(path, **arguments)
|
13
|
+
Asset.new(handler: Handler.auto, path: path, arguments: arguments)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.use_webpacker(assets, grep: nil)
|
17
|
+
assets = [assets] if !assets.kind_of?(Array)
|
18
|
+
|
19
|
+
assets.map do |asset|
|
20
|
+
grep_matches = grep && asset === grep
|
21
|
+
if grep_matches || !grep
|
22
|
+
asset.instance_variable_set(:@handler, Handler.webpacker)
|
23
|
+
end
|
24
|
+
|
25
|
+
asset
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.use_sprockets(assets, grep: nil)
|
30
|
+
assets = [assets] if !assets.kind_of?(Array)
|
31
|
+
|
32
|
+
assets.map do |asset|
|
33
|
+
grep_matches = grep && asset === grep
|
34
|
+
if grep_matches || !grep
|
35
|
+
asset.instance_variable_set(:@asset_handler, Handler.sprockets)
|
36
|
+
end
|
37
|
+
|
38
|
+
asset
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Asset
|
43
|
+
def initialize(handler:, path:, arguments:)
|
44
|
+
@handler = handler
|
45
|
+
@path = path
|
46
|
+
@arguments = arguments
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_reader :handler
|
50
|
+
attr_reader :path
|
51
|
+
attr_reader :arguments
|
52
|
+
|
53
|
+
def ===(other)
|
54
|
+
return true if path == other
|
55
|
+
return true if other.is_a?(Regexp) && path.match?(other)
|
56
|
+
return true if handler == other
|
57
|
+
return true if handler.to_sym == other
|
58
|
+
return true if handler.to_s == other
|
59
|
+
|
60
|
+
false
|
61
|
+
end
|
6
62
|
end
|
7
63
|
|
8
64
|
def self.dist(gem_name, package_name)
|
@@ -15,49 +71,63 @@ module Super
|
|
15
71
|
gem_path.join("frontend", package_name, "dist")
|
16
72
|
end
|
17
73
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
sprockets
|
22
|
-
|
23
|
-
sprockets
|
24
|
-
|
25
|
-
sprockets
|
26
|
-
|
27
|
-
webpacker
|
28
|
-
|
29
|
-
webpacker
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
74
|
+
class Handler
|
75
|
+
def self.auto
|
76
|
+
@auto ||=
|
77
|
+
if Gem::Dependency.new("sprockets", "~> 4.0").matching_specs.any?
|
78
|
+
sprockets
|
79
|
+
elsif Gem::Dependency.new("sprockets", "~> 3.0").matching_specs.any?
|
80
|
+
sprockets
|
81
|
+
elsif Gem::Dependency.new("sprockets", "~> 2.0").matching_specs.any?
|
82
|
+
sprockets
|
83
|
+
elsif Gem::Dependency.new("webpacker", "~> 4.0").matching_specs.any?
|
84
|
+
webpacker
|
85
|
+
elsif Gem::Dependency.new("webpacker", "~> 3.0").matching_specs.any?
|
86
|
+
webpacker
|
87
|
+
else
|
88
|
+
none
|
89
|
+
end
|
90
|
+
end
|
34
91
|
|
35
|
-
|
36
|
-
|
37
|
-
|
92
|
+
def self.sprockets_available?
|
93
|
+
Gem::Dependency.new("sprockets").matching_specs.any? && defined?(Sprockets)
|
94
|
+
end
|
38
95
|
|
39
|
-
|
40
|
-
|
41
|
-
|
96
|
+
def self.sprockets
|
97
|
+
@sprockets ||= new(:sprockets)
|
98
|
+
end
|
42
99
|
|
43
|
-
|
44
|
-
|
45
|
-
|
100
|
+
def self.webpacker
|
101
|
+
@webpacker ||= new(:webpacker)
|
102
|
+
end
|
46
103
|
|
47
|
-
|
48
|
-
|
49
|
-
|
104
|
+
def self.none
|
105
|
+
@none ||= new(:none)
|
106
|
+
end
|
50
107
|
|
51
|
-
|
52
|
-
|
53
|
-
|
108
|
+
def initialize(asset_handler)
|
109
|
+
@asset_handler = asset_handler
|
110
|
+
end
|
54
111
|
|
55
|
-
|
56
|
-
|
57
|
-
|
112
|
+
def sprockets?
|
113
|
+
@asset_handler == :sprockets
|
114
|
+
end
|
115
|
+
|
116
|
+
def webpacker?
|
117
|
+
@asset_handler == :webpacker
|
118
|
+
end
|
119
|
+
|
120
|
+
def none?
|
121
|
+
@asset_handler == :none
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_sym
|
125
|
+
@asset_handler
|
126
|
+
end
|
58
127
|
|
59
|
-
|
60
|
-
|
128
|
+
def to_s
|
129
|
+
@asset_handler.to_s
|
130
|
+
end
|
61
131
|
end
|
62
132
|
end
|
63
133
|
end
|