active_element 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -2
  3. data/.strong_versions.yml +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +111 -78
  6. data/Makefile +10 -0
  7. data/active_element.gemspec +1 -1
  8. data/app/assets/javascripts/active_element/application.js +1 -0
  9. data/app/assets/javascripts/active_element/form.js +16 -32
  10. data/app/assets/javascripts/active_element/json_field.js +391 -135
  11. data/app/assets/javascripts/active_element/setup.js +13 -8
  12. data/app/assets/javascripts/active_element/text_search_field.js +27 -28
  13. data/app/assets/javascripts/active_element/theme.js +1 -1
  14. data/app/assets/javascripts/active_element/timezones.js +6 -0
  15. data/app/assets/stylesheets/active_element/_dark.scss +86 -0
  16. data/app/assets/stylesheets/active_element/_variables.scss +2 -1
  17. data/app/assets/stylesheets/active_element/application.scss +170 -31
  18. data/app/controllers/active_element/application_controller.rb +5 -0
  19. data/app/controllers/concerns/active_element/default_controller_actions.rb +38 -0
  20. data/app/views/active_element/_user.html.erb +20 -0
  21. data/app/views/active_element/components/fields/_json.html.erb +24 -0
  22. data/app/views/active_element/components/form/_check_box.html.erb +1 -0
  23. data/app/views/active_element/components/form/_check_boxes.html.erb +1 -1
  24. data/app/views/active_element/components/form/_datetime_range_field.html.erb +14 -0
  25. data/app/views/active_element/components/form/_field.html.erb +10 -7
  26. data/app/views/active_element/components/form/_generic_field.html.erb +1 -0
  27. data/app/views/active_element/components/form/_json.html.erb +10 -2
  28. data/app/views/active_element/components/form/_label.html.erb +12 -1
  29. data/app/views/active_element/components/form/_select.html.erb +4 -1
  30. data/app/views/active_element/components/form/_summary.html.erb +11 -1
  31. data/app/views/active_element/components/form/_templates.html.erb +37 -22
  32. data/app/views/active_element/components/form/_text_area.html.erb +2 -1
  33. data/app/views/active_element/components/form/_text_search.html.erb +7 -3
  34. data/app/views/active_element/components/form.html.erb +20 -17
  35. data/app/views/active_element/components/json.html.erb +1 -0
  36. data/app/views/active_element/components/navbar.html.erb +26 -0
  37. data/app/views/active_element/components/table/_collection_row.html.erb +2 -1
  38. data/app/views/active_element/components/table/_field.html.erb +8 -0
  39. data/app/views/active_element/components/table/collection.html.erb +1 -1
  40. data/app/views/active_element/components/table/item.html.erb +5 -4
  41. data/app/views/active_element/default_views/edit.html.erb +5 -0
  42. data/app/views/active_element/default_views/index.html.erb +15 -0
  43. data/app/views/active_element/default_views/new.html.erb +4 -0
  44. data/app/views/active_element/default_views/show.html.erb +7 -0
  45. data/app/views/active_element/navbar/_menu.html.erb +1 -30
  46. data/app/views/active_element/theme/_select.html.erb +1 -1
  47. data/app/views/layouts/active_element.html.erb +17 -2
  48. data/config/brakeman.ignore +48 -0
  49. data/example_app/.gitattributes +7 -0
  50. data/example_app/.gitignore +35 -0
  51. data/example_app/.ruby-version +1 -0
  52. data/example_app/Gemfile +34 -0
  53. data/example_app/Gemfile.lock +296 -0
  54. data/example_app/README.md +24 -0
  55. data/example_app/Rakefile +6 -0
  56. data/example_app/app/assets/config/manifest.js +4 -0
  57. data/example_app/app/assets/images/.keep +0 -0
  58. data/example_app/app/assets/stylesheets/application.css +15 -0
  59. data/example_app/app/channels/application_cable/channel.rb +4 -0
  60. data/example_app/app/channels/application_cable/connection.rb +4 -0
  61. data/example_app/app/controllers/application_controller.rb +12 -0
  62. data/example_app/app/controllers/concerns/.keep +0 -0
  63. data/example_app/app/controllers/pets_controller.rb +6 -0
  64. data/example_app/app/controllers/users_controller.rb +6 -0
  65. data/example_app/app/helpers/application_helper.rb +2 -0
  66. data/example_app/app/javascript/application.js +3 -0
  67. data/example_app/app/javascript/controllers/application.js +9 -0
  68. data/example_app/app/javascript/controllers/hello_controller.js +7 -0
  69. data/example_app/app/javascript/controllers/index.js +11 -0
  70. data/example_app/app/jobs/application_job.rb +7 -0
  71. data/example_app/app/mailers/application_mailer.rb +4 -0
  72. data/example_app/app/models/application_record.rb +3 -0
  73. data/example_app/app/models/concerns/.keep +0 -0
  74. data/example_app/app/models/pet.rb +3 -0
  75. data/example_app/app/models/user.rb +8 -0
  76. data/example_app/app/views/layouts/application.html.erb +16 -0
  77. data/example_app/app/views/layouts/mailer.html.erb +13 -0
  78. data/example_app/app/views/layouts/mailer.text.erb +1 -0
  79. data/example_app/app/views/pets/index.html.erb +3 -0
  80. data/example_app/app/views/users/show.html.erb +3 -0
  81. data/example_app/bin/bundle +109 -0
  82. data/example_app/bin/importmap +4 -0
  83. data/example_app/bin/rails +4 -0
  84. data/example_app/bin/rake +4 -0
  85. data/example_app/bin/setup +33 -0
  86. data/example_app/config/application.rb +22 -0
  87. data/example_app/config/boot.rb +4 -0
  88. data/example_app/config/cable.yml +10 -0
  89. data/example_app/config/credentials.yml.enc +1 -0
  90. data/example_app/config/database.yml +25 -0
  91. data/example_app/config/environment.rb +5 -0
  92. data/example_app/config/environments/development.rb +70 -0
  93. data/example_app/config/environments/production.rb +93 -0
  94. data/example_app/config/environments/test.rb +60 -0
  95. data/example_app/config/importmap.rb +7 -0
  96. data/example_app/config/initializers/assets.rb +12 -0
  97. data/example_app/config/initializers/content_security_policy.rb +25 -0
  98. data/example_app/config/initializers/devise.rb +16 -0
  99. data/example_app/config/initializers/filter_parameter_logging.rb +8 -0
  100. data/example_app/config/initializers/inflections.rb +16 -0
  101. data/example_app/config/initializers/permissions_policy.rb +11 -0
  102. data/example_app/config/locales/devise.en.yml +65 -0
  103. data/example_app/config/locales/en.yml +33 -0
  104. data/example_app/config/puma.rb +43 -0
  105. data/example_app/config/routes.rb +8 -0
  106. data/example_app/config/storage.yml +34 -0
  107. data/example_app/config.ru +6 -0
  108. data/example_app/db/migrate/20230616210539_create_pet.rb +12 -0
  109. data/example_app/db/migrate/20230616211328_devise_create_users.rb +46 -0
  110. data/example_app/db/schema.rb +37 -0
  111. data/example_app/db/seeds.rb +33 -0
  112. data/example_app/lib/assets/.keep +0 -0
  113. data/example_app/lib/tasks/.keep +0 -0
  114. data/example_app/log/.keep +0 -0
  115. data/example_app/public/404.html +67 -0
  116. data/example_app/public/422.html +67 -0
  117. data/example_app/public/500.html +66 -0
  118. data/example_app/public/apple-touch-icon-precomposed.png +0 -0
  119. data/example_app/public/apple-touch-icon.png +0 -0
  120. data/example_app/public/favicon.ico +0 -0
  121. data/example_app/public/robots.txt +1 -0
  122. data/example_app/storage/.keep +0 -0
  123. data/example_app/test/application_system_test_case.rb +5 -0
  124. data/example_app/test/channels/application_cable/connection_test.rb +11 -0
  125. data/example_app/test/controllers/.keep +0 -0
  126. data/example_app/test/fixtures/files/.keep +0 -0
  127. data/example_app/test/fixtures/users.yml +11 -0
  128. data/example_app/test/helpers/.keep +0 -0
  129. data/example_app/test/integration/.keep +0 -0
  130. data/example_app/test/mailers/.keep +0 -0
  131. data/example_app/test/models/.keep +0 -0
  132. data/example_app/test/models/user_test.rb +7 -0
  133. data/example_app/test/system/.keep +0 -0
  134. data/example_app/test/test_helper.rb +13 -0
  135. data/example_app/tmp/.keep +0 -0
  136. data/example_app/tmp/pids/.keep +0 -0
  137. data/example_app/tmp/storage/.keep +0 -0
  138. data/example_app/vendor/.keep +0 -0
  139. data/example_app/vendor/javascript/.keep +0 -0
  140. data/lib/active_element/component.rb +9 -2
  141. data/lib/active_element/components/collection_table.rb +9 -2
  142. data/lib/active_element/components/email_fields.rb +14 -0
  143. data/lib/active_element/components/form.rb +48 -17
  144. data/lib/active_element/components/navbar.rb +64 -0
  145. data/lib/active_element/components/phone_fields.rb +14 -0
  146. data/lib/active_element/components/text_search/authorization.rb +9 -6
  147. data/lib/active_element/components/text_search/component.rb +4 -2
  148. data/lib/active_element/components/text_search.rb +4 -0
  149. data/lib/active_element/components/util/association_mapping.rb +74 -19
  150. data/lib/active_element/components/util/display_value_mapping.rb +13 -4
  151. data/lib/active_element/components/util/form_field_mapping.rb +127 -10
  152. data/lib/active_element/components/util/form_value_mapping.rb +3 -7
  153. data/lib/active_element/components/util/i18n.rb +1 -1
  154. data/lib/active_element/components/util/record_mapping.rb +43 -11
  155. data/lib/active_element/components/util/record_path.rb +21 -4
  156. data/lib/active_element/components/util.rb +12 -5
  157. data/lib/active_element/components.rb +3 -0
  158. data/lib/active_element/controller_action.rb +8 -2
  159. data/lib/active_element/controller_interface.rb +47 -5
  160. data/lib/active_element/default_controller.rb +93 -0
  161. data/lib/active_element/default_record_params.rb +62 -0
  162. data/lib/active_element/default_text_search.rb +110 -0
  163. data/lib/active_element/json_field_schema.rb +59 -0
  164. data/lib/active_element/pre_render_processors/json.rb +98 -0
  165. data/lib/active_element/pre_render_processors.rb +11 -0
  166. data/lib/active_element/route.rb +12 -0
  167. data/lib/active_element/routes.rb +2 -1
  168. data/lib/active_element/version.rb +1 -1
  169. data/lib/active_element.rb +14 -32
  170. data/lib/tasks/active_element.rake +12 -1
  171. data/rspec-documentation/_head.html.erb +34 -0
  172. data/rspec-documentation/pages/000-Introduction.md +18 -0
  173. data/rspec-documentation/pages/005-Setup.md +75 -0
  174. data/rspec-documentation/pages/010-Components/Form Fields/Check Boxes.md +1 -0
  175. data/rspec-documentation/pages/010-Components/Form Fields/JSON/Controller Params.md +97 -0
  176. data/rspec-documentation/pages/010-Components/Form Fields/JSON/Schema.md +283 -0
  177. data/rspec-documentation/pages/010-Components/Form Fields/JSON/Types.md +36 -0
  178. data/rspec-documentation/pages/010-Components/Form Fields/JSON.md +70 -0
  179. data/rspec-documentation/pages/010-Components/Form Fields/Text Search.md +133 -0
  180. data/rspec-documentation/pages/010-Components/Form Fields.md +46 -0
  181. data/rspec-documentation/pages/010-Components/Forms.md +44 -0
  182. data/rspec-documentation/pages/010-Components/JSON Data.md +23 -0
  183. data/rspec-documentation/pages/010-Components/Navbar.md +56 -0
  184. data/rspec-documentation/pages/010-Components/Page Section Title.md +13 -0
  185. data/rspec-documentation/pages/010-Components/Page Subtitle.md +11 -0
  186. data/rspec-documentation/pages/010-Components/Page Title.md +11 -0
  187. data/rspec-documentation/pages/010-Components/Tables/Collection Table.md +29 -0
  188. data/rspec-documentation/pages/010-Components/Tables/Item Table.md +18 -0
  189. data/rspec-documentation/pages/010-Components/Tables/Options.md +19 -0
  190. data/rspec-documentation/pages/010-Components/Tables.md +29 -0
  191. data/rspec-documentation/pages/010-Components.md +15 -0
  192. data/rspec-documentation/pages/020-Access Control/010-Authentication.md +20 -0
  193. data/rspec-documentation/pages/020-Access Control/020-Authorization/Environments.md +9 -0
  194. data/rspec-documentation/pages/020-Access Control/020-Authorization/Permissions/Custom Routes.md +41 -0
  195. data/rspec-documentation/pages/020-Access Control/020-Authorization/Permissions.md +58 -0
  196. data/rspec-documentation/pages/020-Access Control/020-Authorization/Setup.md +27 -0
  197. data/rspec-documentation/pages/020-Access Control/020-Authorization.md +11 -0
  198. data/rspec-documentation/pages/020-Access Control.md +31 -0
  199. data/rspec-documentation/pages/040-Decorators/Inline Decorators.md +24 -0
  200. data/rspec-documentation/pages/040-Decorators/View Decorators.md +55 -0
  201. data/rspec-documentation/pages/040-Decorators.md +12 -0
  202. data/rspec-documentation/pages/300-Alternatives.md +21 -0
  203. data/rspec-documentation/pages/900-License.md +11 -0
  204. data/rspec-documentation/spec_helper.rb +53 -16
  205. data/rspec-documentation/support.rb +84 -0
  206. metadata +155 -14
  207. data/rspec-documentation/pages/Components/Forms.md +0 -1
  208. data/rspec-documentation/pages/Components/Tables.md +0 -47
  209. data/rspec-documentation/pages/Components.md +0 -1
  210. data/rspec-documentation/pages/Decorators/Inline Decorators.md +0 -1
  211. data/rspec-documentation/pages/Decorators/View Decorators.md +0 -1
  212. data/rspec-documentation/pages/Index.md +0 -3
  213. data/rspec-documentation/pages/Util/I18n.md +0 -1
  214. /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
