reactiveadmin 0.2.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/app/assets/reactive_admin/bridge.js +89 -0
- data/app/controllers/reactive_admin/api_controller.rb +30 -0
- data/app/controllers/reactive_admin/client_errors_controller.rb +38 -0
- data/app/controllers/reactive_admin/manifest_controller.rb +10 -0
- data/app/controllers/reactive_admin/mcp_controller.rb +48 -0
- data/app/controllers/reactive_admin/openapi_controller.rb +13 -0
- data/app/controllers/reactive_admin/session_controller.rb +11 -0
- data/app/views/layouts/reactive_admin/embed.html.erb +30 -0
- data/lib/generators/reactiveadmin/install/install_generator.rb +341 -0
- data/lib/generators/reactiveadmin/install/templates/menu.rb.tt +25 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin.rb.tt +53 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin_annotated.rb.tt +110 -0
- data/lib/reactive_admin/aa/v3/controller.rb +76 -0
- data/lib/reactive_admin/aa/v3/forms.rb +29 -0
- data/lib/reactive_admin/aa/v3/inputs/filters/typeahead_input.rb +51 -0
- data/lib/reactive_admin/aa/v3/inputs/typeahead_input.rb +8 -0
- data/lib/reactive_admin/aa/v3/install.rb +36 -0
- data/lib/reactive_admin/aa/v3/menu.rb +67 -0
- data/lib/reactive_admin/aa/v3/presenters.rb +102 -0
- data/lib/reactive_admin/aa/v3/registry.rb +78 -0
- data/lib/reactive_admin/aa/v3/views.rb +63 -0
- data/lib/reactive_admin/aa/v3.rb +23 -0
- data/lib/reactive_admin/aa/v4.rb +59 -0
- data/lib/reactive_admin/aa.rb +46 -0
- data/lib/reactive_admin/action_items.rb +39 -0
- data/lib/reactive_admin/action_links.rb +197 -0
- data/lib/reactive_admin/action_safety.rb +19 -0
- data/lib/reactive_admin/actions.rb +95 -0
- data/lib/reactive_admin/api_errors.rb +116 -0
- data/lib/reactive_admin/api_fallback.rb +15 -0
- data/lib/reactive_admin/api_guards.rb +445 -0
- data/lib/reactive_admin/audit.rb +72 -0
- data/lib/reactive_admin/auth/guard.rb +68 -0
- data/lib/reactive_admin/auth/token_requests.rb +15 -0
- data/lib/reactive_admin/auth.rb +135 -0
- data/lib/reactive_admin/authorizer.rb +47 -0
- data/lib/reactive_admin/background_requests.rb +33 -0
- data/lib/reactive_admin/batch_actions.rb +57 -0
- data/lib/reactive_admin/choices.rb +289 -0
- data/lib/reactive_admin/client_error.rb +70 -0
- data/lib/reactive_admin/composite_keys.rb +12 -0
- data/lib/reactive_admin/configuration.rb +221 -0
- data/lib/reactive_admin/controller_extension.rb +229 -0
- data/lib/reactive_admin/csv_injection.rb +26 -0
- data/lib/reactive_admin/date_bound.rb +31 -0
- data/lib/reactive_admin/degradation.rb +72 -0
- data/lib/reactive_admin/diagnostics.rb +16 -0
- data/lib/reactive_admin/doctor.rb +466 -0
- data/lib/reactive_admin/dry_run.rb +147 -0
- data/lib/reactive_admin/dry_run_flag.rb +18 -0
- data/lib/reactive_admin/embed.rb +73 -0
- data/lib/reactive_admin/engine.rb +47 -0
- data/lib/reactive_admin/error_keys.rb +23 -0
- data/lib/reactive_admin/exposure.rb +86 -0
- data/lib/reactive_admin/filters.rb +165 -0
- data/lib/reactive_admin/fixtures/scrubber.rb +1075 -0
- data/lib/reactive_admin/fixtures.rb +161 -0
- data/lib/reactive_admin/form_content.rb +78 -0
- data/lib/reactive_admin/form_field.rb +279 -0
- data/lib/reactive_admin/form_has_many.rb +116 -0
- data/lib/reactive_admin/form_lock.rb +71 -0
- data/lib/reactive_admin/form_payload.rb +57 -0
- data/lib/reactive_admin/form_recorder.rb +192 -0
- data/lib/reactive_admin/form_schema.rb +160 -0
- data/lib/reactive_admin/frame.rb +97 -0
- data/lib/reactive_admin/html_nodes.rb +390 -0
- data/lib/reactive_admin/html_policy.rb +338 -0
- data/lib/reactive_admin/html_rich.rb +186 -0
- data/lib/reactive_admin/implicit_defaults.rb +102 -0
- data/lib/reactive_admin/index_options.rb +41 -0
- data/lib/reactive_admin/index_payload.rb +259 -0
- data/lib/reactive_admin/index_recorder.rb +115 -0
- data/lib/reactive_admin/index_views.rb +85 -0
- data/lib/reactive_admin/inline_style.rb +125 -0
- data/lib/reactive_admin/labels_payload.rb +34 -0
- data/lib/reactive_admin/ladder.rb +268 -0
- data/lib/reactive_admin/layout_classes.rb +167 -0
- data/lib/reactive_admin/legacy_inventory.rb +547 -0
- data/lib/reactive_admin/location.rb +22 -0
- data/lib/reactive_admin/lookup_audit.rb +30 -0
- data/lib/reactive_admin/lookup_payload.rb +41 -0
- data/lib/reactive_admin/manifest.rb +36 -0
- data/lib/reactive_admin/masked_json.rb +62 -0
- data/lib/reactive_admin/masking.rb +100 -0
- data/lib/reactive_admin/mcp/access.rb +111 -0
- data/lib/reactive_admin/mcp/api.rb +123 -0
- data/lib/reactive_admin/mcp/count_tool.rb +22 -0
- data/lib/reactive_admin/mcp/layout.rb +175 -0
- data/lib/reactive_admin/mcp/output.rb +46 -0
- data/lib/reactive_admin/mcp/prompts.rb +111 -0
- data/lib/reactive_admin/mcp/server.rb +134 -0
- data/lib/reactive_admin/mcp/shapes.rb +164 -0
- data/lib/reactive_admin/mcp/tools.rb +386 -0
- data/lib/reactive_admin/mcp.rb +53 -0
- data/lib/reactive_admin/media_nodes.rb +34 -0
- data/lib/reactive_admin/menu.rb +90 -0
- data/lib/reactive_admin/menu_overlay.rb +291 -0
- data/lib/reactive_admin/node_registry.rb +47 -0
- data/lib/reactive_admin/open_api/builder.rb +156 -0
- data/lib/reactive_admin/open_api/context.rb +46 -0
- data/lib/reactive_admin/open_api/core.rb +51 -0
- data/lib/reactive_admin/open_api/operation_ids.rb +18 -0
- data/lib/reactive_admin/open_api/page_doc.rb +75 -0
- data/lib/reactive_admin/open_api/parts.rb +86 -0
- data/lib/reactive_admin/open_api/resource_doc.rb +423 -0
- data/lib/reactive_admin/open_api/security.rb +55 -0
- data/lib/reactive_admin/open_api/write_schema.rb +104 -0
- data/lib/reactive_admin/open_api.rb +41 -0
- data/lib/reactive_admin/option_source.rb +36 -0
- data/lib/reactive_admin/option_sources.rb +14 -0
- data/lib/reactive_admin/options_payload.rb +61 -0
- data/lib/reactive_admin/page_controller_extension.rb +112 -0
- data/lib/reactive_admin/page_forms.rb +181 -0
- data/lib/reactive_admin/page_payload.rb +120 -0
- data/lib/reactive_admin/param_normalizer.rb +89 -0
- data/lib/reactive_admin/paths.rb +63 -0
- data/lib/reactive_admin/permissions.rb +31 -0
- data/lib/reactive_admin/provenance.rb +57 -0
- data/lib/reactive_admin/query_guard.rb +108 -0
- data/lib/reactive_admin/ransack_guard.rb +107 -0
- data/lib/reactive_admin/rate_limit.rb +59 -0
- data/lib/reactive_admin/reactive_dsl.rb +99 -0
- data/lib/reactive_admin/readiness.rb +189 -0
- data/lib/reactive_admin/registry.rb +69 -0
- data/lib/reactive_admin/resource_meta.rb +120 -0
- data/lib/reactive_admin/resource_summary.rb +41 -0
- data/lib/reactive_admin/routes.rb +60 -0
- data/lib/reactive_admin/row_errors.rb +29 -0
- data/lib/reactive_admin/rspec.rb +116 -0
- data/lib/reactive_admin/scrubbed_error.rb +22 -0
- data/lib/reactive_admin/search.rb +79 -0
- data/lib/reactive_admin/server_timing.rb +31 -0
- data/lib/reactive_admin/show_payload.rb +88 -0
- data/lib/reactive_admin/sidebars.rb +34 -0
- data/lib/reactive_admin/site.rb +55 -0
- data/lib/reactive_admin/style_report.rb +129 -0
- data/lib/reactive_admin/style_sources.rb +83 -0
- data/lib/reactive_admin/template_actions.rb +126 -0
- data/lib/reactive_admin/template_content.rb +49 -0
- data/lib/reactive_admin/template_form.rb +442 -0
- data/lib/reactive_admin/test_support.rb +31 -0
- data/lib/reactive_admin/typeahead.rb +33 -0
- data/lib/reactive_admin/ui/assets.rb +91 -0
- data/lib/reactive_admin/ui/client_build.rb +47 -0
- data/lib/reactive_admin/ui/helper.rb +24 -0
- data/lib/reactive_admin/ui/packaged_client.rb +67 -0
- data/lib/reactive_admin/ui/shell.rb +81 -0
- data/lib/reactive_admin/ui/switch.rb +38 -0
- data/lib/reactive_admin/ui.rb +43 -0
- data/lib/reactive_admin/value_payload.rb +147 -0
- data/lib/reactive_admin/value_token.rb +36 -0
- data/lib/reactive_admin/values.rb +43 -0
- data/lib/reactive_admin/version.rb +3 -0
- data/lib/reactive_admin/write_audit.rb +60 -0
- data/lib/reactive_admin/write_guards.rb +142 -0
- data/lib/reactive_admin.rb +153 -0
- data/lib/reactiveadmin.rb +1 -0
- data/lib/tasks/reactiveadmin.rake +36 -0
- data/lib/tasks/reactiveadmin_client.rake +11 -0
- data/lib/tasks/reactiveadmin_legacy.rake +7 -0
- data/lib/tasks/reactiveadmin_styles.rake +6 -0
- data/openapi/core.yaml +1643 -0
- data/vendor/client/assets/ActionPage-XUYorI8E.js +1 -0
- data/vendor/client/assets/ActionView-BsZFcsgp.js +1 -0
- data/vendor/client/assets/CommandPalette-C59HT1ip.js +1 -0
- data/vendor/client/assets/DatePicker-DuaK0iMg.js +1 -0
- data/vendor/client/assets/DateRangeCalendar-B2BDsG-X.js +1 -0
- data/vendor/client/assets/DegradedNotice-DiH5n2DO.js +1 -0
- data/vendor/client/assets/FormDialog-pmYl8Eov.js +1 -0
- data/vendor/client/assets/FormSkeleton-DuSBZO3C.js +1 -0
- data/vendor/client/assets/FrameView-2X8cFvUt.css +1 -0
- data/vendor/client/assets/FrameView-zmUeDO8d.js +1 -0
- data/vendor/client/assets/GroupOverview-DI5T3k5K.js +1 -0
- data/vendor/client/assets/InlineForm-CMEIMgeh.js +1 -0
- data/vendor/client/assets/JsonDiff-o7JWr7CH.js +3 -0
- data/vendor/client/assets/JsonEditor-D4VXdlEx.js +1 -0
- data/vendor/client/assets/JsonView-BrJLDmSN.js +1 -0
- data/vendor/client/assets/MobileMenu-GAeFOeEb.js +1 -0
- data/vendor/client/assets/Node-SQl61V4K.js +2 -0
- data/vendor/client/assets/PageView-C-laNEPZ.js +1 -0
- data/vendor/client/assets/ResourceForm-BPjsoCY6.js +1 -0
- data/vendor/client/assets/ResourceIndex-COezAw5t.js +3 -0
- data/vendor/client/assets/ResourceOrPage-CRZGCY84.js +1 -0
- data/vendor/client/assets/ResourceShow-DweRXn18.js +1 -0
- data/vendor/client/assets/Segmented-BE9TCbph.js +1 -0
- data/vendor/client/assets/Sidebars-CsB9rFqX.js +1 -0
- data/vendor/client/assets/breadcrumb-DSA3Tlyd.js +1 -0
- data/vendor/client/assets/button-CvZ4_DFC.js +1 -0
- data/vendor/client/assets/calendar-BoyMpJIf.js +1 -0
- data/vendor/client/assets/check-C5A3J16N.js +1 -0
- data/vendor/client/assets/command-CMuk0oAt.js +1 -0
- data/vendor/client/assets/dist-CqEI82S_.js +1 -0
- data/vendor/client/assets/dist-IW4yX942.js +1 -0
- data/vendor/client/assets/editor-yqRLzgsJ.js +2 -0
- data/vendor/client/assets/external-link-C2aR4slL.js +1 -0
- data/vendor/client/assets/frames-C9gPCc3N.js +1 -0
- data/vendor/client/assets/humanize-DtU_Kpr4.js +1 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- data/vendor/client/assets/index-B51aUaAY.js +43 -0
- data/vendor/client/assets/index-Cs9rCoWM.css +2 -0
- data/vendor/client/assets/input-DByFmQPa.js +1 -0
- data/vendor/client/assets/json-De3PN-R6.css +1 -0
- data/vendor/client/assets/json-oTp7Q-d-.js +5 -0
- data/vendor/client/assets/media-D4a_En8R.js +1 -0
- data/vendor/client/assets/plus-CfJ9vo8X.js +1 -0
- data/vendor/client/assets/popover-CDtI9R8Q.js +1 -0
- data/vendor/client/assets/purify-G7QKJyJq.js +1 -0
- data/vendor/client/assets/query-CCsZN2fa.js +1 -0
- data/vendor/client/assets/recent-BrzLwL0D.js +1 -0
- data/vendor/client/assets/rich-BQc_q5T7.js +1 -0
- data/vendor/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- data/vendor/client/assets/select-C43qDA3k.js +1 -0
- data/vendor/client/assets/sheet-BPl2n-4n.js +1 -0
- data/vendor/client/assets/textarea-BnOphXry.js +1 -0
- data/vendor/client/assets/uiMode-z0ZbRV49.js +1 -0
- data/vendor/client/assets/uiToggle-DwnRQTH1.js +1 -0
- data/vendor/client/assets/useRecordForm-X_DExEP2.js +1 -0
- data/vendor/client/assets/useRecordVisit-BRtfMi-q.js +1 -0
- data/vendor/client/assets/utils-DwBGbDkG.js +1 -0
- data/vendor/client/assets/vendor-calendar-nTZiq9oY.js +1 -0
- data/vendor/client/assets/vendor-datefns-BoC6MCnl.js +1 -0
- data/vendor/client/assets/vendor-forms-D0h8hG_S.js +55 -0
- data/vendor/client/assets/vendor-purify-BXoPR7WT.js +3 -0
- data/vendor/client/assets/vendor-query-DZ6APRNI.js +1 -0
- data/vendor/client/assets/vendor-react-C1iE8mnY.js +9 -0
- data/vendor/client/assets/vendor-router-CI6Vh4k_.js +1 -0
- data/vendor/client/assets/vendor-table-DuQ835by.js +4 -0
- data/vendor/client/index.html +24 -0
- data/vendor/client/manifest.json +867 -0
- data/vendor/client/reactiveadmin-client.json +4 -0
- metadata +350 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Decides how a custom view reaches the client, best first: native (a typed FormResponse) >
|
|
3
|
+
# frame (layout-less html over the wire) > iframe (the page needs its own JS) > custom (a host
|
|
4
|
+
# React component). Decisions come from the view source, so they are cheap and need no request;
|
|
5
|
+
# `reactive { render_as ... }` overrides them.
|
|
6
|
+
module Ladder
|
|
7
|
+
MODES = %w[native frame iframe custom].freeze
|
|
8
|
+
RANK = {"native" => 0, "custom" => 0, "frame" => 1, "iframe" => 2}.freeze
|
|
9
|
+
DIALOG_FIELDS = 6
|
|
10
|
+
|
|
11
|
+
SCRIPT = /<script\b|<iframe\b|\bjavascript_(?:tag|include_tag|pack_tag)\b|data-controller|data:\s*\{[^}]*\bcontroller:|\sremote:\s*true|href=["']javascript:|[\s,{(]on(?:click|change|submit|input|focus|blur|load|key\w+|mouse\w+)\s*(?:=|:|=>)/i
|
|
12
|
+
RAW_CONTROLS = /<(?:form|input|select|textarea|button|fieldset)\b|\b(?:form_tag|form_with|submit_tag|select_tag|label_tag|\w+_field_tag|\w+_box_tag|collection_select|radio_button_tag)\b|(?<!\w)form_for\b/
|
|
13
|
+
# Controls that act (a single-button form, a rails-ujs link) become typed action nodes, which map to the API
|
|
14
|
+
# per route at render time and are listed as unavailable when they don't.
|
|
15
|
+
ACTION_CONTROLS = /\bbutton_to\b|link_to[^\n]*(?:method:|confirm)/
|
|
16
|
+
FORM_FOR = /\b(?:semantic_form_for|active_admin_form_for)\b/
|
|
17
|
+
GET_FORM = /\bmethod(?::|\s*=>)\s*(?::get\b|["']get["'])/
|
|
18
|
+
SIMPLE_TAGS = %w[h1 h2 h3 h4 h5 h6 p div span br hr a strong em b i small ul ol li section table thead tbody tfoot tr th td caption].freeze
|
|
19
|
+
BUILDER_METHODS = %w[input inputs semantic_fields_for actions action submit commit_action_with_cancel_link cancel_link semantic_errors object].freeze
|
|
20
|
+
RENDER = /\brender\s*\(?\s*(?<kind>partial:\s*|template:\s*|action:\s*)?(?::(?<sym>\w+)|["'](?<name>[\w\/-]+)["'])/
|
|
21
|
+
|
|
22
|
+
# `wide`: the template shows more than a form (further forms, actions, tables), which needs a page.
|
|
23
|
+
# `read_only`: native without a form; the content is answered as a PageResponse of typed nodes.
|
|
24
|
+
# `get_form`: a GET form among them (filters over results), read from the query string of the same view.
|
|
25
|
+
Decision = Data.define(:mode, :reason, :template, :custom_key, :fields, :wide, :read_only, :get_form) do
|
|
26
|
+
def initialize(mode:, reason:, template:, custom_key:, fields:, wide: false, read_only: false, get_form: false) = super
|
|
27
|
+
|
|
28
|
+
def native? = mode == "native"
|
|
29
|
+
|
|
30
|
+
def presentation = (native? && fields <= DIALOG_FIELDS && !wide && !read_only) ? "dialog" : "page"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
module_function
|
|
34
|
+
|
|
35
|
+
# An action's decision, or nil when it renders no page (it redirects, sends data or renders json).
|
|
36
|
+
def action(config, name)
|
|
37
|
+
return unless declared?(config, name)
|
|
38
|
+
|
|
39
|
+
remember([config, name.to_s]) do
|
|
40
|
+
override = override_for(config, name)
|
|
41
|
+
next custom(override) if override&.fetch(:mode) == "custom"
|
|
42
|
+
|
|
43
|
+
template = template_for(config, name)
|
|
44
|
+
overridden(template(config, template), override) if template
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Member and collection actions of a resource, page actions of a page; AA's own are not views.
|
|
49
|
+
def declared?(config, name)
|
|
50
|
+
AA.custom_actions(config).any? { it.name.to_s == name.to_s }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def reset!
|
|
54
|
+
@decisions = nil
|
|
55
|
+
@downgraded = nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Templates that failed to record are decided as frames until the next reset.
|
|
59
|
+
def downgrade!(path)
|
|
60
|
+
(@downgraded ||= Set.new) << path.to_s
|
|
61
|
+
@decisions = nil
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Reading view source is cheap but not free; code only changes with a reload.
|
|
65
|
+
def remember(key)
|
|
66
|
+
return yield if Rails.application.config.enable_reloading
|
|
67
|
+
|
|
68
|
+
cache = (@decisions ||= {})
|
|
69
|
+
cache.key?(key) ? cache[key] : (cache[key] = yield)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# The same for a template named by a render call, e.g. the re-render after a failed write.
|
|
73
|
+
def for_template(config, path)
|
|
74
|
+
override = override_for(config, File.basename(path))
|
|
75
|
+
return custom(override) if override&.fetch(:mode) == "custom"
|
|
76
|
+
|
|
77
|
+
overridden(template(config, path), override)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Decision for a template (and the partials it renders) given by name, e.g. "approve".
|
|
81
|
+
def template(config, name)
|
|
82
|
+
return Decision.new("frame", "recording failed", name, nil, 0) if @downgraded&.include?(name.to_s)
|
|
83
|
+
|
|
84
|
+
sources = sources_for(config, name)
|
|
85
|
+
return Decision.new("frame", "template not found", name, nil, 0) if sources.empty?
|
|
86
|
+
|
|
87
|
+
decide(sources.map(&:last), name)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# The page's `content` block, plus the partials it renders.
|
|
91
|
+
def page(config)
|
|
92
|
+
override = override(config, "*")
|
|
93
|
+
return custom(override) if override&.fetch(:mode) == "custom"
|
|
94
|
+
|
|
95
|
+
content = block_source(AA.page_presenter(config, :index)&.block).to_s
|
|
96
|
+
overridden(decide_page([content, *partial_texts(config, content)]), override)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def script?(text) = SCRIPT.match?(text.to_s)
|
|
100
|
+
|
|
101
|
+
# Where a client (or the frame) loads the classic page; iframes get the chrome-free layout.
|
|
102
|
+
def view(config, name, href:)
|
|
103
|
+
decision = action(config, name) or return
|
|
104
|
+
path = case decision.mode
|
|
105
|
+
when "native" then Paths.api(href)
|
|
106
|
+
when "frame" then href
|
|
107
|
+
when "iframe" then embed_url(href)
|
|
108
|
+
end
|
|
109
|
+
{mode: decision.mode, path:, custom_key: decision.custom_key, presentation: decision.presentation}.compact
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# A page's index is always fetched as a PageResponse, whose nodes carry any frames and iframes.
|
|
113
|
+
def page_view(config, href:)
|
|
114
|
+
decision = page(config)
|
|
115
|
+
return {mode: "custom", custom_key: decision.custom_key, presentation: "page"}.compact if decision.mode == "custom"
|
|
116
|
+
|
|
117
|
+
{mode: "native", path: Paths.api(page_path(config, href)), presentation: "page"}
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# `/admin/key?x=1` is served as a PageResponse at `/admin/_pages/key?x=1`, under its parent when nested.
|
|
121
|
+
# The key comes from the config because the root page (dashboard) is also reachable at `/admin`.
|
|
122
|
+
def page_path(config, href)
|
|
123
|
+
path, query = href.split("?", 2)
|
|
124
|
+
key = config.underscored_resource_name
|
|
125
|
+
base = path.chomp("/").delete_suffix("/#{key}")
|
|
126
|
+
["#{base}/_pages/#{key}", query].compact.join("?")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def embed_url(href) = href + (href.include?("?") ? "&" : "?") + "embed=1"
|
|
130
|
+
|
|
131
|
+
def page_key_for(url)
|
|
132
|
+
return unless url&.start_with?("/")
|
|
133
|
+
|
|
134
|
+
route = Rails.application.routes.recognize_path(url)
|
|
135
|
+
page_config = Registry.page_for_controller_path(route[:controller])
|
|
136
|
+
page_config&.underscored_resource_name if route[:action] == "index"
|
|
137
|
+
rescue ActionController::RoutingError
|
|
138
|
+
nil
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def override(config, name) = config.try(:reactive_options)&.dig(:render_as)&.[](name.to_s)
|
|
142
|
+
|
|
143
|
+
def override_for(config, name) = override(config, name) || (override(config, "*") if AA.resource?(config))
|
|
144
|
+
|
|
145
|
+
def custom(override) = Decision.new("custom", "render_as custom", nil, override[:custom_key], 0)
|
|
146
|
+
|
|
147
|
+
def overridden(decision, override)
|
|
148
|
+
override ? decision.with(mode: override[:mode], reason: "render_as #{override[:mode]}") : decision
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def template_for(config, name)
|
|
152
|
+
controller_path = config.controller.controller_path
|
|
153
|
+
return "#{controller_path}/#{name}" if lookup.exists?(name.to_s, [controller_path], false, [], formats: [:html])
|
|
154
|
+
|
|
155
|
+
explicit_template(config, name)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# An action that renders another template by name: `render :approve`, `render "admin/x/y", layout: ...`.
|
|
159
|
+
def explicit_template(config, name)
|
|
160
|
+
return unless config.controller.method_defined?(name.to_sym)
|
|
161
|
+
|
|
162
|
+
location = config.controller.instance_method(name.to_sym).source_location or return
|
|
163
|
+
match = renders(block_at(*location)).find { it[:kind].nil? || it[:kind].start_with?("template", "action") } or return
|
|
164
|
+
target = (match[:sym] || match[:name]).to_s
|
|
165
|
+
target.include?("/") ? target : "#{config.controller.controller_path}/#{target}"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def renders(text) = text.to_enum(:scan, RENDER).map { Regexp.last_match }
|
|
169
|
+
|
|
170
|
+
def decide(texts, name)
|
|
171
|
+
all = texts.join("\n")
|
|
172
|
+
markup = strip_erb(all)
|
|
173
|
+
forms = all.scan(FORM_FOR).size
|
|
174
|
+
read_only = forms.zero? && !all.match?(RAW_CONTROLS) && !all.match?(ACTION_CONTROLS)
|
|
175
|
+
get = forms.positive? && all.match?(GET_FORM)
|
|
176
|
+
reason = if (match = all[SCRIPT]) then ["iframe", "needs the page's own JS (#{match.strip})"]
|
|
177
|
+
elsif read_only then ["native", "read-only markup"]
|
|
178
|
+
elsif forms.zero? then ["frame", "no Formtastic form"]
|
|
179
|
+
elsif (match = markup[RAW_CONTROLS] || all[RAW_CONTROLS]) then ["frame", "raw form controls (#{match.strip.first(30)})"]
|
|
180
|
+
elsif (tag = other_tags(markup).first) then ["frame", "markup beyond simple wrappers (<#{tag}>)"]
|
|
181
|
+
elsif (call = builder_misuse(all).first) then ["frame", "form builder call #{call}"]
|
|
182
|
+
else
|
|
183
|
+
["native", get ? "Formtastic GET form (filters and results)" : "Formtastic-only form"]
|
|
184
|
+
end
|
|
185
|
+
get_form = get && reason[0] == "native"
|
|
186
|
+
wide = get_form || forms > 1 || all.match?(ACTION_CONTROLS) || markup.match?(/<table\b/) || all.match?(/\btable_for\b/)
|
|
187
|
+
Decision.new(mode: reason[0], reason: reason[1], template: name, custom_key: nil, fields: all.scan(/\.input\s*[(:]/).size, wide:, read_only: read_only && reason[0] == "native", get_form:)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def decide_page(texts)
|
|
191
|
+
all = texts.join("\n")
|
|
192
|
+
if (match = all[SCRIPT])
|
|
193
|
+
Decision.new("iframe", "needs the page's own JS (#{match.strip})", nil, nil, 0)
|
|
194
|
+
elsif all.match?(RAW_CONTROLS) || all.match?(ACTION_CONTROLS)
|
|
195
|
+
Decision.new("frame", "forms render as frame nodes", nil, nil, 0)
|
|
196
|
+
elsif all.match?(FORM_FOR)
|
|
197
|
+
Decision.new(mode: "native", reason: "Formtastic forms render as form nodes", template: nil, custom_key: nil, fields: 0, get_form: all.match?(GET_FORM))
|
|
198
|
+
else
|
|
199
|
+
Decision.new("native", "content walks into typed nodes", nil, nil, 0)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def strip_erb(text) = text.gsub(/<%#.*?%>/m, "").gsub(/<!--.*?-->/m, "").gsub(/<%.*?%>/m, "")
|
|
204
|
+
|
|
205
|
+
def other_tags(markup) = markup.scan(/<\/?([a-z][a-z0-9]*)/i).flatten.map(&:downcase).uniq - SIMPLE_TAGS
|
|
206
|
+
|
|
207
|
+
# Anything beyond Formtastic's own methods on the form block's variable renders something we can't record.
|
|
208
|
+
def builder_misuse(text)
|
|
209
|
+
vars = text.scan(/(?:semantic_form_for|active_admin_form_for|semantic_fields_for|fields_for)\b[^\n]*?do\s*\|\s*(\w+)/).flatten.uniq
|
|
210
|
+
vars.flat_map { |var| text.scan(/\b#{var}\.(\w+)/).flatten }.uniq - BUILDER_METHODS
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# [[name, text]] of the template and every partial it renders, depth first.
|
|
214
|
+
def sources_for(config, name, seen = {})
|
|
215
|
+
controller_path = config.controller.controller_path
|
|
216
|
+
found = lookup.find_all(name.to_s, name.to_s.include?("/") ? [] : [controller_path], false, [], formats: [:html]).first
|
|
217
|
+
return [] if found.nil? || seen[found.identifier]
|
|
218
|
+
|
|
219
|
+
seen[found.identifier] = true
|
|
220
|
+
text = found.source.to_s
|
|
221
|
+
[[name, text]] + partial_refs(text).flat_map { |partial| partial_sources(config, partial, File.dirname(name.to_s), seen) }
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def partial_sources(config, partial, dir, seen)
|
|
225
|
+
prefixes = [dir, config.controller.controller_path]
|
|
226
|
+
found = lookup.find_all(partial, partial.include?("/") ? [] : prefixes, true, [], formats: [:html]).first
|
|
227
|
+
return [] if found.nil? || seen[found.identifier]
|
|
228
|
+
|
|
229
|
+
seen[found.identifier] = true
|
|
230
|
+
text = found.source.to_s
|
|
231
|
+
[[partial, text]] + partial_refs(text).flat_map { partial_sources(config, it, File.dirname(partial), seen) }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# Partials a view renders: `render "form"` and `render partial: "x"`, not `render template:`.
|
|
235
|
+
def partial_refs(text)
|
|
236
|
+
renders(text).filter_map { it[:name] unless it[:kind]&.start_with?("template", "action") }.uniq
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def partial_texts(config, text, seen = {})
|
|
240
|
+
partial_refs(text.to_s).flat_map { partial_sources(config, it, config.controller.controller_path, seen).map(&:last) }
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def lines_of(file)
|
|
244
|
+
return File.readlines(file) if Rails.application.config.enable_reloading
|
|
245
|
+
|
|
246
|
+
(@files ||= {})[file] ||= File.readlines(file)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def lookup = @lookup ||= ActionView::LookupContext.new(ActionController::Base.view_paths)
|
|
250
|
+
|
|
251
|
+
# Source of the block that starts at file:line, up to the line that closes it.
|
|
252
|
+
def block_source(block) = (block_at(*block.source_location) if block)
|
|
253
|
+
|
|
254
|
+
def block_at(file, line)
|
|
255
|
+
lines = lines_of(file)
|
|
256
|
+
first = lines[line - 1].to_s
|
|
257
|
+
return first unless first.match?(/\b(?:do|\{)\s*(?:\|[^|]*\|)?\s*\z/)
|
|
258
|
+
|
|
259
|
+
indent = first[/\A\s*/]
|
|
260
|
+
body = [first]
|
|
261
|
+
lines.drop(line).each do |text|
|
|
262
|
+
body << text
|
|
263
|
+
break if text.match?(/\A#{indent}(?:end|\})\b/)
|
|
264
|
+
end
|
|
265
|
+
body.join
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Translates a safelisted subset of utility classes, and of inline styles (via InlineStyle, which
|
|
3
|
+
# speaks in the same classes), into hints for the client. Raw classes and styles are never passed
|
|
4
|
+
# through: what has no translation is returned in `unknown` and `unknown_styles` for `doctor`.
|
|
5
|
+
class LayoutClasses
|
|
6
|
+
BREAKPOINTS = %w[sm md lg xl].freeze
|
|
7
|
+
WIDTHS = %w[1/4 1/3 1/2 2/3 3/4 full].freeze
|
|
8
|
+
MAX_WIDTHS = %w[sm md lg xl 2xl].freeze
|
|
9
|
+
ALIGNS = %w[start center end stretch baseline].freeze
|
|
10
|
+
JUSTIFIES = %w[start center end between].freeze
|
|
11
|
+
TEXT_ALIGNS = %w[left center right].freeze
|
|
12
|
+
# Colors say what the text means; the client picks the shade.
|
|
13
|
+
TONES = {"muted" => "muted", "gray" => "muted", "grey" => "muted", "success" => "success", "green" => "success",
|
|
14
|
+
"danger" => "danger", "red" => "danger", "warning" => "warning", "yellow" => "warning", "orange" => "warning",
|
|
15
|
+
"amber" => "warning"}.freeze
|
|
16
|
+
MAX_GAP = 8
|
|
17
|
+
MAX_SPACING = 8
|
|
18
|
+
MAX_COLUMNS = 12
|
|
19
|
+
# Plain-word utilities. Other plain words (button, empty, ...) are AA's own semantic classes.
|
|
20
|
+
UTILITY_WORDS = %w[hidden block inline contents relative absolute fixed sticky truncate underline italic uppercase
|
|
21
|
+
lowercase capitalize grow shrink container].freeze
|
|
22
|
+
# A dashed class is a utility when it starts like one; `button-secondary` or `nav-tabs` is the host's or AA's own.
|
|
23
|
+
UTILITY_FAMILY = /\A-?(?:[mp][trblxy]?|(?:min|max)-[wh]|[wh]|size|gap|space|flex|grid|col|row|basis|order|items|justify|content|self|place|
|
|
24
|
+
text|font|leading|tracking|bg|border|divide|ring|outline|rounded|shadow|opacity|overflow|object|cursor|whitespace|break|z|top|right|bottom|
|
|
25
|
+
left|inset|align|list|decoration|transition|duration|translate|rotate|scale|transform|float|clear|aspect|columns|sr|indent|fill|stroke)-/x
|
|
26
|
+
SIDES = {"t" => %i[top], "r" => %i[right], "b" => %i[bottom], "l" => %i[left], "x" => %i[left right], "y" => %i[top bottom],
|
|
27
|
+
"" => %i[top right bottom left]}.freeze
|
|
28
|
+
|
|
29
|
+
Result = Struct.new(:layout, :width, :span, :text_align, :justify, :spacing, :max_width, :grow, :marks, :tone, :nowrap, :unknown, :unknown_styles) do
|
|
30
|
+
# Contract fields for a box; empty when the classes say nothing about layout.
|
|
31
|
+
def hints = {layout:, width:, span:, text_align:, spacing:, max_width:, grow:}.compact
|
|
32
|
+
|
|
33
|
+
# Contract fields for text, or for a box whose content they apply to.
|
|
34
|
+
def text_style = {marks:, tone:, nowrap:}.compact
|
|
35
|
+
|
|
36
|
+
# Where a toolbar's content sits, from `text-right` or `justify-end`.
|
|
37
|
+
def toolbar_align = {"right" => "end", "center" => "center", "end" => "end"}[text_align || justify]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.parse(classes, style: nil) = new(classes, style:).parse
|
|
41
|
+
|
|
42
|
+
# What to use instead of an untranslatable class, for the styles report.
|
|
43
|
+
ADVICE = {
|
|
44
|
+
/\A(?:[a-z]+:)?-?[mp][trblxy]?-\d+\z/ => "margins go up to 8 (2rem), unprefixed and positive; padding has no typed equivalent (wrap in a panel)",
|
|
45
|
+
/\A(?:[a-z]+:)?(?:bg|border|rounded|shadow|ring)(?:-|\z)/ => "no typed fill or border; use a panel or a `flash`",
|
|
46
|
+
/\A(?:[a-z]+:)?text-(?:xs|sm|base|lg|xl|\dxl)\z/ => "no typed text size; drop it",
|
|
47
|
+
/\A(?:[a-z]+:)?max-w-/ => "use `max-w-sm|md|lg|xl|2xl`",
|
|
48
|
+
/\A(?:[a-z]+:)?(?:w|basis)-/ => "use `w-1/4|1/3|1/2|2/3|3/4|full`",
|
|
49
|
+
/\A[a-z]+:/ => "responsive variants only read for flex-row, grid-cols, w and col-span"
|
|
50
|
+
}.freeze
|
|
51
|
+
|
|
52
|
+
def self.advice(token) = ADVICE.find { |pattern, _| token.match?(pattern) }&.last || "no typed equivalent"
|
|
53
|
+
|
|
54
|
+
def initialize(classes, style: nil)
|
|
55
|
+
translated = InlineStyle.parse(style)
|
|
56
|
+
@tokens = [*classes.to_s.split, *translated.tokens]
|
|
57
|
+
@unknown_styles = translated.unknown
|
|
58
|
+
@responsive_rows = []
|
|
59
|
+
@responsive_columns = []
|
|
60
|
+
@responsive_widths = {}
|
|
61
|
+
@responsive_spans = {}
|
|
62
|
+
@gap = 0
|
|
63
|
+
@wrap = false
|
|
64
|
+
@spacing = {}
|
|
65
|
+
@marks = []
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def parse
|
|
69
|
+
unknown = @tokens.select { !handled?(*split(it)) && utility?(it) }
|
|
70
|
+
Result.new(layout:, width: @responsive_widths.values.first || @width, span: @responsive_spans.values.first || @span,
|
|
71
|
+
text_align: @text_align, justify: @justify, spacing: @spacing.presence, max_width: @max_width, grow: (true if @grow),
|
|
72
|
+
marks: @marks.presence, tone: @tone, nowrap: (true if @nowrap), unknown:, unknown_styles: @unknown_styles)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def split(token)
|
|
78
|
+
prefix, _, base = token.rpartition(":")
|
|
79
|
+
[prefix.presence, base]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def utility?(token) = token.match?(/[:\/\[]/) || token.match?(UTILITY_FAMILY) || UTILITY_WORDS.include?(token)
|
|
83
|
+
|
|
84
|
+
def handled?(prefix, base)
|
|
85
|
+
return false if prefix && BREAKPOINTS.exclude?(prefix)
|
|
86
|
+
|
|
87
|
+
case base
|
|
88
|
+
when "flex", "inline-flex" then !prefix && (@display ||= "flex")
|
|
89
|
+
when "grid" then !prefix && (@display = "grid")
|
|
90
|
+
when "flex-row" then prefix ? @responsive_rows << prefix : (@direction = "row")
|
|
91
|
+
when "flex-col" then !prefix && (@direction = "column")
|
|
92
|
+
when "flex-wrap" then !prefix && (@wrap = true)
|
|
93
|
+
when "flex-nowrap" then !prefix
|
|
94
|
+
when /\Agap-(\d+)\z/ then !prefix && (@gap = [$1.to_i, MAX_GAP].min)
|
|
95
|
+
when /\Aitems-(\w+)\z/ then !prefix && ALIGNS.include?($1) && (@align = $1)
|
|
96
|
+
when /\Ajustify-(\w+)\z/ then !prefix && JUSTIFIES.include?($1) && (@justify = $1)
|
|
97
|
+
when "w-auto" then !prefix
|
|
98
|
+
when /\A(?:w|basis)-(.+)\z/ then width($1, prefix)
|
|
99
|
+
when /\Amax-w-(\w+)\z/ then !prefix && MAX_WIDTHS.include?($1) && (@max_width = $1)
|
|
100
|
+
when "grow", "flex-grow", "flex-1" then !prefix && (@grow = true)
|
|
101
|
+
when /\Am([trblxy]?)-(\d+)\z/ then !prefix && spacing($1, $2.to_i)
|
|
102
|
+
when "font-bold", "font-semibold" then !prefix && mark("strong")
|
|
103
|
+
when "italic" then !prefix && mark("em")
|
|
104
|
+
when "whitespace-nowrap", "text-nowrap" then !prefix && (@nowrap = true)
|
|
105
|
+
when /\Atext-(\w+)\z/ then !prefix && (TEXT_ALIGNS.include?($1) ? (@text_align = $1) : tone($1))
|
|
106
|
+
when /\Atext-(\w+)-\d+\z/ then !prefix && tone($1)
|
|
107
|
+
when /\Agrid-cols-(\d+)\z/ then columns($1.to_i, prefix)
|
|
108
|
+
when /\Acol-span-(\d+)\z/ then span($1.to_i, prefix)
|
|
109
|
+
else false
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def width(value, prefix)
|
|
114
|
+
return false unless WIDTHS.include?(value)
|
|
115
|
+
|
|
116
|
+
prefix ? @responsive_widths[prefix] = value : @width = value
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# A zero margin only resets classic's defaults, which the client doesn't have.
|
|
120
|
+
def spacing(side, steps)
|
|
121
|
+
return false if steps > MAX_SPACING
|
|
122
|
+
|
|
123
|
+
SIDES.fetch(side).each { @spacing[it] = steps } if steps.positive?
|
|
124
|
+
true
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def mark(name)
|
|
128
|
+
@marks << name unless @marks.include?(name)
|
|
129
|
+
true
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def tone(name) = TONES.key?(name) && (@tone = TONES[name])
|
|
133
|
+
|
|
134
|
+
def columns(count, prefix)
|
|
135
|
+
return false unless (1..MAX_COLUMNS).cover?(count)
|
|
136
|
+
|
|
137
|
+
prefix ? @responsive_columns << [prefix, count] : @columns = count
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def span(count, prefix)
|
|
141
|
+
return false unless (1..MAX_COLUMNS).cover?(count)
|
|
142
|
+
|
|
143
|
+
prefix ? @responsive_spans[prefix] = count : @span = count
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def layout
|
|
147
|
+
case @display
|
|
148
|
+
when "flex" then flex
|
|
149
|
+
when "grid" then grid
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# `flex lg:flex-row` means stacked below lg, even though plain `flex` is a row at every width.
|
|
154
|
+
def flex
|
|
155
|
+
breakpoint = @responsive_rows.min_by { BREAKPOINTS.index(it) } unless @direction == "row"
|
|
156
|
+
{display: "flex", direction: breakpoint ? "row" : (@direction || "row"), breakpoint:, gap: @gap, wrap: @wrap}
|
|
157
|
+
.merge({align: @align, justify: @justify}.compact)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def grid
|
|
161
|
+
breakpoint, count = @responsive_columns.min_by { BREAKPOINTS.index(it.first) }
|
|
162
|
+
layout = {display: "grid", columns: count || @columns || 1, breakpoint:, gap: @gap}
|
|
163
|
+
layout[:base_columns] = @columns if breakpoint && @columns && @columns != 1
|
|
164
|
+
layout
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|