reactiveadmin 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +1 -1
  4. data/lib/reactive_admin/aa/input.rb +26 -0
  5. data/lib/reactive_admin/aa/v3/form_hooks.rb +38 -0
  6. data/lib/reactive_admin/aa/v3/forms.rb +9 -1
  7. data/lib/reactive_admin/aa/v3/recorders.rb +51 -0
  8. data/lib/reactive_admin/aa/v3/views.rb +20 -1
  9. data/lib/reactive_admin/aa/v3.rb +2 -0
  10. data/lib/reactive_admin/aa/v4.rb +10 -0
  11. data/lib/reactive_admin/aa.rb +2 -1
  12. data/lib/reactive_admin/engine.rb +6 -0
  13. data/lib/reactive_admin/form_field.rb +3 -3
  14. data/lib/reactive_admin/form_recorder.rb +8 -10
  15. data/lib/reactive_admin/html_nodes.rb +17 -16
  16. data/lib/reactive_admin/index_recorder.rb +9 -11
  17. data/lib/reactive_admin/open_api/page_doc.rb +2 -2
  18. data/lib/reactive_admin/open_api/parts.rb +3 -0
  19. data/lib/reactive_admin/open_api/resource_doc.rb +1 -8
  20. data/lib/reactive_admin/page_forms.rb +3 -26
  21. data/lib/reactive_admin/page_payload.rb +4 -6
  22. data/lib/reactive_admin/rspec.rb +12 -2
  23. data/lib/reactive_admin/show_payload.rb +4 -6
  24. data/lib/reactive_admin/style_sources.rb +1 -1
  25. data/lib/reactive_admin/template_form.rb +12 -27
  26. data/lib/reactive_admin/ui/assets.rb +19 -1
  27. data/lib/reactive_admin/ui/helper.rb +2 -2
  28. data/lib/reactive_admin/version.rb +1 -1
  29. data/openapi/core.yaml +59 -5
  30. data/vendor/client/assets/{ActionPage-XUYorI8E.js → ActionPage-B_eluF5e.js} +1 -1
  31. data/vendor/client/assets/{ActionView-BsZFcsgp.js → ActionView-CGcC3D3z.js} +1 -1
  32. data/vendor/client/assets/{CommandPalette-C59HT1ip.js → CommandPalette-IF4e0T2d.js} +1 -1
  33. data/vendor/client/assets/{DatePicker-DuaK0iMg.js → DatePicker-CgNVJIOj.js} +1 -1
  34. data/vendor/client/assets/DateRangeCalendar-BbIDUkc0.js +1 -0
  35. data/vendor/client/assets/{DegradedNotice-DiH5n2DO.js → DegradedNotice-DPH_YfUt.js} +1 -1
  36. data/vendor/client/assets/{FormDialog-pmYl8Eov.js → FormDialog-DzHVGQ6M.js} +1 -1
  37. data/vendor/client/assets/{FormSkeleton-DuSBZO3C.js → FormSkeleton-5eT0T2pe.js} +1 -1
  38. data/vendor/client/assets/{FrameView-zmUeDO8d.js → FrameView-CczSy0lF.js} +1 -1
  39. data/vendor/client/assets/{GroupOverview-DI5T3k5K.js → GroupOverview-BgyZuNFr.js} +1 -1
  40. data/vendor/client/assets/{InlineForm-CMEIMgeh.js → InlineForm-D0e87tnu.js} +1 -1
  41. data/vendor/client/assets/{JsonDiff-o7JWr7CH.js → JsonDiff-CAW7eyGU.js} +1 -1
  42. data/vendor/client/assets/{JsonEditor-D4VXdlEx.js → JsonEditor-DQGi6MrZ.js} +1 -1
  43. data/vendor/client/assets/{JsonView-BrJLDmSN.js → JsonView-WqpIBVJn.js} +1 -1
  44. data/vendor/client/assets/{MobileMenu-GAeFOeEb.js → MobileMenu-BmrGFN_r.js} +1 -1
  45. data/vendor/client/assets/{Node-SQl61V4K.js → Node-BFhcTc_1.js} +2 -2
  46. data/vendor/client/assets/{PageView-C-laNEPZ.js → PageView-DJSTdX6o.js} +1 -1
  47. data/vendor/client/assets/{ResourceForm-BPjsoCY6.js → ResourceForm-7FgpxGHE.js} +1 -1
  48. data/vendor/client/assets/{ResourceIndex-COezAw5t.js → ResourceIndex-BXnX5xpb.js} +3 -3
  49. data/vendor/client/assets/{ResourceOrPage-CRZGCY84.js → ResourceOrPage-54vonIqh.js} +1 -1
  50. data/vendor/client/assets/{ResourceShow-DweRXn18.js → ResourceShow-BAO32hZ2.js} +1 -1
  51. data/vendor/client/assets/{Sidebars-CsB9rFqX.js → Sidebars-C3SKSr0y.js} +1 -1
  52. data/vendor/client/assets/{breadcrumb-DSA3Tlyd.js → breadcrumb-FT076GDh.js} +1 -1
  53. data/vendor/client/assets/{calendar-BoyMpJIf.js → calendar-C7i0aj0N.js} +1 -1
  54. data/vendor/client/assets/{command-CMuk0oAt.js → command-Cxg-I-G2.js} +1 -1
  55. data/vendor/client/assets/{frames-C9gPCc3N.js → frames-5gaTmR-V.js} +1 -1
  56. data/vendor/client/assets/{index-B51aUaAY.js → index-BX4ymNYp.js} +2 -2
  57. data/vendor/client/assets/{json-oTp7Q-d-.js → json-DJQxJYgz.js} +1 -1
  58. data/vendor/client/assets/{media-D4a_En8R.js → media-D9RvvA8H.js} +1 -1
  59. data/vendor/client/assets/{popover-CDtI9R8Q.js → popover-C_DGv69u.js} +1 -1
  60. data/vendor/client/assets/{rich-BQc_q5T7.js → rich-Dl2s62g4.js} +1 -1
  61. data/vendor/client/assets/{select-C43qDA3k.js → select-DWKulrU7.js} +1 -1
  62. data/vendor/client/assets/{sheet-BPl2n-4n.js → sheet-CihU0Mcq.js} +1 -1
  63. data/vendor/client/assets/{useRecordForm-X_DExEP2.js → useRecordForm-BOmRWZbo.js} +1 -1
  64. data/vendor/client/index.html +1 -1
  65. data/vendor/client/manifest.json +110 -110
  66. data/vendor/client/reactiveadmin-client.json +1 -1
  67. metadata +38 -35
  68. data/vendor/client/assets/DateRangeCalendar-B2BDsG-X.js +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44c03bc2825ae658fec598e140daf653a6637af6d303d77f7555dfa68c04e1f2