- rescue ActiveRecord::StatementInvalid
8
- # Skip
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
- config.context do |context|
20
- class StubbedController < ActiveElement::ApplicationController
21
-
22
- def initialize(*args, &block)
23
- append_view_path File.expand_path(File.join(__dir__, '../app/views/'))
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
- context.active_element.component = ActiveElement::Component.new(StubbedController.new)
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.9
4
+ version: 0.0.11
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-05-31 00:00:00.000000000 Z
11
+ date: 2023-06-18 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.1'
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.1'
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,10 @@ 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/index.html.erb
172
+ - app/views/active_element/default_views/new.html.erb
173
+ - app/views/active_element/default_views/show.html.erb
162
174
  - app/views/active_element/forbidden.html.erb
163
175
  - app/views/active_element/main_menu/_item.html.erb
164
176
  - app/views/active_element/navbar/_menu.html.erb
@@ -173,18 +185,113 @@ files:
173
185
  - app/views/kaminari/_prev_page.html.erb
174
186
  - app/views/layouts/active_element.html.erb
175
187
  - app/views/layouts/active_element_error.html.erb
188
+ - config/brakeman.ignore
176
189
  - config/routes.rb
190
+ - example_app/.gitattributes
191
+ - example_app/.gitignore
192
+ - example_app/.ruby-version
193
+ - example_app/Gemfile
194
+ - example_app/Gemfile.lock
195
+ - example_app/README.md
196
+ - example_app/Rakefile
197
+ - example_app/app/assets/config/manifest.js
198
+ - example_app/app/assets/images/.keep
199
+ - example_app/app/assets/stylesheets/application.css
200
+ - example_app/app/channels/application_cable/channel.rb
201
+ - example_app/app/channels/application_cable/connection.rb
202
+ - example_app/app/controllers/application_controller.rb
203
+ - example_app/app/controllers/concerns/.keep
204
+ - example_app/app/controllers/pets_controller.rb
205
+ - example_app/app/controllers/users_controller.rb
206
+ - example_app/app/helpers/application_helper.rb
207
+ - example_app/app/javascript/application.js
208
+ - example_app/app/javascript/controllers/application.js
209
+ - example_app/app/javascript/controllers/hello_controller.js
210
+ - example_app/app/javascript/controllers/index.js
211
+ - example_app/app/jobs/application_job.rb
212
+ - example_app/app/mailers/application_mailer.rb
213
+ - example_app/app/models/application_record.rb
214
+ - example_app/app/models/concerns/.keep
215
+ - example_app/app/models/pet.rb
216
+ - example_app/app/models/user.rb
217
+ - example_app/app/views/layouts/application.html.erb
218
+ - example_app/app/views/layouts/mailer.html.erb
219
+ - example_app/app/views/layouts/mailer.text.erb
220
+ - example_app/app/views/pets/index.html.erb
221
+ - example_app/app/views/users/show.html.erb
222
+ - example_app/bin/bundle
223
+ - example_app/bin/importmap
224
+ - example_app/bin/rails
225
+ - example_app/bin/rake
226
+ - example_app/bin/setup
227
+ - example_app/config.ru
228
+ - example_app/config/application.rb
229
+ - example_app/config/boot.rb
230
+ - example_app/config/cable.yml
231
+ - example_app/config/credentials.yml.enc
232
+ - example_app/config/database.yml
233
+ - example_app/config/environment.rb
234
+ - example_app/config/environments/development.rb
235
+ - example_app/config/environments/production.rb
236
+ - example_app/config/environments/test.rb
237
+ - example_app/config/importmap.rb
238
+ - example_app/config/initializers/assets.rb
239
+ - example_app/config/initializers/content_security_policy.rb
240
+ - example_app/config/initializers/devise.rb
241
+ - example_app/config/initializers/filter_parameter_logging.rb
242
+ - example_app/config/initializers/inflections.rb
243
+ - example_app/config/initializers/permissions_policy.rb
244
+ - example_app/config/locales/devise.en.yml
245
+ - example_app/config/locales/en.yml
246
+ - example_app/config/puma.rb
247
+ - example_app/config/routes.rb
248
+ - example_app/config/storage.yml
249
+ - example_app/db/migrate/20230616210539_create_pet.rb
250
+ - example_app/db/migrate/20230616211328_devise_create_users.rb
251
+ - example_app/db/schema.rb
252
+ - example_app/db/seeds.rb
253
+ - example_app/lib/assets/.keep
254
+ - example_app/lib/tasks/.keep
255
+ - example_app/log/.keep
256
+ - example_app/public/404.html
257
+ - example_app/public/422.html
258
+ - example_app/public/500.html
259
+ - example_app/public/apple-touch-icon-precomposed.png
260
+ - example_app/public/apple-touch-icon.png
261
+ - example_app/public/favicon.ico
262
+ - example_app/public/robots.txt
263
+ - example_app/storage/.keep
264
+ - example_app/test/application_system_test_case.rb
265
+ - example_app/test/channels/application_cable/connection_test.rb
266
+ - example_app/test/controllers/.keep
267
+ - example_app/test/fixtures/files/.keep
268
+ - example_app/test/fixtures/users.yml
269
+ - example_app/test/helpers/.keep
270
+ - example_app/test/integration/.keep
271
+ - example_app/test/mailers/.keep
272
+ - example_app/test/models/.keep
273
+ - example_app/test/models/user_test.rb
274
+ - example_app/test/system/.keep
275
+ - example_app/test/test_helper.rb
276
+ - example_app/tmp/.keep
277
+ - example_app/tmp/pids/.keep
278
+ - example_app/tmp/storage/.keep
279
+ - example_app/vendor/.keep
280
+ - example_app/vendor/javascript/.keep
177
281
  - lib/active_element.rb
