active_element 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -2
- data/.strong_versions.yml +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +115 -75
- data/Makefile +10 -0
- data/active_element.gemspec +1 -1
- data/app/assets/javascripts/active_element/application.js +1 -0
- data/app/assets/javascripts/active_element/form.js +16 -32
- data/app/assets/javascripts/active_element/json_field.js +391 -135
- data/app/assets/javascripts/active_element/setup.js +13 -8
- data/app/assets/javascripts/active_element/text_search_field.js +38 -27
- data/app/assets/javascripts/active_element/theme.js +1 -1
- data/app/assets/javascripts/active_element/timezones.js +6 -0
- data/app/assets/stylesheets/active_element/_dark.scss +86 -0
- data/app/assets/stylesheets/active_element/_variables.scss +2 -1
- data/app/assets/stylesheets/active_element/application.scss +166 -33
- data/app/controllers/active_element/application_controller.rb +5 -0
- data/app/controllers/concerns/active_element/default_controller_actions.rb +38 -0
- data/app/views/active_element/_user.html.erb +20 -0
- data/app/views/active_element/components/fields/_json.html.erb +24 -0
- data/app/views/active_element/components/form/_check_box.html.erb +1 -0
- data/app/views/active_element/components/form/_check_boxes.html.erb +1 -1
- data/app/views/active_element/components/form/_datetime_range_field.html.erb +14 -0
- data/app/views/active_element/components/form/_field.html.erb +10 -7
- data/app/views/active_element/components/form/_generic_field.html.erb +1 -0
- data/app/views/active_element/components/form/_json.html.erb +10 -2
- data/app/views/active_element/components/form/_label.html.erb +12 -1
- data/app/views/active_element/components/form/_select.html.erb +4 -1
- data/app/views/active_element/components/form/_summary.html.erb +11 -1
- data/app/views/active_element/components/form/_templates.html.erb +42 -24
- data/app/views/active_element/components/form/_text_area.html.erb +2 -1
- data/app/views/active_element/components/form/_text_search.html.erb +8 -4
- data/app/views/active_element/components/form.html.erb +20 -17
- data/app/views/active_element/components/json.html.erb +1 -0
- data/app/views/active_element/components/navbar.html.erb +26 -0
- data/app/views/active_element/components/table/_collection_row.html.erb +2 -1
- data/app/views/active_element/components/table/_field.html.erb +8 -0
- data/app/views/active_element/components/table/_ungrouped_collection.html.erb +1 -0
- data/app/views/active_element/components/table/collection.html.erb +1 -1
- data/app/views/active_element/components/table/item.html.erb +6 -4
- data/app/views/active_element/default_views/edit.html.erb +5 -0
- data/app/views/active_element/default_views/forbidden.html.erb +7 -0
- data/app/views/active_element/default_views/index.html.erb +15 -0
- data/app/views/active_element/default_views/new.html.erb +4 -0
- data/app/views/active_element/default_views/show.html.erb +7 -0
- data/app/views/active_element/navbar/_menu.html.erb +1 -30
- data/app/views/active_element/theme/_select.html.erb +1 -1
- data/app/views/layouts/active_element.html.erb +16 -1
- data/config/brakeman.ignore +48 -0
- data/config/locales/en.yml +3 -0
- data/example_app/.gitattributes +7 -0
- data/example_app/.gitignore +35 -0
- data/example_app/.ruby-version +1 -0
- data/example_app/Gemfile +34 -0
- data/example_app/Gemfile.lock +296 -0
- data/example_app/README.md +24 -0
- data/example_app/Rakefile +6 -0
- data/example_app/app/assets/config/manifest.js +4 -0
- data/example_app/app/assets/images/.keep +0 -0
- data/example_app/app/assets/stylesheets/application.css +15 -0
- data/example_app/app/channels/application_cable/channel.rb +4 -0
- data/example_app/app/channels/application_cable/connection.rb +4 -0
- data/example_app/app/controllers/application_controller.rb +12 -0
- data/example_app/app/controllers/concerns/.keep +0 -0
- data/example_app/app/controllers/pets_controller.rb +7 -0
- data/example_app/app/controllers/users_controller.rb +7 -0
- data/example_app/app/helpers/application_helper.rb +2 -0
- data/example_app/app/javascript/application.js +3 -0
- data/example_app/app/javascript/controllers/application.js +9 -0
- data/example_app/app/javascript/controllers/hello_controller.js +7 -0
- data/example_app/app/javascript/controllers/index.js +11 -0
- data/example_app/app/jobs/application_job.rb +7 -0
- data/example_app/app/mailers/application_mailer.rb +4 -0
- data/example_app/app/models/application_record.rb +3 -0
- data/example_app/app/models/concerns/.keep +0 -0
- data/example_app/app/models/pet.rb +3 -0
- data/example_app/app/models/user.rb +8 -0
- data/example_app/app/views/layouts/application.html.erb +16 -0
- data/example_app/app/views/layouts/mailer.html.erb +13 -0
- data/example_app/app/views/layouts/mailer.text.erb +1 -0
- data/example_app/app/views/pets/index.html.erb +3 -0
- data/example_app/app/views/users/show.html.erb +3 -0
- data/example_app/bin/bundle +109 -0
- data/example_app/bin/importmap +4 -0
- data/example_app/bin/rails +4 -0
- data/example_app/bin/rake +4 -0
- data/example_app/bin/setup +33 -0
- data/example_app/config/application.rb +22 -0
- data/example_app/config/boot.rb +4 -0
- data/example_app/config/cable.yml +10 -0
- data/example_app/config/credentials.yml.enc +1 -0
- data/example_app/config/database.yml +25 -0
- data/example_app/config/environment.rb +5 -0
- data/example_app/config/environments/development.rb +70 -0
- data/example_app/config/environments/production.rb +93 -0
- data/example_app/config/environments/test.rb +60 -0
- data/example_app/config/importmap.rb +7 -0
- data/example_app/config/initializers/assets.rb +12 -0
- data/example_app/config/initializers/content_security_policy.rb +25 -0
- data/example_app/config/initializers/devise.rb +16 -0
- data/example_app/config/initializers/filter_parameter_logging.rb +8 -0
- data/example_app/config/initializers/inflections.rb +16 -0
- data/example_app/config/initializers/permissions_policy.rb +11 -0
- data/example_app/config/locales/devise.en.yml +65 -0
- data/example_app/config/locales/en.yml +33 -0
- data/example_app/config/puma.rb +43 -0
- data/example_app/config/routes.rb +8 -0
- data/example_app/config/storage.yml +34 -0
- data/example_app/config.ru +6 -0
- data/example_app/db/migrate/20230616210539_create_pet.rb +12 -0
- data/example_app/db/migrate/20230616211328_devise_create_users.rb +46 -0
- data/example_app/db/schema.rb +37 -0
- data/example_app/db/seeds.rb +33 -0
- data/example_app/lib/assets/.keep +0 -0
- data/example_app/lib/tasks/.keep +0 -0
- data/example_app/log/.keep +0 -0
- data/example_app/public/404.html +67 -0
- data/example_app/public/422.html +67 -0
- data/example_app/public/500.html +66 -0
- data/example_app/public/apple-touch-icon-precomposed.png +0 -0
- data/example_app/public/apple-touch-icon.png +0 -0
- data/example_app/public/favicon.ico +0 -0
- data/example_app/public/robots.txt +1 -0
- data/example_app/storage/.keep +0 -0
- data/example_app/test/application_system_test_case.rb +5 -0
- data/example_app/test/channels/application_cable/connection_test.rb +11 -0
- data/example_app/test/controllers/.keep +0 -0
- data/example_app/test/fixtures/files/.keep +0 -0
- data/example_app/test/fixtures/users.yml +11 -0
- data/example_app/test/helpers/.keep +0 -0
- data/example_app/test/integration/.keep +0 -0
- data/example_app/test/mailers/.keep +0 -0
- data/example_app/test/models/.keep +0 -0
- data/example_app/test/models/user_test.rb +7 -0
- data/example_app/test/system/.keep +0 -0
- data/example_app/test/test_helper.rb +13 -0
- data/example_app/tmp/.keep +0 -0
- data/example_app/tmp/pids/.keep +0 -0
- data/example_app/tmp/storage/.keep +0 -0
- data/example_app/vendor/.keep +0 -0
- data/example_app/vendor/javascript/.keep +0 -0
- data/lib/active_element/component.rb +9 -2
- data/lib/active_element/components/collection_table.rb +9 -2
- data/lib/active_element/components/email_fields.rb +14 -0
- data/lib/active_element/components/form.rb +48 -17
- data/lib/active_element/components/navbar.rb +64 -0
- data/lib/active_element/components/phone_fields.rb +14 -0
- data/lib/active_element/components/text_search/authorization.rb +9 -6
- data/lib/active_element/components/text_search/component.rb +4 -2
- data/lib/active_element/components/text_search.rb +13 -0
- data/lib/active_element/components/util/association_mapping.rb +74 -19
- data/lib/active_element/components/util/display_value_mapping.rb +13 -4
- data/lib/active_element/components/util/form_field_mapping.rb +139 -10
- data/lib/active_element/components/util/form_value_mapping.rb +3 -3
- data/lib/active_element/components/util/i18n.rb +1 -1
- data/lib/active_element/components/util/numeric_field.rb +73 -0
- data/lib/active_element/components/util/record_mapping.rb +43 -11
- data/lib/active_element/components/util/record_path.rb +21 -4
- data/lib/active_element/components/util.rb +13 -5
- data/lib/active_element/components.rb +3 -0
- data/lib/active_element/controller_action.rb +8 -2
- data/lib/active_element/controller_interface.rb +56 -18
- data/lib/active_element/controller_state.rb +44 -0
- data/lib/active_element/default_controller.rb +137 -0
- data/lib/active_element/default_record_params.rb +62 -0
- data/lib/active_element/default_search.rb +110 -0
- data/lib/active_element/json_field_schema.rb +59 -0
- data/lib/active_element/pre_render_processors/json.rb +98 -0
- data/lib/active_element/pre_render_processors.rb +11 -0
- data/lib/active_element/route.rb +12 -0
- data/lib/active_element/routes.rb +2 -1
- data/lib/active_element/version.rb +1 -1
- data/lib/active_element.rb +15 -32
- data/lib/tasks/active_element.rake +12 -1
- data/rspec-documentation/_head.html.erb +34 -0
- data/rspec-documentation/pages/000-Introduction.md +18 -0
- data/rspec-documentation/pages/005-Setup.md +75 -0
- data/rspec-documentation/pages/010-Components/Form Fields/Check Boxes.md +1 -0
- data/rspec-documentation/pages/010-Components/Form Fields/JSON/Controller Params.md +97 -0
- data/rspec-documentation/pages/010-Components/Form Fields/JSON/Schema.md +283 -0
- data/rspec-documentation/pages/010-Components/Form Fields/JSON/Types.md +36 -0
- data/rspec-documentation/pages/010-Components/Form Fields/JSON.md +70 -0
- data/rspec-documentation/pages/010-Components/Form Fields/Text Search.md +133 -0
- data/rspec-documentation/pages/010-Components/Form Fields.md +46 -0
- data/rspec-documentation/pages/010-Components/Forms.md +44 -0
- data/rspec-documentation/pages/010-Components/JSON Data.md +23 -0
- data/rspec-documentation/pages/010-Components/Navbar.md +56 -0
- data/rspec-documentation/pages/010-Components/Page Section Title.md +13 -0
- data/rspec-documentation/pages/010-Components/Page Subtitle.md +11 -0
- data/rspec-documentation/pages/010-Components/Page Title.md +11 -0
- data/rspec-documentation/pages/010-Components/Tables/Collection Table.md +29 -0
- data/rspec-documentation/pages/010-Components/Tables/Item Table.md +18 -0
- data/rspec-documentation/pages/010-Components/Tables/Options.md +19 -0
- data/rspec-documentation/pages/010-Components/Tables.md +29 -0
- data/rspec-documentation/pages/010-Components.md +15 -0
- data/rspec-documentation/pages/020-Access Control/010-Authentication.md +20 -0
- data/rspec-documentation/pages/020-Access Control/020-Authorization/Environments.md +9 -0
- data/rspec-documentation/pages/020-Access Control/020-Authorization/Permissions/Custom Routes.md +41 -0
- data/rspec-documentation/pages/020-Access Control/020-Authorization/Permissions.md +58 -0
- data/rspec-documentation/pages/020-Access Control/020-Authorization/Setup.md +27 -0
- data/rspec-documentation/pages/020-Access Control/020-Authorization.md +11 -0
- data/rspec-documentation/pages/020-Access Control.md +31 -0
- data/rspec-documentation/pages/040-Decorators/Inline Decorators.md +24 -0
- data/rspec-documentation/pages/040-Decorators/View Decorators.md +55 -0
- data/rspec-documentation/pages/040-Decorators.md +12 -0
- data/rspec-documentation/pages/300-Alternatives.md +21 -0
- data/rspec-documentation/pages/900-License.md +11 -0
- data/rspec-documentation/spec_helper.rb +53 -16
- data/rspec-documentation/support.rb +84 -0
- metadata +159 -14
- data/rspec-documentation/pages/Components/Forms.md +0 -1
- data/rspec-documentation/pages/Components/Tables.md +0 -47
- data/rspec-documentation/pages/Components.md +0 -1
- data/rspec-documentation/pages/Decorators/Inline Decorators.md +0 -1
- data/rspec-documentation/pages/Decorators/View Decorators.md +0 -1
- data/rspec-documentation/pages/Index.md +0 -3
- data/rspec-documentation/pages/Util/I18n.md +0 -1
- /data/rspec-documentation/pages/{Components → 010-Components}/Tabs.md +0 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# Access Control
|
2
|
+
|
3
|
+
_ActiveElement_ provides a comprehensive authorization model for restricting access to all parts of your application based on a simple permissions system.
|
4
|
+
|
5
|
+
_ActiveElement_ does not enforce any particular authentication framework and works out of the box with [Devise](https://github.com/heartcombo/devise).
|
6
|
+
|
7
|
+
There are no restrictions on how you choose to implement your application's authentication system, but if you wish to use _ActiveElement's_ authorization model the following two methods must be defined:
|
8
|
+
|
9
|
+
* An authenticator that will render or redirect on authentication failure, e.g. _Devise's_ `authenticate_user!`.
|
10
|
+
* A user accessor that provides a user object, e.g. _Devise's_ `current_user`. The user object must respond to a `#permissions` method which returns an array of strings such as `['can_list_users']`.
|
11
|
+
|
12
|
+
A typical setup would look like this:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# app/controllers/application_controller.rb
|
16
|
+
|
17
|
+
class ApplicationController < ActionController::Base
|
18
|
+
prepend_before_action :configure_authentication
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def configure_authentication
|
23
|
+
active_element.authenticate_with { authenticate_user! }
|
24
|
+
active_element.authorize_with { current_user }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
_ActiveElement_ does not require authentication/authorization to be implemented and works either without any authentication at all or with your own custom authentication stack.
|
30
|
+
|
31
|
+
See the [Authentication](access-control/authentication.html) and [Authorization](access-control/authorization.html) for more details on the benefits of using the provided authorization features.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Inline Decorators
|
2
|
+
|
3
|
+
In most use cases it is recommended to use [View Decorators](view-decorators.html) to render custom data to provide reusable and composable view fragments without polluting component definitions with custom logic.
|
4
|
+
|
5
|
+
However, if you need a simple one-off data transformation when using a [Table](../components/tables.html), you can specify a `Proc` within the table `fields` definition by using the secondary form of passing an `Array` of `[Symbol, Hash]` instead of just a `Symbol` for any given field.
|
6
|
+
|
7
|
+
The `Proc` will receive the current record (i.e. the object for the current row of a `collection` with a [Collection Table](../components/tables/collection-table.html) or the `item` with an [Item Table](components/tables/item-table.html)).
|
8
|
+
|
9
|
+
```rspec:html
|
10
|
+
collection = [
|
11
|
+
User.new(name: 'John Smith', email: 'john@example.com'),
|
12
|
+
User.new(name: 'Sally Anderson', email: 'sally@example.org')
|
13
|
+
]
|
14
|
+
subject do
|
15
|
+
active_element.component.table collection: collection,
|
16
|
+
fields: [
|
17
|
+
:email,
|
18
|
+
[:name, { mapper: ->(record) { record.name.upcase } }]
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
it { is_expected.to include 'JOHN SMITH' }
|
23
|
+
it { is_expected.to include 'SALLY ANDERSON' }
|
24
|
+
```
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# View Decorators
|
2
|
+
|
3
|
+
_View Decorators_ are _Rails_ view partials that are discovered by a conventional file path based on the model name and attribute being accessed. The partial has access to the current record, the default value, as well as all other objects typically available in _Rails_ views.
|
4
|
+
|
5
|
+
The following methods are available in a decorator's render context on top of the typical _Rails_ view context:
|
6
|
+
|
7
|
+
|Name|Description|
|
8
|
+
|-|-|
|
9
|
+
| `default` | The original, unmodified value returned directly from the model.
|
10
|
+
| `record` | The full model instance. i.e. `default` is shorthand for (e.g.) `record.name`, `record.email`, etc. depending on the given decorator definition.
|
11
|
+
|
12
|
+
To create a decorator for a `User` object's `name` attribute, create a file named `app/views/decorators/users/_name.html.erb`.
|
13
|
+
|
14
|
+
```erb
|
15
|
+
<%# app/views/decorators/users/_name.html.erb %>
|
16
|
+
|
17
|
+
<span class="name">
|
18
|
+
<%= default %>
|
19
|
+
</span>
|
20
|
+
|
21
|
+
<% if record.created_at.present? %>
|
22
|
+
<span class="created-at">
|
23
|
+
(Created: <%= time_ago_in_words(record.created_at) %> ago)
|
24
|
+
</span>
|
25
|
+
<% end %>
|
26
|
+
```
|
27
|
+
|
28
|
+
Here's an example of that exact decorator being applied to a `User` instance in an [Item Table](../../components/tables/item-table.html):
|
29
|
+
|
30
|
+
```rspec:html
|
31
|
+
user = User.create!(email: 'user@example.com', name: 'John Smith', created_at: 5.days.ago)
|
32
|
+
|
33
|
+
subject do
|
34
|
+
active_element.component.table item: user,
|
35
|
+
fields: [:email, :name]
|
36
|
+
end
|
37
|
+
|
38
|
+
it { is_expected.to include '5 days ago' }
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contexts
|
42
|
+
|
43
|
+
Since _View Decorators_ are applied every time a value is displayed (note that [Forms](../../components/forms.html) always use the raw value, never the decorated value), you may need to display a value differently depending on the context. For example, you may want to display the default value in an `index` view, and you may want a customized display value in a `show` view.
|
44
|
+
|
45
|
+
If this is required, simply use an `if` statement and inspect _Rails'_ provided `controller_action` method:
|
46
|
+
|
47
|
+
```erb
|
48
|
+
<%# app/views/decorators/users/_email.html.erb %>
|
49
|
+
|
50
|
+
<% if controller_action == 'index' %>
|
51
|
+
<%= default %>
|
52
|
+
<% else %>
|
53
|
+
<%= mail_to default %>
|
54
|
+
<% end %>
|
55
|
+
```
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Decorators
|
2
|
+
|
3
|
+
_ActiveElement_ decorators provide a way to override the default display value for your data fields.
|
4
|
+
|
5
|
+
For example, you may want to display an icon or an image instead of the raw value from the database, or you may want to do custom formatting if the default formatters don't suit your requirements.
|
6
|
+
|
7
|
+
Decorators are implemented in two ways:
|
8
|
+
|
9
|
+
* _Rails_ view partials as [View Decorators](decorators/view-decorators.html).
|
10
|
+
* Inline `Proc` data mappers as [Inline Decorators](decorators/inline-decorators.html).
|
11
|
+
|
12
|
+
It is recommended to use _View Decorators_ instead of _Inline Decorators_ but documentation is provided for both to allow developers to make an informed decision on which solution to choose.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Alternatives
|
2
|
+
|
3
|
+
You may prefer to use some of the following either instead of or in conjunction with _ActiveElement_, depending on your requirements:
|
4
|
+
|
5
|
+
## Administration Frameworks
|
6
|
+
|
7
|
+
* [Administrate](https://github.com/thoughtbot/administrate) by [thoughtbot](https://thoughtbot.com)
|
8
|
+
* [ActiveAdmin](https://activeadmin.info)
|
9
|
+
|
10
|
+
## Form Generation
|
11
|
+
|
12
|
+
* [SimpleForm](https://github.com/heartcombo/simple_form) by [heartcombo](https://github.com/heartcombo)
|
13
|
+
|
14
|
+
## Model Decorators
|
15
|
+
|
16
|
+
* [Draper](https://github.com/drapergem/draper)
|
17
|
+
|
18
|
+
## Authorization
|
19
|
+
|
20
|
+
* [CanCanCan](https://github.com/CanCanCommunity/cancancan)
|
21
|
+
* [Pundit](https://github.com/varvet/pundit) by [VARVET](https://www.varvet.com)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# License
|
2
|
+
|
3
|
+
## MIT
|
4
|
+
|
5
|
+
Copyright 2023 Robert Farrell
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,11 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_element'
|
2
4
|
require_relative 'dummy/config/environment'
|
5
|
+
require_relative 'support'
|
6
|
+
|
7
|
+
RSpec::Documentation.configure do |config| # rubocop:disable Metrics/BlockLength
|
8
|
+
active_element = Struct.new(:component).new(ActiveElement::Component.new(UsersController.new))
|
9
|
+
application_css = Rails.application
|
10
|
+
.assets
|
11
|
+
.find_asset('active_element/application.css')
|
12
|
+
.source.split("\n")
|
13
|
+
.drop_while { |line| line.exclude?('app/assets/stylesheets/active_element') }
|
14
|
+
.join("\n")
|
15
|
+
text_search_names = 1000.times.map do
|
16
|
+
first_name = Faker::Name.first_name
|
17
|
+
last_name = Faker::Name.last_name
|
18
|
+
{
|
19
|
+
value: rand(1000),
|
20
|
+
attributes: [
|
21
|
+
"#{first_name}.#{last_name}@#{Faker::Internet.domain_name}".downcase,
|
22
|
+
"#{first_name} #{Faker::Name.middle_name} #{last_name}".downcase
|
23
|
+
]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
before_content = [
|
28
|
+
ERB.new(File.read('app/views/active_element/components/form/_templates.html.erb')).result(binding),
|
29
|
+
ERB.new(File.read('rspec-documentation/_head.html.erb')).result(binding)
|
30
|
+
].join("\n")
|
31
|
+
|
32
|
+
config.hook(:before_content) { before_content }
|
3
33
|
|
4
|
-
RSpec::Documentation.configure do |config|
|
5
34
|
ActiveRecord::Migration.class_eval do
|
6
35
|
drop_table :users
|
7
|
-
|
8
|
-
|
36
|
+
drop_table :pets
|
37
|
+
rescue ActiveRecord::StatementInvalid => e
|
38
|
+
warn e.message
|
9
39
|
end
|
10
40
|
|
11
41
|
ActiveRecord::Migration.class_eval do
|
@@ -13,23 +43,30 @@ RSpec::Documentation.configure do |config|
|
|
13
43
|
t.string :name
|
14
44
|
t.string :email
|
15
45
|
t.text :overview
|
46
|
+
t.boolean :enabled
|
47
|
+
t.date :date_of_birth
|
48
|
+
t.datetime :created_at
|
49
|
+
t.json :pets
|
50
|
+
t.json :nicknames
|
51
|
+
t.json :permissions
|
52
|
+
t.json :family
|
53
|
+
t.json :extended_family
|
54
|
+
t.json :user_data
|
55
|
+
t.string :encrypted_password
|
16
56
|
end
|
17
57
|
end
|
18
58
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
def params
|
29
|
-
{}
|
30
|
-
end
|
59
|
+
ActiveRecord::Migration.class_eval do
|
60
|
+
create_table :pets do |t|
|
61
|
+
t.string :name
|
62
|
+
t.string :animal
|
63
|
+
t.integer :user_id
|
31
64
|
end
|
65
|
+
end
|
32
66
|
|
33
|
-
|
67
|
+
config.context do
|
68
|
+
let(:active_element) do
|
69
|
+
double(component: ActiveElement::Component.new(UsersController.new))
|
70
|
+
end
|
34
71
|
end
|
35
72
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Controller used in various examples.
|
4
|
+
class UsersController < ActiveElement::ApplicationController
|
5
|
+
def initialize(*args, &block)
|
6
|
+
append_view_path File.expand_path(File.join(__dir__, '../app/views/'))
|
7
|
+
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
{}
|
13
|
+
end
|
14
|
+
|
15
|
+
def helpers
|
16
|
+
@helpers ||= Helpers.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def request
|
20
|
+
@_request = Session.new
|
21
|
+
@request ||= Request.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Stand-in for Rails controller helpers.
|
26
|
+
class Helpers
|
27
|
+
def pet_path(record = nil)
|
28
|
+
"/pet/#{record&.id}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def user_path(record = nil)
|
32
|
+
"/user/#{record&.id}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def edit_user_path(record)
|
36
|
+
"/user/#{record.id}/edit"
|
37
|
+
end
|
38
|
+
|
39
|
+
def new_user_path(*_args)
|
40
|
+
'/users/new'
|
41
|
+
end
|
42
|
+
|
43
|
+
def render(*args)
|
44
|
+
ActionController::Base.new.render_to_string(*args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Stand-in for a Rails Request.
|
49
|
+
class Request
|
50
|
+
def path
|
51
|
+
'/users/new'
|
52
|
+
end
|
53
|
+
|
54
|
+
def host
|
55
|
+
'www.example.com'
|
56
|
+
end
|
57
|
+
|
58
|
+
def optional_port
|
59
|
+
80
|
60
|
+
end
|
61
|
+
|
62
|
+
def protocol
|
63
|
+
'http'
|
64
|
+
end
|
65
|
+
|
66
|
+
def path_parameters
|
67
|
+
{}
|
68
|
+
end
|
69
|
+
|
70
|
+
def method_missing(*)
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def respond_to_missing?(*)
|
75
|
+
true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Stand-in for a Rails Session.
|
80
|
+
class Session
|
81
|
+
def session
|
82
|
+
{}
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_element
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '6.
|
61
|
+
version: '6.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '6.
|
68
|
+
version: '6.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rouge
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,17 +123,23 @@ files:
|
|
123
123
|
- app/assets/javascripts/active_element/setup.js
|
124
124
|
- app/assets/javascripts/active_element/text_search_field.js
|
125
125
|
- app/assets/javascripts/active_element/theme.js
|
126
|
+
- app/assets/javascripts/active_element/timezones.js
|
126
127
|
- app/assets/javascripts/active_element/toast.js
|
128
|
+
- app/assets/stylesheets/active_element/_dark.scss
|
127
129
|
- app/assets/stylesheets/active_element/_variables.scss
|
128
130
|
- app/assets/stylesheets/active_element/application.scss
|
129
131
|
- app/controllers/active_element/application_controller.rb
|
132
|
+
- app/controllers/concerns/active_element/default_controller_actions.rb
|
133
|
+
- app/views/active_element/_user.html.erb
|
130
134
|
- app/views/active_element/components/_horizontal_tabs.html.erb
|
131
135
|
- app/views/active_element/components/_vertical_tabs.html.erb
|
132
136
|
- app/views/active_element/components/button.html.erb
|
133
137
|
- app/views/active_element/components/fields/_boolean.html.erb
|
138
|
+
- app/views/active_element/components/fields/_json.html.erb
|
134
139
|
- app/views/active_element/components/form.html.erb
|
135
140
|
- app/views/active_element/components/form/_check_box.html.erb
|
136
141
|
- app/views/active_element/components/form/_check_boxes.html.erb
|
142
|
+
- app/views/active_element/components/form/_datetime_range_field.html.erb
|
137
143
|
- app/views/active_element/components/form/_field.html.erb
|
138
144
|
- app/views/active_element/components/form/_generic_field.html.erb
|
139
145
|
- app/views/active_element/components/form/_json.html.erb
|
@@ -145,10 +151,12 @@ files:
|
|
145
151
|
- app/views/active_element/components/form/_text_area.html.erb
|
146
152
|
- app/views/active_element/components/form/_text_search.html.erb
|
147
153
|
- app/views/active_element/components/json.html.erb
|
154
|
+
- app/views/active_element/components/navbar.html.erb
|
148
155
|
- app/views/active_element/components/page_description.html.erb
|
149
156
|
- app/views/active_element/components/secret/_field.html.erb
|
150
157
|
- app/views/active_element/components/secret/_templates.html.erb
|
151
158
|
- app/views/active_element/components/table/_collection_row.html.erb
|
159
|
+
- app/views/active_element/components/table/_field.html.erb
|
152
160
|
- app/views/active_element/components/table/_grouped_collection.html.erb
|
153
161
|
- app/views/active_element/components/table/_pagination.html.erb
|
154
162
|
- app/views/active_element/components/table/_ungrouped_collection.html.erb
|
@@ -159,6 +167,11 @@ files:
|
|
159
167
|
- app/views/active_element/decorators/_date.html.erb
|
160
168
|
- app/views/active_element/decorators/_datetime.html.erb
|
161
169
|
- app/views/active_element/decorators/_time.html.erb
|
170
|
+
- app/views/active_element/default_views/edit.html.erb
|
171
|
+
- app/views/active_element/default_views/forbidden.html.erb
|
172
|
+
- app/views/active_element/default_views/index.html.erb
|
173
|
+
- app/views/active_element/default_views/new.html.erb
|
174
|
+
- app/views/active_element/default_views/show.html.erb
|
162
175
|
- app/views/active_element/forbidden.html.erb
|
163
176
|
- app/views/active_element/main_menu/_item.html.erb
|
164
177
|
- app/views/active_element/navbar/_menu.html.erb
|
@@ -173,18 +186,114 @@ files:
|
|
173
186
|
- app/views/kaminari/_prev_page.html.erb
|
174
187
|
- app/views/layouts/active_element.html.erb
|
175
188
|
- app/views/layouts/active_element_error.html.erb
|
189
|
+
- config/brakeman.ignore
|
190
|
+
- config/locales/en.yml
|
176
191
|
- config/routes.rb
|
192
|
+
- example_app/.gitattributes
|
193
|
+
- example_app/.gitignore
|
194
|
+
- example_app/.ruby-version
|
195
|
+
- example_app/Gemfile
|
196
|
+
- example_app/Gemfile.lock
|
197
|
+
- example_app/README.md
|
198
|
+
- example_app/Rakefile
|
199
|
+
- example_app/app/assets/config/manifest.js
|
200
|
+
- example_app/app/assets/images/.keep
|
201
|
+
- example_app/app/assets/stylesheets/application.css
|
202
|
+
- example_app/app/channels/application_cable/channel.rb
|
203
|
+
- example_app/app/channels/application_cable/connection.rb
|
204
|
+
- example_app/app/controllers/application_controller.rb
|
205
|
+
- example_app/app/controllers/concerns/.keep
|
206
|
+
- example_app/app/controllers/pets_controller.rb
|
207
|
+
- example_app/app/controllers/users_controller.rb
|
208
|
+
- example_app/app/helpers/application_helper.rb
|
209
|
+
- example_app/app/javascript/application.js
|
210
|
+
- example_app/app/javascript/controllers/application.js
|
211
|
+
- example_app/app/javascript/controllers/hello_controller.js
|
212
|
+
- example_app/app/javascript/controllers/index.js
|
213
|
+
- example_app/app/jobs/application_job.rb
|
214
|
+
- example_app/app/mailers/application_mailer.rb
|
215
|
+
- example_app/app/models/application_record.rb
|
216
|
+
- example_app/app/models/concerns/.keep
|
217
|
+
- example_app/app/models/pet.rb
|
218
|
+
- example_app/app/models/user.rb
|
219
|
+
- example_app/app/views/layouts/application.html.erb
|
220
|
+
- example_app/app/views/layouts/mailer.html.erb
|
221
|
+
- example_app/app/views/layouts/mailer.text.erb
|
222
|
+
- example_app/app/views/pets/index.html.erb
|
223
|
+
- example_app/app/views/users/show.html.erb
|
224
|
+
- example_app/bin/bundle
|
225
|
+
- example_app/bin/importmap
|
226
|
+
- example_app/bin/rails
|
227
|
+
- example_app/bin/rake
|
228
|
+
- example_app/bin/setup
|
229
|
+
- example_app/config.ru
|
230
|
+
- example_app/config/application.rb
|
231
|
+
- example_app/config/boot.rb
|
232
|
+
- example_app/config/cable.yml
|
233
|
+
- example_app/config/credentials.yml.enc
|
234
|
+
- example_app/config/database.yml
|
235
|
+
- example_app/config/environment.rb
|
236
|
+
- example_app/config/environments/development.rb
|
237
|
+
- example_app/config/environments/production.rb
|
238
|
+
- example_app/config/environments/test.rb
|
239
|
+
- example_app/config/importmap.rb
|
240
|
+
- example_app/config/initializers/assets.rb
|
241
|
+
- example_app/config/initializers/content_security_policy.rb
|
242
|
+
- example_app/config/initializers/devise.rb
|
243
|
+
- example_app/config/initializers/filter_parameter_logging.rb
|
244
|
+
- example_app/config/initializers/inflections.rb
|
245
|
+
- example_app/config/initializers/permissions_policy.rb
|
246
|
+
- example_app/config/locales/devise.en.yml
|
247
|
+
- example_app/config/locales/en.yml
|
248
|
+
- example_app/config/puma.rb
|
249
|
+
- example_app/config/routes.rb
|
250
|
+
- example_app/config/storage.yml
|
251
|
+
- example_app/db/migrate/20230616210539_create_pet.rb
|
252
|
+
- example_app/db/migrate/20230616211328_devise_create_users.rb
|
253
|
+
- example_app/db/schema.rb
|
254
|
+
- example_app/db/seeds.rb
|
255
|
+
- example_app/lib/assets/.keep
|
256
|
+
- example_app/lib/tasks/.keep
|
257
|
+
- example_app/log/.keep
|
258
|
+
- example_app/public/404.html
|
259
|
+
- example_app/public/422.html
|
260
|
+
- example_app/public/500.html
|
261
|
+
- example_app/public/apple-touch-icon-precomposed.png
|
262
|
+
- example_app/public/apple-touch-icon.png
|
263
|
+
- example_app/public/favicon.ico
|
264
|
+
- example_app/public/robots.txt
|
265
|
+
- example_app/storage/.keep
|
266
|
+
- example_app/test/application_system_test_case.rb
|
267
|
+
- example_app/test/channels/application_cable/connection_test.rb
|
268
|
+
- example_app/test/controllers/.keep
|
269
|
+
- example_app/test/fixtures/files/.keep
|
270
|
+
- example_app/test/fixtures/users.yml
|
271
|
+
- example_app/test/helpers/.keep
|
272
|
+
- example_app/test/integration/.keep
|
273
|
+
- example_app/test/mailers/.keep
|
274
|
+
- example_app/test/models/.keep
|
275
|
+
- example_app/test/models/user_test.rb
|
276
|
+
- example_app/test/system/.keep
|
277
|
+
- example_app/test/test_helper.rb
|
278
|
+
- example_app/tmp/.keep
|
279
|
+
- example_app/tmp/pids/.keep
|
280
|
+
- example_app/tmp/storage/.keep
|
281
|
+
- example_app/vendor/.keep
|
282
|
+
- example_app/vendor/javascript/.keep
|
177
283
|
- lib/active_element.rb
|
178
284
|
- lib/active_element/active_menu_link.rb
|
179
285
|
- lib/active_element/component.rb
|
180
286
|
- lib/active_element/components.rb
|
181
287
|
- lib/active_element/components/button.rb
|
182
288
|
- lib/active_element/components/collection_table.rb
|
289
|
+
- lib/active_element/components/email_fields.rb
|
183
290
|
- lib/active_element/components/form.rb
|
184
291
|
- lib/active_element/components/item_table.rb
|
185
292
|
- lib/active_element/components/json.rb
|
186
293
|
- lib/active_element/components/link_helpers.rb
|
294
|
+
- lib/active_element/components/navbar.rb
|
187
295
|
- lib/active_element/components/page_description.rb
|
296
|
+
- lib/active_element/components/phone_fields.rb
|
188
297
|
- lib/active_element/components/secret_fields.rb
|
189
298
|
- lib/active_element/components/tab.rb
|
190
299
|
- lib/active_element/components/tabs.rb
|
@@ -202,28 +311,64 @@ files:
|
|
202
311
|
- lib/active_element/components/util/form_field_mapping.rb
|
203
312
|
- lib/active_element/components/util/form_value_mapping.rb
|
204
313
|
- lib/active_element/components/util/i18n.rb
|
314
|
+
- lib/active_element/components/util/numeric_field.rb
|
205
315
|
- lib/active_element/components/util/record_mapping.rb
|
206
316
|
- lib/active_element/components/util/record_path.rb
|
207
317
|
- lib/active_element/controller_action.rb
|
208
318
|
- lib/active_element/controller_interface.rb
|
319
|
+
- lib/active_element/controller_state.rb
|
320
|
+
- lib/active_element/default_controller.rb
|
321
|
+
- lib/active_element/default_record_params.rb
|
322
|
+
- lib/active_element/default_search.rb
|
209
323
|
- lib/active_element/engine.rb
|
324
|
+
- lib/active_element/json_field_schema.rb
|
210
325
|
- lib/active_element/permissions_check.rb
|
211
326
|
- lib/active_element/permissions_report.rb
|
327
|
+
- lib/active_element/pre_render_processors.rb
|
328
|
+
- lib/active_element/pre_render_processors/json.rb
|
212
329
|
- lib/active_element/rails_component.rb
|
213
330
|
- lib/active_element/route.rb
|
214
331
|
- lib/active_element/routes.rb
|
215
332
|
- lib/active_element/version.rb
|
216
333
|
- lib/tasks/active_element.rake
|
334
|
+
- rspec-documentation/_head.html.erb
|
217
335
|
- rspec-documentation/dummy
|
218
|
-
- rspec-documentation/pages/
|
219
|
-
- rspec-documentation/pages/
|
220
|
-
- rspec-documentation/pages/Components
|
221
|
-
- rspec-documentation/pages/Components/
|
222
|
-
- rspec-documentation/pages/
|
223
|
-
- rspec-documentation/pages/
|
224
|
-
- rspec-documentation/pages/
|
225
|
-
- rspec-documentation/pages/
|
336
|
+
- rspec-documentation/pages/000-Introduction.md
|
337
|
+
- rspec-documentation/pages/005-Setup.md
|
338
|
+
- rspec-documentation/pages/010-Components.md
|
339
|
+
- rspec-documentation/pages/010-Components/Form Fields.md
|
340
|
+
- rspec-documentation/pages/010-Components/Form Fields/Check Boxes.md
|
341
|
+
- rspec-documentation/pages/010-Components/Form Fields/JSON.md
|
342
|
+
- rspec-documentation/pages/010-Components/Form Fields/JSON/Controller Params.md
|
343
|
+
- rspec-documentation/pages/010-Components/Form Fields/JSON/Schema.md
|
344
|
+
- rspec-documentation/pages/010-Components/Form Fields/JSON/Types.md
|
345
|
+
- rspec-documentation/pages/010-Components/Form Fields/Text Search.md
|
346
|
+
- rspec-documentation/pages/010-Components/Forms.md
|
347
|
+
- rspec-documentation/pages/010-Components/JSON Data.md
|
348
|
+
- rspec-documentation/pages/010-Components/Navbar.md
|
349
|
+
- rspec-documentation/pages/010-Components/Page Section Title.md
|
350
|
+
- rspec-documentation/pages/010-Components/Page Subtitle.md
|
351
|
+
- rspec-documentation/pages/010-Components/Page Title.md
|
352
|
+
- rspec-documentation/pages/010-Components/Tables.md
|
353
|
+
- rspec-documentation/pages/010-Components/Tables/Collection Table.md
|
354
|
+
- rspec-documentation/pages/010-Components/Tables/Item Table.md
|
355
|
+
- rspec-documentation/pages/010-Components/Tables/Options.md
|
356
|
+
- rspec-documentation/pages/010-Components/Tabs.md
|
357
|
+
- rspec-documentation/pages/020-Access Control.md
|
358
|
+
- rspec-documentation/pages/020-Access Control/010-Authentication.md
|
359
|
+
- rspec-documentation/pages/020-Access Control/020-Authorization.md
|
360
|
+
- rspec-documentation/pages/020-Access Control/020-Authorization/Environments.md
|
361
|
+
- rspec-documentation/pages/020-Access Control/020-Authorization/Permissions.md
|
362
|
+
- rspec-documentation/pages/020-Access Control/020-Authorization/Permissions/Custom
|
363
|
+
Routes.md
|
364
|
+
- rspec-documentation/pages/020-Access Control/020-Authorization/Setup.md
|
365
|
+
- rspec-documentation/pages/040-Decorators.md
|
366
|
+
- rspec-documentation/pages/040-Decorators/Inline Decorators.md
|
367
|
+
- rspec-documentation/pages/040-Decorators/View Decorators.md
|
368
|
+
- rspec-documentation/pages/300-Alternatives.md
|
369
|
+
- rspec-documentation/pages/900-License.md
|
226
370
|
- rspec-documentation/spec_helper.rb
|
371
|
+
- rspec-documentation/support.rb
|
227
372
|
- sig/active_element.rbs
|
228
373
|
homepage: https://github.com/bobf/active_element
|
229
374
|
licenses:
|
@@ -1 +0,0 @@
|
|
1
|
-
# Forms
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# Tables
|
2
|
-
|
3
|
-
## Collection Table
|
4
|
-
|
5
|
-
The _Collection Table_ component provides a vertical table containing a collection of items item. Use with _Active Record_ model instances, an array of objects that extend `ActiveModel::Naming`, or simple hash-like objects.
|
6
|
-
|
7
|
-
Field types are automatically inferred from their respective database columns and rendered using an appropriate formatter.
|
8
|
-
|
9
|
-
```rspec:html
|
10
|
-
class User < ActiveRecord::Base
|
11
|
-
end
|
12
|
-
|
13
|
-
collection = [
|
14
|
-
User.new(name: 'John', email: 'john@example.com'),
|
15
|
-
User.new(name: 'Jane', email: 'jane@example.org')
|
16
|
-
]
|
17
|
-
|
18
|
-
html = active_element.component.table collection: collection, fields: [:name, :email]
|
19
|
-
|
20
|
-
it_documents html do
|
21
|
-
expect(html).to include 'John'
|
22
|
-
end
|
23
|
-
```
|
24
|
-
|
25
|
-
## Item Table
|
26
|
-
|
27
|
-
The _Item Table_ component provides a horizontal table containing a single item and its attributes. It supports the same item types as [Collection Tables](##Collection Table).
|
28
|
-
|
29
|
-
```rspec:html
|
30
|
-
class User < ActiveRecord::Base
|
31
|
-
end
|
32
|
-
|
33
|
-
item = User.new(name: 'John', email: 'john@example.com', overview: 'Writes Ruby code for a living.')
|
34
|
-
|
35
|
-
html = active_element.component.table item: item, fields: [:name, :email, :password, :secret]
|
36
|
-
|
37
|
-
it_documents html do
|
38
|
-
expect(html).to include 'John'
|
39
|
-
end
|
40
|
-
```
|
41
|
-
|
42
|
-
```rspec
|
43
|
-
foo = { foo: 'bar', baz: 'qux' }
|
44
|
-
it_documents foo do
|
45
|
-
expect('hello').to eql 'hello'
|
46
|
-
end
|
47
|
-
```
|
@@ -1 +0,0 @@
|
|
1
|
-
# Components
|
@@ -1 +0,0 @@
|
|
1
|
-
# Inline Decorators
|
@@ -1 +0,0 @@
|
|
1
|
-
# View Decorators
|