4
- data.tar.gz: 2a62fbf39cc4c83981f20b419f75ae6fd7b2e941cd2ae558197b86a424a95b4f
3
+ metadata.gz: 75d43f4a75185667db04f00193d81e2b90f3d18494fcb21de6a7e1479ea37fcc
4
+ data.tar.gz: 5a995d92a8571ca6a04ac2ec893453660f8c9e939f42d68ebc4c04ce712c8d73
5
5
  SHA512:
6
- metadata.gz: 70334041b5c581100636a4db3857fec9f8233753abc3ec68ce38d91a66ce2006e31caebe8a6d02bfa22e7c4d7751f5ea022fd5509a51fd19e36ebe176a3c88ed
7
- data.tar.gz: 2524a3d6e0675add16df9c513c4766d1f2f397596b4bde51939d67f5c275c871ac92b79e7f61bce71d1ee5ff559de5d5834c4b7b4df9107c5c4a48fb6e98b95b
6
+ metadata.gz: 6d87b1b6f95f598d13e7e1391502c9953916c872f1ccc05362c8954aa8b36458b6d01b04d151ae19abdcea40e0e5431931a38e4e691b411ab70255acce685853
7
+ data.tar.gz: 7dc9007bdd28db4df06578170994200df2561fda52ee21ec977a53b77c538c308056eae025ed28c3ac61793aa34b1ad504fac5b39e08042372ed04dd016dd135
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project aims to follow [Semantic Versioning](https://semver.org/) from 1.0.
4
4
 
5
+ ## 0.3.0
6
+
7
+ ### Changed
8
+
9
+ - **Custom actions in the contract.** `core.yaml` declares GET member actions (`runMemberActionGet`, answering `ActionGetResponse`: a form, page content, options or a redirect's result), lets action writes answer `ActionWriteResponse` (a result or a re-rendered form), and declares their `501 unsupported`. The OpenAPI document gives member, collection and page actions the same responses.
10
+
11
+ ### Fixed
12
+
13
+ - The client's files (`ui.asset_prefix`) are answered by a Rack middleware placed before the cookie and session middleware. They were served from the router, behind the session, so a host whose stack loads the session sent `Set-Cookie` on public, immutable responses, which a CDN could cache and hand to other visitors. Files that aren't hashed now say `Cache-Control: no-cache` themselves instead of relying on later middleware.
14
+
5
15
  ## 0.2.0
6
16
 
7
17
  ### Added
data/README.md CHANGED
@@ -6,7 +6,7 @@ Website and docs: <https://formhealth.github.io/reactiveadmin/>, with a [demo](h
6
6
 
7
7
  ## Status
8
8
 
9
- Version 0.2.0. This is early software: interfaces may change before 1.0. See the [changelog](CHANGELOG.md).
9
+ Version 0.3.0. This is early software: interfaces may change before 1.0. See the [changelog](CHANGELOG.md).
10
10
 
11
11
  ## Requirements
12
12
 
@@ -0,0 +1,26 @@
1
+ require "forwardable"
2
+
3
+ module ReactiveAdmin
4
+ module AA
5
+ # One Formtastic input, read through the names FormField needs, so Formtastic's input API stays in the adapter.
6
+ class Input
7
+ extend Forwardable
8
+
9
+ def_delegators :@input, :as, :method, :options, :input_name, :multiple?, :required?, :readonly?, :hint?, :hint_text,
10
+ :localized_label, :humanized_method_name, :errors, :to_html, :collection, :raw_collection, :label_method, :value_method
11
+
12
+ def initialize(input)
13
+ @input = input
14
+ end
15
+
16
+ # :check_boxes and :hidden inputs name their params differently from the rest.
17
+ def kind = AA.input_kind(@input)
18
+
19
+ # Html attributes Formtastic derives from validations and columns (maxlength, min, max, step).
20
+ def html_options = @input.input_html_options
21
+
22
+ # Only association inputs have one.
23
+ def association_primary_key = @input.try(:association_primary_key)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # Modules a view is extended with so Formtastic's and AA's form helpers record instead of print.
5
+ module FormHooks
6
+ # A page's or show's content: each form becomes a form node, or renders as markup when it can't.
7
+ module Page
8
+ %i[semantic_form_for active_admin_form_for].each do |helper|
9
+ define_method(helper) do |*args, &block|
10
+ forms = reactiveadmin_page_forms or return super(*args, &block)
11
+ forms.node(self) { super(*args, &block) } || forms.suspended { super(*args, &block) }
12
+ end
13
+ end
14
+
15
+ def reactiveadmin_page_forms = @_reactiveadmin_page_forms
16
+ end
17
+
18
+ # A custom template: the first form is the response, further ones are extras.
19
+ module Template
20
+ def semantic_form_for(*args, &block)
21
+ state = @_reactiveadmin_template or return super
22
+ return state.extra_form(self) { semantic_form_for(*args, &block) } if state.extra_form?
23
+
24
+ state.record_form(self, block) { |recording| super(*args, &recording) }
25
+ end
26
+
27
+ # AA's version builds an Arbre form around a real builder, which the recorder can't stand in for.
28
+ def active_admin_form_for(resource, options = {}, &block)
29
+ state = @_reactiveadmin_template or return super
30
+ return state.extra_form(self) { active_admin_form_for(resource, options, &block) } if state.extra_form?
31
+
32
+ state.arbre { semantic_form_for(resource, {builder: AA.form_builder}.merge(options), &block) }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -5,10 +5,18 @@ module ReactiveAdmin
5
5
  module Forms
6
6
  def form_builder = ::ActiveAdmin::FormBuilder
7
7
 
8
+ # The element a form block runs in, to subclass.
9
+ def form_recorder_base = Recorders::Form
10
+
11
+ # Extended onto a view so the forms of a page's content, or of a template, record instead of print.
12
+ def page_form_hooks = FormHooks::Page
13
+
14
+ def template_form_hooks = FormHooks::Template
15
+
8
16
  # The input Formtastic would render for `method`: AA's `as:` default unless `options[:as]` says otherwise.
9
17
  def build_input(builder, view, method, options)
10
18
  options[:as] ||= builder.send(:default_input_type, method, options)
11
- builder.send(:namespaced_input_class, options[:as]).new(builder, view, builder.object, builder.object_name, method, options)
19
+ Input.new(builder.send(:namespaced_input_class, options[:as]).new(builder, view, builder.object, builder.object_name, method, options))
12
20
  end
13
21
 
14
22
  # :check_boxes and :hidden inputs name their params differently from the rest.
@@ -0,0 +1,51 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # The Arbre elements that run a host block (`index`, `form`, `show`, `register_page`'s `content`) so the
5
+ # recorders can capture what it builds. Each is an Element rather than a Context: a Context forwards
6
+ # unknown methods to its html string, which would swallow helpers like `truncate` that blocks call.
7
+ module Recorders
8
+ class Element < ::Arbre::Element
9
+ def self.build_in(assigns, view, *args) = ::Arbre::Context.new(assigns, view).insert_tag(self, *args)
10
+
11
+ # Everything rendered into the context so far.
12
+ def document_html = arbre_context.to_s
13
+
14
+ private
15
+
16
+ def add_tag(klass, *args, &) = insert_tag(klass, *args, &)
17
+
18
+ def open_element = current_arbre_element
19
+
20
+ def render_within(&) = within(self, &)
21
+
22
+ def detach(element) = element.parent&.remove_child(element)
23
+ end
24
+
25
+ class Form < Element
26
+ Holder = Class.new(Element)
27
+
28
+ private
29
+
30
+ def add_holder(&) = add_tag(Holder, &)
31
+ end
32
+
33
+ class Index < Element
34
+ private
35
+
36
+ # AA's container for a row's action links.
37
+ def action_links(&) = table_actions(&)
38
+ end
39
+
40
+ # A page's content, where AA's form component builds an Arbre form rather than calling the view helper.
41
+ class Page < Element
42
+ def active_admin_form_for(*args, &block)
43
+ forms = helpers.try(:reactiveadmin_page_forms) or return super
44
+ marker = forms.node(helpers) { helpers.active_admin_form_for(*args, &block) }
45
+ marker ? text_node(marker) : forms.suspended { super(*args, &block) }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -32,15 +32,34 @@ module ReactiveAdmin
32
32
 
33
33
  def plural_many_count = ::ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT
34
34
 
35
- def arbre_element = ::Arbre::Element
35
+ # The elements the index block and a show or page block run in, to subclass.
36
+ def index_recorder_base = Recorders::Index
37
+
38
+ def page_element_base = Recorders::Page
36
39
 
37
40
  def arbre_context(assigns, view) = ::Arbre::Context.new(assigns, view)
38
41
 
39
42
  def arbre_element?(object) = object.is_a?(::Arbre::Element)
40
43
 
44
+ # The view helpers an Arbre tag was built with.
45
+ def arbre_helpers(tag) = tag.arbre_context.helpers
46
+
41
47
  # Has `tracer` see every tag's `build`, once.
42
48
  def trace_arbre_tags(tracer) = (::Arbre::HTML::Tag.prepend(tracer) unless ::Arbre::HTML::Tag.include?(tracer))
43
49
 
50
+ # Class names of the classic pages' components that HtmlNodes walks into typed nodes.
51
+ MARKUP = {
52
+ status_tag: "status_tag", empty: "empty", attributes_table: "attributes_table", panel: "panel",
53
+ panel_contents: "panel_contents", tabs: "tabs", nav_tabs: "nav-tabs", tab_content: "tab-content",
54
+ columns: "columns", column: "column", header_action: "header_action"
55
+ }.freeze
56
+ STRUCTURAL = MARKUP.values_at(:panel, :attributes_table, :tabs, :columns, :status_tag, :empty).freeze
57
+
58
+ def markup = MARKUP
59
+
60
+ # Containers whose children HtmlNodes must not flatten into a toolbar or pass through.
61
+ def structural_classes = STRUCTURAL
62
+
44
63
  # Where a classic page keeps its content, and the chrome the embed hides.
45
64
  def frame_content_selector = "#main_content"
46
65
 
@@ -10,6 +10,8 @@ module ReactiveAdmin
10
10
  require "reactive_admin/aa/v3/views"
11
11
  require "reactive_admin/aa/v3/menu"
12
12
  require "reactive_admin/aa/v3/forms"
13
+ require "reactive_admin/aa/v3/recorders"
14
+ require "reactive_admin/aa/v3/form_hooks"
13
15
 
14
16
  include Registry
15
17
  include Controller
@@ -51,6 +51,16 @@ module ReactiveAdmin
51
51
  # Private in AA 4.
52
52
  def find_value(view, record, attr) = view.send(:find_value, record, attr)
53
53
 
54
+ # AA 4 renames these and drops the tabs and columns components; the V3 names left for them never match.
55
+ MARKUP = V3::Views::MARKUP.merge(
56
+ status_tag: "status-tag", empty: "attributes-table-empty-value", attributes_table: "attributes-table", panel_contents: "panel-body"
57
+ ).freeze
58
+ STRUCTURAL = MARKUP.values_at(:panel, :attributes_table, :tabs, :columns, :status_tag, :empty).freeze
59
+
60
+ def markup = MARKUP
61
+
62
+ def structural_classes = STRUCTURAL
63
+
54
64
  def frame_content_selector = "[data-test-page-content]"
55
65
 
56
66
  def chrome_selectors = "[data-test-page-header], #main-menu, header"
@@ -5,7 +5,7 @@ module ReactiveAdmin
5
5
  # and view methods, inherited_resources ivars, Arbre and Formtastic classes. Everything else calls
6
6
  # intention-revealing methods here (`AA.scopes(config)`, `AA.resource_ivar(controller)`), so an AA
7
7
  # upgrade is a new implementation module, not a hunt through the gem. `aa_boundary_spec` fails when
8
- # an AA constant appears elsewhere in `lib` or `app`.
8
+ # an AA constant, Arbre or Formtastic method, or AA markup class name appears elsewhere in `lib` or `app`.
9
9
  #
10
10
  # `V3` implements AA 3.5; `V4` documents what changes for AA 4. The module is picked by
11
11
  # `ActiveAdmin::VERSION` when this file loads.
@@ -20,6 +20,7 @@ module ReactiveAdmin
20
20
  module AA
21
21
  autoload :V3, "reactive_admin/aa/v3"
22
22
  autoload :V4, "reactive_admin/aa/v4"
23
+ autoload :Input, "reactive_admin/aa/input"
23
24
 
24
25
  class << self
25
26
  def version = Gem::Version.new(::ActiveAdmin::VERSION)
@@ -16,6 +16,12 @@ module ReactiveAdmin
16
16
  ActiveSupport.on_load(:action_view) { prepend Provenance::Helpers }
17
17
  end
18
18
 
19
+ # Before the cookie and session middleware: the client's files are public and cacheable, so they must not set a
20
+ # cookie. A host static file server placed earlier still wins for files it has.
21
+ initializer "reactiveadmin.ui_assets" do |app|
22
+ app.middleware.insert_before ActionDispatch::Cookies, Ui::Assets::Middleware
23
+ end
24
+
19
25
  # Innermost, so the host's own middleware (CSP headers, host authorization) wraps the shell as it does any page.
20
26
  initializer "reactiveadmin.ui_shell" do |app|
21
27
  app.middleware.use Ui::Shell
@@ -143,7 +143,7 @@ module ReactiveAdmin
143
143
  # check_boxes input_name is already the whole param, brackets included, and its hidden input posts
144
144
  # under the method name even for an association (`category`, not `category_id`).
145
145
  def param(input, multiple)
146
- kind = AA.input_kind(input)
146
+ kind = input.kind
147
147
  return plain(input.input_name) if kind == :check_boxes
148
148
 
149
149
  name = (kind == :hidden) ? input.method : input.input_name
@@ -172,7 +172,7 @@ module ReactiveAdmin
172
172
 
173
173
  # Limits Formtastic derives from validations/columns, plus whatever the form block set explicitly.
174
174
  def input_html(input, control)
175
- derived = input.input_html_options.slice(*DERIVED_HTML.fetch(control, []))
175
+ derived = input.html_options.slice(*DERIVED_HTML.fetch(control, []))
176
176
  html = derived.merge(input.options[:input_html].to_h.slice(*DERIVED_HTML.values.flatten, :rows))
177
177
  html = html.merge(day_limits(input, html, control)) if DAY_CONTROLS.include?(control)
178
178
  html.compact_blank.presence
@@ -231,7 +231,7 @@ module ReactiveAdmin
231
231
 
232
232
  def current(input)
233
233
  object = @builder.object
234
- names = [(input.association_primary_key if input.respond_to?(:association_primary_key)), input.input_name, input.method]
234
+ names = [input.association_primary_key, input.input_name, input.method]
235
235
  name = names.find { (it.is_a?(Symbol) || it.is_a?(String)) && object.respond_to?(it) }
236
236
  object.public_send(name) if name
237
237
  end
@@ -1,16 +1,14 @@
1
1
  module ReactiveAdmin
2
2
  # Stands in for AA's ActiveAdminForm while a `form do |f| ... end` block runs: inputs are
3
3
  # recorded instead of rendered, and any other Arbre content (panels, paragraphs) is captured
4
- # as typed `content` fields between them (see FormContent). An Element for the same reason as IndexRecorder.
5
- class FormRecorder < AA.arbre_element
6
- Holder = Class.new(AA.arbre_element)
7
-
4
+ # as typed `content` fields between them (see FormContent).
5
+ class FormRecorder < AA.form_recorder_base
8
6
  NOOPS = %i[semantic_errors commit_action_with_cancel_link cancel_link].freeze
9
7
 
10
8
  attr_reader :builder, :sections
11
9
 
12
10
  def self.build(builder, schema, prefix: nil)
13
- AA.arbre_context(schema.assigns, schema.view).insert_tag(self, builder, schema, prefix)
11
+ build_in(schema.assigns, schema.view, builder, schema, prefix)
14
12
  end
15
13
 
16
14
  def build(builder, schema, prefix)
@@ -22,7 +20,7 @@ module ReactiveAdmin
22
20
  end
23
21
 
24
22
  def record(&block)
25
- within(self) do
23
+ render_within do
26
24
  instance_exec(self, &block)
27
25
  flush_html
28
26
  end
@@ -40,11 +38,11 @@ module ReactiveAdmin
40
38
  def actions(*, &block)
41
39
  return unless block
42
40
 
43
- holder = insert_tag(Holder) do
41
+ holder = add_holder do
44
42
  block.arity.zero? ? block.call : block.call(self)
45
43
  nil
46
44
  end
47
- holder.parent&.remove_child(holder)
45
+ detach(holder)
48
46
  rescue => e
49
47
  Rails.logger.warn("[reactiveadmin] #{@schema.config.resource_name} actions block skipped: #{e.class} at #{e.backtrace&.first}")
50
48
  end
@@ -102,7 +100,7 @@ module ReactiveAdmin
102
100
 
103
101
  # Content so far belongs in this spot: a marker says where, and `settle` fills the field once the
104
102
  # whole block has run (an element open around an input can't be walked before then).
105
- def flush_html(element = current_arbre_element)
103
+ def flush_html(element = open_element)
106
104
  return discard(element) unless @schema.content?
107
105
 
108
106
  id = (@cuts.size + 1).to_s
@@ -171,7 +169,7 @@ module ReactiveAdmin
171
169
 
172
170
  # Arbre content built by the block lands in a throwaway holder so it can be flushed in order.
173
171
  def collect
174
- insert_tag(Holder) do
172
+ add_holder do
175
173
  yield
176
174
  flush_html
177
175
  nil
@@ -13,7 +13,6 @@ module ReactiveAdmin
13
13
  SAFE_SCHEMES = %w[http https mailto tel].freeze
14
14
  TOOLBAR_TAGS = %w[div section].freeze
15
15
  PASSTHROUGH_TAGS = %w[div span section].freeze
16
- STRUCTURAL_CLASSES = %w[panel attributes_table tabs columns status_tag empty].freeze
17
16
 
18
17
  # `frame_src` is the classic URL the html came from: forms that PageForms did not record
19
18
  # (see its marker nodes) are kept as interactive frame nodes that submit relative to it.
@@ -62,15 +61,17 @@ module ReactiveAdmin
62
61
 
63
62
  private
64
63
 
64
+ def css = AA.markup
65
+
65
66
  def node(el)
66
67
  return text(el.text) if el.text? || el.cdata?
67
68
  return unless el.element?
68
69
 
69
70
  if el.name == "br"
70
71
  nil
71
- elsif el.name == "span" && el["class"].to_s.split.include?("status_tag")
72
+ elsif el.name == "span" && el["class"].to_s.split.include?(css[:status_tag])
72
73
  status(el)
73
- elsif el.name == "span" && el.classes.include?("empty")
74
+ elsif el.name == "span" && el.classes.include?(css[:empty])
74
75
  {type: "empty"}
75
76
  elsif el.name == "span" && el.classes.include?(Masking::CLASS_NAME)
76
77
  Masking::NODE
@@ -88,13 +89,13 @@ module ReactiveAdmin
88
89
  frame(el)
89
90
  elsif el.name == "a"
90
91
  link(el)
91
- elsif el.name == "div" && el.classes.include?("attributes_table")
92
+ elsif el.name == "div" && el.classes.include?(css[:attributes_table])
92
93
  attributes_table(el)
93
- elsif el.name == "div" && el.classes.include?("panel")
94
+ elsif el.name == "div" && el.classes.include?(css[:panel])
94
95
  panel(el)
95
- elsif el.name == "div" && el.classes.include?("tabs")
96
+ elsif el.name == "div" && el.classes.include?(css[:tabs])
96
97
  tabs(el)
97
- elsif el.name == "div" && el.classes.include?("columns")
98
+ elsif el.name == "div" && el.classes.include?(css[:columns])
98
99
  columns(el)
99
100
  elsif el.name == "table"
100
101
  table(el)
@@ -249,7 +250,7 @@ module ReactiveAdmin
249
250
  end
250
251
 
251
252
  def attributes_table(el)
252
- title = el.parent&.classes&.include?("panel_contents") ? panel_title(el.parent.parent) : nil
253
+ title = el.parent&.classes&.include?(css[:panel_contents]) ? panel_title(el.parent.parent) : nil
253
254
  rows = el.css("tr").map do |tr|
254
255
  {label: tr.at_css("th")&.text.to_s.strip, value: cell_nodes(tr.at_css("td"))}
255
256
  end
@@ -262,19 +263,19 @@ module ReactiveAdmin
262
263
  end
263
264
 
264
265
  def panel(el)
265
- contents = child(el, "panel_contents")
266
+ contents = child(el, css[:panel_contents])
266
267
  node = {type: "panel", title: panel_title(el), children: nodes((contents || el).inner_html)}
267
268
  (actions = header_actions(el)).present? ? node.merge(header_actions: actions) : node
268
269
  end
269
270
 
270
271
  def panel_title(panel)
271
272
  heading = panel&.element_children&.find { it.name == "h3" } or return
272
- heading.children.reject { it.element? && it.classes.include?("header_action") }.sum("") { it.text }.strip
273
+ heading.children.reject { it.element? && it.classes.include?(css[:header_action]) }.sum("") { it.text }.strip
273
274
  end
274
275
 
275
276
  # `header_action` renders a div inside the h3 per call. Anything but actions and links is dropped, with a note.
276
277
  def header_actions(panel)
277
- slots = panel.element_children.find { it.name == "h3" }&.element_children.to_a.select { it.classes.include?("header_action") }
278
+ slots = panel.element_children.find { it.name == "h3" }&.element_children.to_a.select { it.classes.include?(css[:header_action]) }
278
279
  slots.to_a.flat_map do |slot|
279
280
  toolbar_items(slot, [slot]) || begin
280
281
  HtmlPolicy.degrade(:panel_header_action, "Panel header action holds more than actions and links; not shown", where: @path.join("/"))
@@ -286,14 +287,14 @@ module ReactiveAdmin
286
287
  def child(el, class_name) = el.element_children.find { it.classes.include?(class_name) }
287
288
 
288
289
  def tabs(el)
289
- titles = child(el, "nav-tabs")&.element_children.to_a.map { it.text.strip }
290
- contents = child(el, "tab-content")&.element_children.to_a
290
+ titles = child(el, css[:nav_tabs])&.element_children.to_a.map { it.text.strip }
291
+ contents = child(el, css[:tab_content])&.element_children.to_a
291
292
  tabs = titles.zip(contents).map { |title, content| {type: "tab", title:, children: nodes(content&.inner_html)} }
292
293
  {type: "tabs", children: tabs}
293
294
  end
294
295
 
295
296
  def columns(el)
296
- columns = el.element_children.select { it.classes.include?("column") }
297
+ columns = el.element_children.select { it.classes.include?(css[:column]) }
297
298
  {type: "columns", children: columns.map { {type: "column", children: nodes(it.inner_html)} }}
298
299
  end
299
300
 
@@ -312,7 +313,7 @@ module ReactiveAdmin
312
313
  # A container holding only actions and links, however deeply wrapped. A width or a column
313
314
  # direction means it is laying out other content, so it stays a box.
314
315
  def toolbar(el)
315
- return unless TOOLBAR_TAGS.include?(el.name) && (STRUCTURAL_CLASSES & el.classes).empty?
316
+ return unless TOOLBAR_TAGS.include?(el.name) && (AA.structural_classes & el.classes).empty?
316
317
 
317
318
  wrappers = [el]
318
319
  items = toolbar_items(el, wrappers)
@@ -341,7 +342,7 @@ module ReactiveAdmin
341
342
  # An icon-only link with an unsafe href has no label to fall back on, so `link` gives nothing.
342
343
  node = link(el)
343
344
  [node] if node&.dig(:type) == "link"
344
- elsif PASSTHROUGH_TAGS.include?(el.name) && (STRUCTURAL_CLASSES & el.classes).empty?
345
+ elsif PASSTHROUGH_TAGS.include?(el.name) && (AA.structural_classes & el.classes).empty?
345
346
  wrappers << el
346
347
  toolbar_items(el, wrappers)
347
348
  end
@@ -1,15 +1,13 @@
1
1
  module ReactiveAdmin
2
2
  # Stands in for AA's IndexAsTable while the `index do ... end` block runs, capturing columns
3
- # and rendering cells the way TableFor#build_table_cell does. An Element (not a Context):
4
- # Contexts forward unknown methods to their html string, which would swallow helpers like
5
- # `truncate` that column blocks call.
6
- class IndexRecorder < AA.arbre_element
3
+ # and rendering cells the way TableFor#build_table_cell does.
4
+ class IndexRecorder < AA.index_recorder_base
7
5
  Column = AA.table_column_class
8
6
 
9
7
  attr_reader :columns, :row_options
10
8
 
11
9
  def self.build(resource_class, assigns, helpers)
12
- AA.arbre_context(assigns, helpers).insert_tag(self, resource_class)
10
+ build_in(assigns, helpers, resource_class)
13
11
  end
14
12
 
15
13
  def build(resource_class)
@@ -79,21 +77,21 @@ module ReactiveAdmin
79
77
 
80
78
  # Renders a row's custom `item`s the way IndexTableFor#actions does.
81
79
  def render_row_items(record)
82
- items = table_actions do
80
+ items = action_links do
83
81
  result = instance_exec(record, &@row_items)
84
82
  text_node result unless AA.arbre_element?(result)
85
83
  end
86
- items.to_s.tap { items.parent&.remove_child(items) }
84
+ items.to_s.tap { detach(items) }
87
85
  end
88
86
 
89
87
  # A grid or block view's item, or a blog or custom view's whole output for one record.
90
88
  def render_item(record, views)
91
89
  item = if views.custom? || views.kind == "blog"
92
- insert_tag(views.renderer, views.presenter, [record])
90
+ add_tag(views.renderer, views.presenter, [record])
93
91
  else
94
92
  div { instance_exec(record, &views.presenter.block) }
95
93
  end
96
- html = item.to_s.tap { item.parent&.remove_child(item) }
94
+ html = item.to_s.tap { detach(item) }
97
95
  strip_selection(html)
98
96
  end
99
97
 
@@ -107,9 +105,9 @@ module ReactiveAdmin
107
105
  def render_cell(record, col)
108
106
  cell = td do
109
107
  html = AA.format_attribute(helpers, record, col.data)
110
- current_arbre_element << html unless current_arbre_element.children.include?(html)
108
+ open_element << html unless open_element.children.include?(html)
111
109
  end
112
- cell.children.to_s.tap { cell.parent&.remove_child(cell) }
110
+ cell.children.to_s.tap { detach(cell) }
113
111
  end
114
112
  end
115
113
  end
@@ -64,9 +64,9 @@ module ReactiveAdmin
64
64
  add(Paths.api("#{prefix}#{@key}/#{name}"), verb, operation(
65
65
  id: id("#{camel(@key).camelize(:lower)}#{camel(name)}#{suffix}"), summary: "#{name.humanize} (page action)", tags:, write: !get,
66
66
  parameters: [*parameters, *([form_query_param] if get && Ladder.action(@page, name)&.get_form)],
67
- description: get ? "Answers the action's template as a form." : "Page action `#{name}`, usually the target of a form in the page's content. The redirect and flash become the result; an alert answers 422.",
67
+ description: get ? "Answers the action's template as a form or as its content, or its redirect as the result." : "Page action `#{name}`, usually the target of a form in the page's content. The redirect and flash become the result; an alert answers 422.",
68
68
  request_body: (ref("requestBodies", "ActionParams") unless get),
69
- responses: {200 => get ? shared("FormOk") : ref("responses", "ActionResult")},
69
+ responses: action_responses(get),
70
70
  errors: [403, *(422 unless get)]
71
71
  ), names: [name])
72
72
  end
@@ -60,6 +60,9 @@ module ReactiveAdmin
60
60
  {"x-reactiveadmin-session-only": (true if ApiGuards.session_only?(config, names)), "x-reactiveadmin-guard": custom&.name}.compact
61
61
  end
62
62
 
63
+ # As core.yaml declares for runMemberActionGet and its writes.
64
+ def action_responses(get) = {200 => shared(get ? "ActionGet" : "ActionWrite"), 501 => shared("Unsupported")}
65
+
63
66
  # Verbs of a declared action (`member_action :x, method: [:get, :post]`).
64
67
  def verbs_of(declaration)
65
68
  Array.wrap(declaration.http_verb).map { it.to_s.downcase } & VERBS
@@ -279,18 +279,11 @@ module ReactiveAdmin
279
279
  end
280
280
 
281
281
  def action_note(get)
282
- return "Answers the action's template as a form, or 501 `unsupported` when it renders an html page (use the classic admin)." if get
282
+ return "Answers the action's template as a form or as its content, its redirect as the result, or 501 `unsupported` when it renders an html page (use the classic admin)." if get
283
283
 
284
284
  "The action's redirect and flash become the result; an alert or errors answer 422."
285
285
  end
286
286
 
287
- def action_responses(get)
288
- return {200 => ref("responses", "ActionResult")} unless get
289
-
290
- {200 => shared("FormOk"),
291
- 501 => {description: "The action renders an html page the API can't describe (`unsupported`).", content: json(schema_ref("Error"))}}
292
- end
293
-
294
287
  def action_errors(get, verb, member) = [403, *(404 if member), *(422 unless get), *(409 if %w[put patch].include?(verb))]
295
288
 
296
289
  def batch
@@ -6,35 +6,12 @@ module ReactiveAdmin
6
6
  class PageForms
7
7
  Recorded = Struct.new(:response, :choices)
8
8
 
9
- # Mixed into the view that renders the content, ahead of TemplateForm::Recording.
10
- module Recording
11
- def semantic_form_for(*args, &block)
12
- forms = reactiveadmin_page_forms or return super
13
- forms.node(self) { super(*args, &block) } || forms.suspended { super(*args, &block) }
14
- end
15
-
16
- def active_admin_form_for(*args, &block)
17
- forms = reactiveadmin_page_forms or return super
18
- forms.node(self) { super(*args, &block) } || forms.suspended { super(*args, &block) }
19
- end
20
-
21
- def reactiveadmin_page_forms = @_reactiveadmin_page_forms
22
- end
23
-
24
- # For Arbre content: `active_admin_form_for` there is an Arbre component, not the view helper.
25
- module ArbreForms
26
- def active_admin_form_for(*args, &block)
27
- forms = helpers.try(:reactiveadmin_page_forms) or return super
28
- marker = forms.node(helpers) { helpers.active_admin_form_for(*args, &block) }
29
- marker ? text_node(marker) : forms.suspended { super(*args, &block) }
30
- end
31
- end
32
-
33
9
  # Runs the block with the view's forms recording, and returns what was recorded.
34
10
  def self.recording(view, controller, controls_only: false)
35
11
  forms = new(controller, controls_only:)
36
- view.extend(TemplateForm::Recording)
37
- view.extend(Recording)
12
+ # Page hooks go on last so they run ahead of the template's.
13
+ view.extend(AA.template_form_hooks)
14
+ view.extend(AA.page_form_hooks)
38
15
  view.instance_variable_set(:@_reactiveadmin_page_forms, forms)
39
16
  yield
40
17
  forms
@@ -3,9 +3,7 @@ module ReactiveAdmin
3
3
  # and the GET page actions that render something. Sidebars are not carried.
4
4
  class PagePayload
5
5
  # Arbre context that runs the content block the way ActiveAdmin::Views::Pages::Page does.
6
- class Content < AA.arbre_element
7
- include PageForms::ArbreForms
8
- end
6
+ class Content < AA.page_element_base; end
9
7
 
10
8
  def initialize(controller)
11
9
  @controller = controller
@@ -92,14 +90,14 @@ module ReactiveAdmin
92
90
  def render_content(forms: true, controls_only: false)
93
91
  return "" unless presenter&.block
94
92
 
95
- context = AA.arbre_context(@controller.view_assigns, @view)
96
- render = -> { context.insert_tag(Content).instance_exec(&presenter.block) }
93
+ content = Content.build_in(@controller.view_assigns, @view)
94
+ render = -> { content.instance_exec(&presenter.block) }
97
95
  if forms
98
96
  @forms = PageForms.recording(@view, @controller, controls_only:, &render)
99
97
  else
100
98
  render.call
101
99
  end
102
- context.to_s
100
+ content.document_html
103
101
  end
104
102
 
105
103
  # Only GETs: a page action that writes is the target of a form in the content.