178
282
  - lib/active_element/active_menu_link.rb
179
283
  - lib/active_element/component.rb
180
284
  - lib/active_element/components.rb
181
285
  - lib/active_element/components/button.rb
182
286
  - lib/active_element/components/collection_table.rb
287
+ - lib/active_element/components/email_fields.rb
183
288
  - lib/active_element/components/form.rb
184
289
  - lib/active_element/components/item_table.rb
185
290
  - lib/active_element/components/json.rb
186
291
  - lib/active_element/components/link_helpers.rb
292
+ - lib/active_element/components/navbar.rb
187
293
  - lib/active_element/components/page_description.rb
294
+ - lib/active_element/components/phone_fields.rb
188
295
  - lib/active_element/components/secret_fields.rb
189
296
  - lib/active_element/components/tab.rb
190
297
  - lib/active_element/components/tabs.rb
@@ -206,24 +313,58 @@ files:
206
313
  - lib/active_element/components/util/record_path.rb
207
314
  - lib/active_element/controller_action.rb
208
315
  - lib/active_element/controller_interface.rb
316
+ - lib/active_element/default_controller.rb
317
+ - lib/active_element/default_record_params.rb
318
+ - lib/active_element/default_text_search.rb
209
319
  - lib/active_element/engine.rb
320
+ - lib/active_element/json_field_schema.rb
210
321
  - lib/active_element/permissions_check.rb
