super 0.0.11 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +0 -9
- data/README.md +42 -54
- data/app/assets/javascripts/super/application.js +5617 -3806
- data/app/assets/stylesheets/super/application.css +114687 -71486
- data/app/controllers/super/application_controller.rb +41 -47
- data/app/controllers/super/substructure_controller.rb +265 -0
- data/app/helpers/super/form_builder_helper.rb +7 -0
- data/app/views/layouts/super/application.html.erb +4 -21
- data/app/views/super/application/_collection_header.html.erb +2 -2
- data/app/views/super/application/{_super_schema_display_actions.html.erb → _display_actions.html.erb} +1 -1
- data/app/views/super/application/{_super_schema_display_index.html.erb → _display_index.html.erb} +5 -5
- data/app/views/super/application/_display_show.html.erb +8 -0
- data/app/views/super/application/_filter_type_select.html.erb +1 -1
- data/app/views/super/application/_filter_type_text.html.erb +1 -1
- data/app/views/super/application/_filter_type_timestamp.html.erb +3 -3
- data/app/views/super/application/{_super_schema_form.html.erb → _form.html.erb} +2 -2
- data/app/views/super/application/_form_field.html.erb +5 -0
- data/app/views/super/application/{_super_layout.html.erb → _layout.html.erb} +8 -8
- data/app/views/super/application/_member_header.html.erb +2 -2
- 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/app/views/super/application/_site_footer.html.erb +3 -0
- data/app/views/super/application/_site_header.html.erb +17 -0
- data/app/views/super/feather/README.md +0 -1
- data/frontend/super-frontend/dist/application.css +114687 -71486
- data/frontend/super-frontend/dist/application.js +5617 -3806
- data/lib/generators/super/install/install_generator.rb +16 -23
- data/lib/generators/super/install/templates/base_controller.rb.tt +1 -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 +4 -10
- data/lib/generators/super/webpacker/webpacker_generator.rb +9 -5
- data/lib/super.rb +6 -2
- data/lib/super/action_inquirer.rb +18 -3
- data/lib/super/assets.rb +44 -23
- data/lib/super/badge.rb +60 -0
- data/lib/super/cheat.rb +17 -0
- data/lib/super/compatibility.rb +19 -0
- data/lib/super/configuration.rb +14 -23
- data/lib/super/display.rb +16 -8
- data/lib/super/display/guesser.rb +2 -0
- data/lib/super/display/schema_types.rb +116 -29
- data/lib/super/error.rb +7 -0
- data/lib/super/form.rb +1 -1
- data/lib/super/form/builder.rb +107 -27
- data/lib/super/form/guesser.rb +10 -1
- data/lib/super/form/schema_types.rb +73 -7
- data/lib/super/layout.rb +1 -1
- data/lib/super/link.rb +42 -31
- data/lib/super/link_builder.rb +58 -0
- data/lib/super/navigation.rb +164 -0
- data/lib/super/pagination.rb +3 -45
- data/lib/super/panel.rb +1 -1
- data/lib/super/reset.rb +22 -0
- data/lib/super/useful/builder.rb +25 -0
- data/lib/super/useful/enum.rb +63 -0
- data/lib/super/version.rb +1 -1
- data/lib/tasks/super/cheat.rake +9 -0
- metadata +27 -31
- data/CONTRIBUTING.md +0 -56
- data/Rakefile +0 -36
- data/STABILITY.md +0 -50
- data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
- data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
- data/app/views/super/application/_form_field_text.html.erb +0 -1
- data/app/views/super/application/_super_schema_display_show.html.erb +0 -8
- data/app/views/super/feather/_chevron_down.html +0 -1
- data/docs/README.md +0 -8
- data/docs/action_text.md +0 -48
- data/docs/cheat.md +0 -41
- 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.rb +0 -17
- data/lib/super/controls/optional.rb +0 -112
- data/lib/super/controls/required.rb +0 -15
- data/lib/super/controls/steps.rb +0 -106
- data/lib/super/controls/view.rb +0 -55
- data/lib/super/navigation/automatic.rb +0 -73
@@ -1 +0,0 @@
|
|
1
|
-
<%= form.super.check_box!(column) %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= form.super.rich_text_area!(column) %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= form.super.text_field!(column) %>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<table class="max-w-full mt-4">
|
2
|
-
<% super_schema_display_show.each_attribute_name do |attribute_name| %>
|
3
|
-
<tr>
|
4
|
-
<th class="py-1 align-baseline text-right px-4"><%= controls.model.human_attribute_name(attribute_name) %></th>
|
5
|
-
<td class="py-1 align-baseline"><%= super_schema_display_show.render_field(template: self, record: @record, column: attribute_name) %></td>
|
6
|
-
</tr>
|
7
|
-
<% end %>
|
8
|
-
</table>
|
@@ -1 +0,0 @@
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>
|
data/docs/README.md
DELETED
data/docs/action_text.md
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @title ActionText
|
3
|
-
-->
|
4
|
-
|
5
|
-
# Using ActionText with Super
|
6
|
-
|
7
|
-
Super has some basic support for editing and viewing ActionText. Since
|
8
|
-
ActionText only works with Webpacker, you'll have to set up Webpacker for your
|
9
|
-
application. You can optionally set up [Super to use Webpacker](./webpacker.md).
|
10
|
-
|
11
|
-
Once you've set that up, ActionText should be relatively simple. The following
|
12
|
-
command will copy over the necessary JS and CSS into your application:
|
13
|
-
|
14
|
-
```bash
|
15
|
-
bundle exec rails generate super:action_text
|
16
|
-
```
|
17
|
-
|
18
|
-
As an example, let's say we're making admin pages for a blog. We'll keep this
|
19
|
-
example simple and work with a `Post` model with just a `#title` column and
|
20
|
-
a rich text `#content` field.
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
class Post < ApplicationRecord
|
24
|
-
has_rich_text :content
|
25
|
-
end
|
26
|
-
```
|
27
|
-
|
28
|
-
We'll need to configure the `#form_schema` and `#display_schema` methods.
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
class Controls < Super::Controls
|
32
|
-
# ...
|
33
|
-
|
34
|
-
def form_schema(action:)
|
35
|
-
Super::Form.new do |fields, type|
|
36
|
-
fields[:title] = type.text
|
37
|
-
fields[:content] = type.rich_text_area
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def display_schema(action:)
|
42
|
-
Super::Display.new do |fields, type|
|
43
|
-
fields[:title] = type.text
|
44
|
-
fields[:content] = type.rich_text
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
```
|
data/docs/cheat.md
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @title Cheat sheet
|
3
|
-
-->
|
4
|
-
|
5
|
-
# Cheat sheet
|
6
|
-
|
7
|
-
## Controls
|
8
|
-
|
9
|
-
You can configure most of your admin page's behavior by editing Controls.
|
10
|
-
They only work with ActiveRecord models
|
11
|
-
|
12
|
-
Controls have several required and optional methods. Note that all arguments
|
13
|
-
must be defined, even if they are ignored.
|
14
|
-
|
15
|
-
|
16
|
-
### Required methods
|
17
|
-
|
18
|
-
The following are the methods that must be defined in the `Controls` class.
|
19
|
-
|
20
|
-
* **`#model()`**
|
21
|
-
The model that your controller is working with
|
22
|
-
|
23
|
-
|
24
|
-
### Optional methods
|
25
|
-
|
26
|
-
The following are the methods that can be defined in the `Controls` class.
|
27
|
-
|
28
|
-
* **`#title()`**
|
29
|
-
The title to show on the main panel
|
30
|
-
* **`#collection_actions(action:)`**
|
31
|
-
The list of collection-level links
|
32
|
-
* **`#member_actions(action:)`**
|
33
|
-
The list of member-level links and `#show` pages
|
34
|
-
* **`#scope(action:)`**
|
35
|
-
The starting point of the query/relation. Defaults to `#all`
|
36
|
-
* **`#display_schema(action:)`**
|
37
|
-
The display schema definition for the `#index` and `#show` pages
|
38
|
-
* **`#form_schema(action:)`**
|
39
|
-
The form schema definition for the `#new` and `#edit` pages
|
40
|
-
* **`#permitted_params(params, action:)`**
|
41
|
-
The strong parameters definition
|
data/docs/faq.md
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @title FAQ
|
3
|
-
-->
|
4
|
-
|
5
|
-
# FAQ
|
6
|
-
|
7
|
-
## How do I handle authorization?
|
8
|
-
|
9
|
-
Assuming you already have authentication set up, it should only require defining
|
10
|
-
a `Controls#initialize` that accepts an authenticated user. From there, you can
|
11
|
-
customize `Controls#scope` to have the required behavior.
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
class PostsController < AdminController
|
15
|
-
def new_controls
|
16
|
-
Controls.new(current_user)
|
17
|
-
end
|
18
|
-
|
19
|
-
class Controls < Super::Controls
|
20
|
-
def initialize(current_user)
|
21
|
-
@current_user = current_user
|
22
|
-
end
|
23
|
-
|
24
|
-
def model
|
25
|
-
Post
|
26
|
-
end
|
27
|
-
|
28
|
-
def scope(action:)
|
29
|
-
# Example: admins can read and write; others can only read
|
30
|
-
if @current_user.admin?
|
31
|
-
return model.all
|
32
|
-
end
|
33
|
-
|
34
|
-
if action.read?
|
35
|
-
return model.all
|
36
|
-
end
|
37
|
-
|
38
|
-
raise Super::ClientError::Forbidden
|
39
|
-
end
|
40
|
-
|
41
|
-
# ...
|
42
|
-
end
|
43
|
-
end
|
44
|
-
```
|
data/docs/installation.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @title Installation
|
3
|
-
-->
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem "super"
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
```bash
|
16
|
-
bundle install
|
17
|
-
bundle exec rails generate super:install # check out the `--help` option!
|
18
|
-
```
|
19
|
-
|
20
|
-
If you prefer, you can configure Super to use Webpacker instead of Sprockets.
|
21
|
-
Check out the [Webpacker guide](./webpacker.md).
|
data/docs/quick_start.md
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @title Quick start
|
3
|
-
-->
|
4
|
-
|
5
|
-
# Quick start
|
6
|
-
|
7
|
-
See [Installation](./installation.md) for the installation guide.
|
8
|
-
|
9
|
-
|
10
|
-
## Usage
|
11
|
-
|
12
|
-
### Creating new admin pages
|
13
|
-
|
14
|
-
```bash
|
15
|
-
bundle exec rails generate super:resource Thing # check out the `--help` option!
|
16
|
-
```
|
17
|
-
|
18
|
-
The example above will create a controller called `Admin::ThingsController`. It
|
19
|
-
generates a `Controls` class inside the controller as well; it's where most
|
20
|
-
configuration lives. See the documentation on [Controls](./controls.md) for more
|
21
|
-
info.
|
22
|
-
|
23
|
-
You'll have to manually update your routes file. It'll probably look something
|
24
|
-
like the following:
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
namespace :admin do
|
28
|
-
resources :things
|
29
|
-
end
|
30
|
-
```
|
data/docs/webpacker.md
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @title Webpacker
|
3
|
-
-->
|
4
|
-
|
5
|
-
# Installation with Webpacker
|
6
|
-
|
7
|
-
Super supports using Webpacker instead of Sprockets. You'll first need to set up
|
8
|
-
Webpacker to handle ERB templates.
|
9
|
-
|
10
|
-
After installing Super (see the [Installation guide](./installation.md)), run
|
11
|
-
one the following:
|
12
|
-
|
13
|
-
## Webpacker 4 and 5
|
14
|
-
|
15
|
-
```bash
|
16
|
-
bundle exec rails webpacker:install:erb # if you haven't already
|
17
|
-
bundle exec rails generate super:webpacker
|
18
|
-
```
|
19
|
-
|
20
|
-
## Webpacker 6
|
21
|
-
|
22
|
-
```bash
|
23
|
-
yarn add rails-erb-loader # if you haven't already
|
24
|
-
bundle exec rails generate super:webpacker
|
25
|
-
```
|
data/docs/yard_customizations.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yard"
|
4
|
-
|
5
|
-
module FixRelativeLinks
|
6
|
-
def resolve_links(html)
|
7
|
-
html = html.gsub(%r{<a href="([^"]+)">([^<]+)</a>}) do
|
8
|
-
resolve_link_to_docs_subdir(full_match: $&, href: $1, content: $2)
|
9
|
-
end
|
10
|
-
|
11
|
-
html = html.gsub(%r{(<pre[^<]+)?<code[^>]*>([^<]+)</code>}) do
|
12
|
-
resolve_link_to_code(full_match: $&, pre: $1, code: $2)
|
13
|
-
end
|
14
|
-
|
15
|
-
super(html)
|
16
|
-
end
|
17
|
-
|
18
|
-
def resolve_link_to_docs_subdir(full_match:, href:, content:)
|
19
|
-
if href =~ /\bdocs\b/
|
20
|
-
%({file:#{href} #{content}})
|
21
|
-
else
|
22
|
-
full_match
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def resolve_link_to_code(full_match:, pre:, code:)
|
27
|
-
if pre
|
28
|
-
return full_match
|
29
|
-
end
|
30
|
-
|
31
|
-
if code.include?("\n")
|
32
|
-
return full_match
|
33
|
-
end
|
34
|
-
|
35
|
-
if !code.start_with?("Super::")
|
36
|
-
return full_match
|
37
|
-
end
|
38
|
-
|
39
|
-
"{#{code}}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
YARD::Templates::Template.extra_includes << FixRelativeLinks
|
data/lib/super/controls.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "super/controls/optional"
|
4
|
-
require "super/controls/required"
|
5
|
-
require "super/controls/steps"
|
6
|
-
require "super/controls/view"
|
7
|
-
|
8
|
-
module Super
|
9
|
-
# The base Controls class. Most parts of Super can be configured by
|
10
|
-
# customizing its methods.
|
11
|
-
class Controls
|
12
|
-
include Required
|
13
|
-
include Optional
|
14
|
-
include Steps
|
15
|
-
include View
|
16
|
-
end
|
17
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Super
|
4
|
-
class Controls
|
5
|
-
# Methods for `Controls` that have a sane default implementation
|
6
|
-
module Optional
|
7
|
-
# This is an optional method
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
def title
|
11
|
-
model.name.pluralize
|
12
|
-
end
|
13
|
-
|
14
|
-
# Configures what database records are visible on load. This is an optional
|
15
|
-
# method, it defaults to "`all`" methods
|
16
|
-
#
|
17
|
-
# @param action [ActionInquirer]
|
18
|
-
# @return [ActiveRecord::Relation]
|
19
|
-
def scope(action:)
|
20
|
-
model.all
|
21
|
-
end
|
22
|
-
|
23
|
-
# Configures the fields that are displayed on the index and show actions.
|
24
|
-
# This is a required method
|
25
|
-
#
|
26
|
-
# @param action [ActionInquirer]
|
27
|
-
# @return [Display]
|
28
|
-
def display_schema(action:)
|
29
|
-
Display.new do |fields, type|
|
30
|
-
Display::Guesser.new(model: model, action: action, fields: fields, type: type).call
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Configures the editable fields on the new and edit actions. This is a
|
35
|
-
# required method
|
36
|
-
#
|
37
|
-
# @param action [ActionInquirer]
|
38
|
-
# @return [Form]
|
39
|
-
def form_schema(action:)
|
40
|
-
Form.new do |fields, type|
|
41
|
-
Form::Guesser.new(model: model, fields: fields, type: type).call
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Configures which parameters could be written to the database. This is a
|
46
|
-
# required method
|
47
|
-
#
|
48
|
-
# @param params [ActionController::Parameters]
|
49
|
-
# @param action [ActionInquirer]
|
50
|
-
# @return [ActionController::Parameters]
|
51
|
-
def permitted_params(params, action:)
|
52
|
-
strong_params = Super::Form::StrongParams.new(form_schema(action: action))
|
53
|
-
params.require(strong_params.require(model)).permit(strong_params.permit)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Configures the actions linked to on the index page. This is an optional
|
57
|
-
# method
|
58
|
-
#
|
59
|
-
# @param action [ActionInquirer]
|
60
|
-
# @return [Array<Link>]
|
61
|
-
def collection_actions(action:)
|
62
|
-
Super::Link.find_all(:new)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Configures the actions linked to on the show page as well as each row of
|
66
|
-
# the table on the index page. This is an optional method
|
67
|
-
#
|
68
|
-
# @param action [ActionInquirer]
|
69
|
-
# @return [Array<Link>]
|
70
|
-
def member_actions(action:)
|
71
|
-
if action.show?
|
72
|
-
Super::Link.find_all(:edit, :destroy)
|
73
|
-
elsif action.edit?
|
74
|
-
Super::Link.find_all(:show, :destroy)
|
75
|
-
else
|
76
|
-
Super::Link.find_all(:show, :edit, :destroy)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def filters_enabled?
|
81
|
-
true
|
82
|
-
end
|
83
|
-
|
84
|
-
def filter_schema
|
85
|
-
Super::Filter.new do |fields, type|
|
86
|
-
Super::Filter::Guesser.new(model: model, fields: fields, type: type).call
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def sort_enabled?
|
91
|
-
true
|
92
|
-
end
|
93
|
-
|
94
|
-
def sortable_columns
|
95
|
-
action = ActionInquirer.new(
|
96
|
-
ActionInquirer.default_for_resources,
|
97
|
-
"index"
|
98
|
-
)
|
99
|
-
attribute_names =
|
100
|
-
display_schema(action: action).each_attribute.map do |key, val|
|
101
|
-
key if val.real?
|
102
|
-
end
|
103
|
-
|
104
|
-
attribute_names.compact
|
105
|
-
end
|
106
|
-
|
107
|
-
def default_sort
|
108
|
-
{ id: :desc }
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Super
|
4
|
-
class Controls
|
5
|
-
# Methods for `Controls` that must be defined for Super to work properly
|
6
|
-
module Required
|
7
|
-
# Specifies the model. This is a required method
|
8
|
-
#
|
9
|
-
# @return [ActiveRecord::Base]
|
10
|
-
def model
|
11
|
-
raise NotImplementedError
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|