211
322
  - lib/active_element/permissions_report.rb
323
+ - lib/active_element/pre_render_processors.rb
324
+ - lib/active_element/pre_render_processors/json.rb
212
325
  - lib/active_element/rails_component.rb
213
326
  - lib/active_element/route.rb
214
327
  - lib/active_element/routes.rb
215
328
  - lib/active_element/version.rb
216
329
  - lib/tasks/active_element.rake
330
+ - rspec-documentation/_head.html.erb
217
331
  - rspec-documentation/dummy
218
- - rspec-documentation/pages/Components.md
219
- - rspec-documentation/pages/Components/Forms.md
220
- - rspec-documentation/pages/Components/Tables.md
221
- - rspec-documentation/pages/Components/Tabs.md
222
- - rspec-documentation/pages/Decorators/Inline Decorators.md
223
- - rspec-documentation/pages/Decorators/View Decorators.md
224
- - rspec-documentation/pages/Index.md
225
- - rspec-documentation/pages/Util/I18n.md
332
+ - rspec-documentation/pages/000-Introduction.md
333
+ - rspec-documentation/pages/005-Setup.md
334
+ - rspec-documentation/pages/010-Components.md
335
+ - rspec-documentation/pages/010-Components/Form Fields.md
336
+ - rspec-documentation/pages/010-Components/Form Fields/Check Boxes.md
337
+ - rspec-documentation/pages/010-Components/Form Fields/JSON.md
338
+ - rspec-documentation/pages/010-Components/Form Fields/JSON/Controller Params.md
339
+ - rspec-documentation/pages/010-Components/Form Fields/JSON/Schema.md
340
+ - rspec-documentation/pages/010-Components/Form Fields/JSON/Types.md
341
+ - rspec-documentation/pages/010-Components/Form Fields/Text Search.md
342
+ - rspec-documentation/pages/010-Components/Forms.md
343
+ - rspec-documentation/pages/010-Components/JSON Data.md
344
+ - rspec-documentation/pages/010-Components/Navbar.md
345
+ - rspec-documentation/pages/010-Components/Page Section Title.md
346
+ - rspec-documentation/pages/010-Components/Page Subtitle.md
347
+ - rspec-documentation/pages/010-Components/Page Title.md
348
+ - rspec-documentation/pages/010-Components/Tables.md
349
+ - rspec-documentation/pages/010-Components/Tables/Collection Table.md
350
+ - rspec-documentation/pages/010-Components/Tables/Item Table.md
351
+ - rspec-documentation/pages/010-Components/Tables/Options.md
352
+ - rspec-documentation/pages/010-Components/Tabs.md
353
+ - rspec-documentation/pages/020-Access Control.md
354
+ - rspec-documentation/pages/020-Access Control/010-Authentication.md
355
+ - rspec-documentation/pages/020-Access Control/020-Authorization.md
356
+ - rspec-documentation/pages/020-Access Control/020-Authorization/Environments.md
357
+ - rspec-documentation/pages/020-Access Control/020-Authorization/Permissions.md
358
+ - rspec-documentation/pages/020-Access Control/020-Authorization/Permissions/Custom
359
+ Routes.md
360
+ - rspec-documentation/pages/020-Access Control/020-Authorization/Setup.md
361
+ - rspec-documentation/pages/040-Decorators.md
362
+ - rspec-documentation/pages/040-Decorators/Inline Decorators.md
363
+ - rspec-documentation/pages/040-Decorators/View Decorators.md
364
+ - rspec-documentation/pages/300-Alternatives.md
365
+ - rspec-documentation/pages/900-License.md
226
366
  - rspec-documentation/spec_helper.rb
367
+ - rspec-documentation/support.rb
227
368
  - sig/active_element.rbs
228
369
  homepage: https://github.com/bobf/active_element
229
370
  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
@@ -1,3 +0,0 @@
1
- # ActiveElement
2
-
3
- _ActiveElement_ provides a number of components for use in _Ruby on Rails_ views as well as a flexible auhorization model.
@@ -1 +0,0 @@
1
- # Internationalization