inline_forms 8.1.79 → 8.1.81

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5e23dce20574f758b57ab81d8a344f0d74b8e969c13e305ab426b6270623b9d
4
- data.tar.gz: 49eba2b2136e79bd27dbc51c258681c98cbcf718679d22ceced338e0f252bd3d
3
+ metadata.gz: 72335aa9872d9bdb812e7cafa30ce3b9644c15b13332c845124e02f0a1f63b85
4
+ data.tar.gz: 5482bf68736408019e5a8a4c1143a7194ce13d68edac743d6ad18dab52a07a0a
5
5
  SHA512:
6
- metadata.gz: 8d40d0a5af35ef3889706d15b667cffd1eb12165b5a87f397a200cdd044a9ac28ecaadcb0639632b317b837a85d8eade09fe0545e28848334d1bc88e30f88721
7
- data.tar.gz: 239613687ee6ee98a42b9a0997c63af81b0c9e28f326c152363e2edb6cb918b9b0ac430894d0f2c1d440d93e98e23ec23df8129e8754220a371ed06a32ac0287
6
+ metadata.gz: 35072c3e64464f5a93e3d6b24507f37109d01f80c3e64b76b2f216bddda9dccabb962841af1374faa09c2a5e8f30eef44622338d3d2a144716fcdb693bf1d272
7
+ data.tar.gz: a1fd57eb92afec824df4da51f05362db8508f3132a8e03d895bfae9493443dfeaec80c99cab10cfee2e71717d330a8a55e975969af3ecf3429be58f12a8e6584
data/CHANGELOG.md CHANGED
@@ -8,6 +8,46 @@ All notable changes to this project are documented in this file.
8
8
 
9
9
  - Known issues, parked (local note `stuff/2026-10-31-dropdown-rule-3-parked.md`) with dropdown order rule 3: `includes`, `group` or `select` in `inline_forms_list` make `dropdown` and `dropdown_with_other` raise while `/index` works, so 8.1.65's fix for a list order on a joined table holds only for `joins`, `left_joins` and `eager_load`; a has_many join gives duplicate options. Present since 8.1.60. No host's list scope has these today. Parked; not changed.
10
10
 
11
+ ## [8.1.81] - 2026-11-24
12
+
13
+ From the RACVS / yavetracker Rails ladder (`ladder/inline_forms-PROMPT-2026-11-24.md`).
14
+
15
+ ### Fixed
16
+
17
+ - **Three validators added no error since Rails 7.0.** `is_email_address`, `is_curacao_phone` and `must_be_a_value` did `record.errors[attribute] << …`, which Rails 7.0 and later throw away: the record stayed valid and every value was saved. They now call `errors.add`. **An app that uses them will see validation errors on values it used to accept**, including on records already stored with such values (they fail on their next save). Scouting, StProject, Papiamentu and PapCWScrabble do not use them.
18
+ - **An app's own list filter survives `index`.** An index override or `before_action` that sets a filtered `@objects` (a relation of the list's model) before the engine's `index` runs keeps its filter; with CanCan it is narrowed to what the ability allows (`@objects.merge(accessible_by)`), so it never shows more than before. Until now CanCan's collection replaced it, and the app's search and filters were silently lost (apps worked around it, e.g. RACVS's `sync_cancan_collection!`). Anything else in `@objects` (an Array, another model) is replaced as before.
19
+ - **The versions panel and the undo of a delete in an app without the Action Text table.** They asked only whether `ActionText::RichText` is defined, which it is under `rails/all`, and then queried `action_text_rich_texts`. They now ask `InlineForms.action_text_table?` (the class and its table).
20
+ - **Dates read dd-mm-yyyy everywhere the engine shows them.** `date_select_info`, the `info` element (for a Date) and the old and new values in the versions panel printed a bare Date, which is ISO (`2026-01-13`) since Rails 7.1; `date_select_show` already printed `13-01-2026`. New: `InlineForms::DATE_FORMAT` (`"%d-%m-%Y"`) and the view helper `inline_forms_value_text` (a Date as that, a time as `inline_forms_time_text`, anything else unchanged).
21
+ - **`new` and a successful `create` inside a Turbo frame answer with the frame layout** (`turbo_rails/frame`), as `index` and `destroy` do, instead of the full layout: an app's header and menus no longer run there (partials that expect a list's data crashed). A full page load keeps the `inline_forms` layout. This undoes 7.5.1's choice of the full layout for nested new forms "so the swapped frame is styled": Turbo inserts only the frame, which the page already styles (checked in a browser: the nested Photo new form, its Trix editor, cancel and ok).
22
+ - **Logout works without rails-ujs.** The header's link carries `data-turbo-method="delete"` (Turbo sends the DELETE) besides `data-method`; it was a GET, which Devise refuses. The same in the installer's example-app header. Apps with a header of their own (Scouting, StProject, Papiamentu) check theirs.
23
+ - **Trix loads once, in `<head>`,** in both layouts. In `<body>` Turbo ran it again on every visit and it threw on the second definition of `trix-toolbar`.
24
+ - **The cancel buttons are links styled as buttons.** The field cancel and the new form's cancel were an `<input type="button">` inside an `<a>` (invalid HTML). Now `<a class="… button alert" role="button">cancel</a>` (`inline_forms-field-cancel`, `inline_forms-new-cancel`); the CSS follows. An app that styles or selects `input[name=cancel]` must follow.
25
+
26
+ ### Added
27
+
28
+ - **Page links of a top-level list advance the address bar** (`data-turbo-action="advance"`, renderer `inline_forms_advancing_link_renderer`): back, reload and a shared link keep the page. Nested lists keep the plain links.
29
+ - **An app may vendor an archived form element.** The boot check skips an archived symbol when the app's helpers define `<name>_show` (`InlineForms.vendored_form_element?`); `archived/README.md` says how. Before, vendoring did not stop the raise although the message suggested it.
30
+
31
+ ### Upgrade notes
32
+
33
+ - **`:text_area` is rich text (Action Text) since 7.3.1, and `:ckeditor` is archived (8.1.21).** HTML that CKEditor stored in the model's own text column is not shown by `:text_area`, which reads `action_text_rich_texts`. Either declare the column `:plain_text_area` (shows the column as plain text), or move the HTML into Action Text once: rename the old column (say `body` to `body_html`) in a migration, declare `has_rich_text :body`, copy with `Model.find_each { |r| r.update!(body: r.body_html) if r.body_html.present? }` (a runner or a data migration), check the result on a copy of production data, and drop `body_html` later.
34
+
35
+ ## [8.1.80] - 2026-11-24
36
+
37
+ From the notes of the apps' move to 8.1.79's suggestions.
38
+
39
+ ### Changed
40
+
41
+ - **`match: :word` also starts a word after a hyphen or an apostrophe** (`'` and `’`), not only after a space: "marc" finds Jean-Marc, "brien" O'Brien, "abreu" D’Abreu. Still not inside a word ("marc" does not find Lamarck). Apps that pin the old space-only behaviour in a spec (Scouting's `members_autocomplete_spec.rb`) see that spec fail on the upgrade, on purpose.
42
+
43
+ ### Added
44
+
45
+ - **`inline_forms_suggestion_request?`** (concern `SuggestionRequestConcern`), in `InlineFormsController` and in `InlineFormsApplicationController`, so a generated app's `ApplicationController` has it for every controller, and in views: true when the request is the search box's suggestions (`index` with `?suggest=1`), which answer JSON and are not a list view; false outside the inline_forms lists. For an app's own callbacks, e.g. statistics that count list views only: `skip_after_action :track_action, if: :inline_forms_suggestion_request?`.
46
+
47
+ ### Fixed
48
+
49
+ - **The generic search box has accessible names.** The form has `role="search"`, the field an `aria-label` (new key `inline_forms.search.label`: "search", "zoeken"; without it, the placeholder text), the reset link an `aria-label` as well as its `title`, and its `fi-x` icon `aria-hidden="true"`.
50
+
11
51
  ## [8.1.79] - 2026-11-23
12
52
 
13
53
  ### Added
@@ -325,28 +325,19 @@ turbo-frame {
325
325
  }
326
326
  }
327
327
 
328
- // Field edit cancel: outer <a> carries Turbo/UJS; inner input[type=button] matches ok height.
328
+ // Field edit cancel: the <a> itself is the button, the same height as ok.
329
329
  .edit_form .row.collapse {
330
330
  input[type="submit"].postfix.button,
331
- a.inline_forms-field-cancel input[type="button"].postfix.button {
331
+ a.inline_forms-field-cancel.postfix.button {
332
332
  margin: 2px 0 !important;
333
333
  }
334
334
  }
335
335
 
336
336
  .edit_form a.inline_forms-field-cancel {
337
337
  display: inline-block;
338
- padding: 0;
339
- border: 0;
340
- background: transparent;
341
- line-height: 0;
338
+ width: auto;
342
339
  vertical-align: top;
343
340
  text-decoration: none;
344
-
345
- input[type="button"] {
346
- pointer-events: none;
347
- cursor: pointer;
348
- width: auto;
349
- }
350
341
  }
351
342
 
352
343
  .object_presentation {
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `inline_forms_suggestion_request?`: true when this request is an
4
+ # inline_forms list's search-box suggestions (index with ?suggest=1&term=…,
5
+ # which answers a JSON array), not a list view. For an app's own callbacks,
6
+ # e.g. statistics that count list views only:
7
+ #
8
+ # skip_after_action :track_action, if: :inline_forms_suggestion_request?
9
+ #
10
+ # Included in InlineFormsController and in InlineFormsApplicationController,
11
+ # so an ApplicationController that inherits from the latter has it for every
12
+ # controller (false outside the inline_forms lists).
13
+ module SuggestionRequestConcern
14
+ extend ActiveSupport::Concern
15
+
16
+ included do
17
+ helper_method :inline_forms_suggestion_request?
18
+ end
19
+
20
+ protected
21
+
22
+ def inline_forms_suggestion_request?
23
+ is_a?(InlineFormsController) && action_name == "index" &&
24
+ params.key?(:suggest) && params[:parent_class].blank?
25
+ end
26
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  class InlineFormsApplicationController < ActionController::Base
4
4
  protect_from_forgery
5
+ include SuggestionRequestConcern
5
6
  # `layout 'devise' if :devise_controller?` was wrong: `:devise_controller?` is a
6
7
  # Symbol (always truthy), so every controller used the Devise layout. Use a
7
8
  # callable so only Devise controllers get `layouts/devise`; everything else
@@ -28,6 +28,7 @@ class InlineFormsController < ApplicationController
28
28
  include VersionsConcern
29
29
  include FileSlotsConcern
30
30
  include SuggestionsConcern
31
+ include SuggestionRequestConcern
31
32
 
32
33
  before_action :getKlass
33
34
 
@@ -51,10 +52,16 @@ class InlineFormsController < ApplicationController
51
52
  fk_conditions = [ "#{foreign_key} = ?", @parent_id ]
52
53
  end
53
54
  # CanCan's load_and_authorize_resource sets @apartments (etc.); keep @objects in sync.
55
+ # An app's index override or before_action may already have set a filtered
56
+ # @objects (a relation) before this runs: keep its filter, narrowed to what
57
+ # the ability allows, instead of replacing it with the whole collection.
54
58
  collection_ivar = :"@#{controller_name}"
55
59
  if instance_variable_defined?(collection_ivar)
56
60
  loaded = instance_variable_get(collection_ivar)
57
- @objects = loaded unless loaded.nil?
61
+ unless loaded.nil?
62
+ app_filtered = @objects.is_a?(ActiveRecord::Relation) && @objects.model == @Klass
63
+ @objects = app_filtered ? @objects.merge(loaded) : loaded
64
+ end
58
65
  end
59
66
  @objects ||= @Klass.accessible_by(current_ability) if cancan_enabled?
60
67
  @objects ||= @Klass.all
@@ -581,7 +588,7 @@ class InlineFormsController < ApplicationController
581
588
  # row already exists. Only the newest destroy version per attribute name is
582
589
  # applied (repeat delete/undo leaves multiple RT destroy versions in the table).
583
590
  def restore_rich_texts_for_reverted_parent!(parent)
584
- return unless defined?(ActionText::RichText)
591
+ return unless InlineForms.action_text_table?
585
592
 
586
593
  record_type = parent.class.base_class.name
587
594
  record_id = parent.id
@@ -774,9 +781,11 @@ class InlineFormsController < ApplicationController
774
781
  end
775
782
 
776
783
  def associated_list_frame_layout
777
- # Use full inline_forms chrome so the swapped frame is styled; Turbo extracts
778
- # the matching <turbo-frame id="…"> from the response body.
779
- "inline_forms"
784
+ # A Turbo frame request gets the bare frame layout: Turbo takes only the
785
+ # matching <turbo-frame id="…"> from the answer, and the full layout would
786
+ # run the app's header and menus (partials that may expect a list's data)
787
+ # for nothing. A full page load keeps the inline_forms layout.
788
+ turbo_frame_request? ? "turbo_rails/frame" : "inline_forms"
780
789
  end
781
790
 
782
791
  def render_turbo_new
@@ -70,7 +70,7 @@ module InlineFormsHelper
70
70
  { version: v, kind: :primary, rich_text_name: nil }
71
71
  end
72
72
 
73
- if defined?(ActionText::RichText)
73
+ if InlineForms.action_text_table?
74
74
  ActionText::RichText
75
75
  .where(record_type: object.class.base_class.name, record_id: object.id)
76
76
  .each do |rich_text|
@@ -94,6 +94,23 @@ module InlineFormsHelper
94
94
  # requests +text/vnd.turbo-stream.html+ so Turbo does not expect a single matching
95
95
  # frame in the response — POSTs from nested +…_versions+ frames otherwise send
96
96
  # +Turbo-Frame: …_versions+ while the server returns the row frame (+Content missing+).
97
+ # will_paginate renderer for a top-level list: each page link carries
98
+ # data-turbo-action="advance", so a page change inside the list's
99
+ # <turbo-frame> also updates the address bar (back, reload and a shared
100
+ # link keep the page). Nested lists keep the plain renderer: their pages
101
+ # change one panel, not the page.
102
+ def inline_forms_advancing_link_renderer
103
+ InlineFormsHelper.advancing_link_renderer
104
+ end
105
+
106
+ def self.advancing_link_renderer
107
+ @advancing_link_renderer ||= Class.new(WillPaginate::ActionView::LinkRenderer) do
108
+ def link(text, target, attributes = {})
109
+ super(text, target, attributes.merge("data-turbo-action": "advance"))
110
+ end
111
+ end
112
+ end
113
+
97
114
  def inline_forms_turbo_link_data(update_span, method: :get, turbo_stream: false)
98
115
  data = { turbo: true, turbo_frame: update_span }
99
116
  data[:turbo_method] = method.to_s.downcase unless method == :get
@@ -268,22 +285,15 @@ module InlineFormsHelper
268
285
  form_element: form_element,
269
286
  sub_id: sub_id
270
287
  )
271
- opts = { class: "inline_forms-field-cancel" }
288
+ # The link itself is the button (an <input> inside an <a> is invalid HTML).
289
+ opts = { class: "inline_forms-field-cancel postfix button alert", role: "button", tabindex: "-1" }
272
290
  if turbo_frame
273
291
  # Inside a <turbo-frame>: plain GET link; no data-method (legacy ujs fought Turbo).
274
292
  opts[:data] = { turbo: true, turbo_frame: "_self" }
275
293
  else
276
294
  opts[:data] = { turbo: true, turbo_frame: update_span }
277
295
  end
278
- link_to path, opts do
279
- tag.input(
280
- type: "button",
281
- name: "cancel",
282
- value: "cancel",
283
- class: "postfix button alert",
284
- tabindex: "-1"
285
- )
286
- end
296
+ link_to "cancel", path, opts
287
297
  end
288
298
 
289
299
  # link_to_inline_edit
@@ -394,6 +404,17 @@ module InlineFormsHelper
394
404
  values
395
405
  end
396
406
 
407
+ # A value as text for the screen: a Date as dd-mm-yyyy (since Rails 7.1 a
408
+ # bare Date prints ISO), a time as inline_forms_time_text, anything else
409
+ # as it is. Used by the info elements and the versions panel.
410
+ def inline_forms_value_text(value)
411
+ case value
412
+ when DateTime, Time, ActiveSupport::TimeWithZone then inline_forms_time_text(value)
413
+ when Date then value.strftime(InlineForms::DATE_FORMAT)
414
+ else value
415
+ end
416
+ end
417
+
397
418
  # A version or file timestamp: the date with its year
398
419
  # (time.formats.inline_forms; rails-i18n's :short has none, so edits years
399
420
  # apart read the same), the exact ISO 8601 time on hover.
@@ -16,7 +16,7 @@ class IsCuracaoPhoneValidator < ActiveModel::EachValidator
16
16
 
17
17
  def validate_each(record, attribute, value)
18
18
  unless value =~ /[4-8][0-9]{6}/
19
- record.errors[attribute] << (options[:message] || error_message)
19
+ record.errors.add(attribute, options[:message] || error_message)
20
20
  end
21
21
  end
22
22
  end
@@ -29,7 +29,7 @@ class IsEmailAddressValidator < ActiveModel::EachValidator
29
29
 
30
30
  def validate_each(record, attribute, value)
31
31
  unless value =~ EmailAddress
32
- record.errors[attribute] << (options[:message] || error_message)
32
+ record.errors.add(attribute, options[:message] || error_message)
33
33
  end
34
34
  end
35
35
  end
@@ -16,7 +16,7 @@ class MustBeAValueValidator < ActiveModel::EachValidator
16
16
  def validate_each(record, attribute, value)
17
17
  values = attribute_values(record, attribute)
18
18
  if values.assoc(value).nil?
19
- record.errors[attribute] << (options[:message] || error_message)
19
+ record.errors.add(attribute, options[:message] || error_message)
20
20
  end
21
21
  end
22
22
 
@@ -1,15 +1,16 @@
1
- <%= form_tag request.path, method: :get do %>
1
+ <% search_label = t("inline_forms.search.label", default: t("inline_forms.search.placeholder")) %>
2
+ <%= form_tag request.path, method: :get, role: "search" do %>
2
3
  <div class="row collapse">
3
4
  <div class="large-1 small-1 columns">
4
- <%= link_to tag.i(class: "fi-x"), request.path, title: t("inline_forms.search.reset"), class: "button expanded inline_forms_model_top_bar_buttons" %>
5
+ <%= link_to tag.i(class: "fi-x", "aria-hidden": "true"), request.path, title: t("inline_forms.search.reset"), "aria-label": t("inline_forms.search.reset"), class: "button expanded inline_forms_model_top_bar_buttons" %>
5
6
  </div>
6
7
  <div class="large-6 small-6 columns">
7
8
  <%# With `inline_forms_search_on …, suggest: …` the list itself answers %>
8
9
  <%# the suggestions (index with ?suggest=1&term=…). %>
9
10
  <% if @Klass.respond_to?(:inline_forms_suggestions) && @Klass.inline_forms_suggestions %>
10
- <%= suggest_field_tag :search, params[:search], "#{request.path}?suggest=1", placeholder: t("inline_forms.search.placeholder"), id: "input_search", list: "input_search_suggestions" %>
11
+ <%= suggest_field_tag :search, params[:search], "#{request.path}?suggest=1", placeholder: t("inline_forms.search.placeholder"), "aria-label": search_label, id: "input_search", list: "input_search_suggestions" %>
11
12
  <% else %>
12
- <%= text_field_tag :search, params[:search], placeholder: t("inline_forms.search.placeholder"), id: "input_search" %>
13
+ <%= text_field_tag :search, params[:search], placeholder: t("inline_forms.search.placeholder"), "aria-label": search_label, id: "input_search" %>
13
14
  <% end %>
14
15
  </div>
15
16
  <div class="large-3 small-3 columns">
@@ -33,7 +33,8 @@
33
33
  <li><%= trash_link %></li>
34
34
  <% end %>
35
35
  <li>
36
- <%= link_to( t("common.logout"), destroy_user_session_path, :method => :delete) if current_user %>
36
+ <%# data-turbo-method: Turbo sends the DELETE (the engine loads no rails-ujs); data-method for an app that does. %>
37
+ <%= link_to(t("common.logout"), destroy_user_session_path, method: :delete, data: { turbo_method: :delete }) if current_user %>
37
38
  </li>
38
39
  </ul>
39
40
  </li>
@@ -127,7 +127,7 @@
127
127
  test/integration/list_params_test.rb covers both.
128
128
  -%>
129
129
  <% paginate_params = { update: update_span, ul_needed: true } %>
130
- <% pagination = will_paginate objects, params: paginate_params %>
130
+ <% pagination = will_paginate objects, params: paginate_params, renderer: inline_forms_advancing_link_renderer %>
131
131
  <% else %>
132
132
  <% if pagination %>
133
133
  <%#
@@ -75,9 +75,8 @@
75
75
  parent_id: @parent_id,
76
76
  ul_needed: true) %>
77
77
  <% cancel_opts = @update_span.present? ? inline_forms_turbo_link_data(@update_span) : {} %>
78
- <%= link_to cancel_path, cancel_opts do -%>
79
- <input type="button" name="cancel" value="cancel" class="button alert" />
80
- <% end %>
78
+ <%# The link itself is the button (an <input> inside an <a> is invalid HTML). %>
79
+ <%= link_to "cancel", cancel_path, cancel_opts.merge(class: "button alert inline_forms-new-cancel", role: "button") %>
81
80
  <%= submit_tag "ok", :class => "button "-%>
82
81
  </div>
83
82
  </div>
@@ -126,8 +126,8 @@
126
126
  <td><%= sanitize value[0].to_s %></td>
127
127
  <td><%= sanitize value[1].to_s %></td>
128
128
  <% else %>
129
- <td><%= value[0] %></td>
130
- <td><%= value[1] %></td>
129
+ <td><%= inline_forms_value_text(value[0]) %></td>
130
+ <td><%= inline_forms_value_text(value[1]) %></td>
131
131
  <% end %>
132
132
  </tr>
133
133
  </table>
@@ -14,6 +14,10 @@
14
14
  <%# Publishes the CSP nonce (nothing without a nonce generator) for the %>
15
15
  <%# scripts Turbo inserts. %>
16
16
  <%= csp_meta_tag %>
17
+ <%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
18
+ <%# In <head>, so Turbo Drive loads it once: a body copy ran again on each %>
19
+ <%# visit and threw on the second definition of trix-toolbar. %>
20
+ <%= javascript_include_tag "trix.min" %>
17
21
  </head>
18
22
 
19
23
  <body class="<%= inline_forms_body_theme_class %>">
@@ -30,7 +34,5 @@
30
34
  import { Turbo } from "<%= asset_path('turbo.min.js') %>"
31
35
  window.Turbo = Turbo
32
36
  <% end %>
33
- <%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
34
- <%= javascript_include_tag "trix.min" %>
35
37
  </body>
36
38
  </html>
@@ -31,6 +31,10 @@
31
31
  <%= javascript_include_tag 'popper.min' %>
32
32
  <%= javascript_include_tag 'tippy-bundle.umd.min' %>
33
33
  <%= javascript_include_tag 'inline_forms/inline_forms' %>
34
+ <%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
35
+ <%# In <head>, so Turbo Drive loads it once: a body copy ran again on each %>
36
+ <%# visit and threw on the second definition of trix-toolbar. %>
37
+ <%= javascript_include_tag "trix.min" %>
34
38
  </head>
35
39
 
36
40
  <body class="<%= inline_forms_body_theme_class %>">
@@ -60,7 +64,5 @@
60
64
  import { Turbo } from "<%= asset_path('turbo.min.js') %>"
61
65
  window.Turbo = Turbo
62
66
  <% end %>
63
- <%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
64
- <%= javascript_include_tag "trix.min" %>
65
67
  </body>
66
68
  </html>
data/archived/README.md CHANGED
@@ -39,6 +39,18 @@ Active form elements load from `app/helpers/form_elements/*.rb` only (top-level
39
39
  4. Remove the symbol from `InlineForms::ARCHIVED_FORM_ELEMENTS` (or leave it and remove the model reference only in your app).
40
40
  5. Bump your app/gem as needed; run tests.
41
41
 
42
+ ## Vendoring an archived form element into an app
43
+
44
+ An app can keep using an archived element without changing the gem: put its
45
+ helper methods (`<name>_show`, `<name>_edit`, `<name>_update`, and `_info` if it
46
+ has one) in a module under the app's own `app/helpers/`, plus the models,
47
+ controllers, views, routes and assets its README lists. Since 8.1.81 the boot
48
+ check (`InlineForms.validate_no_archived_form_elements_for!`) skips an archived
49
+ symbol when the app's helpers (`ApplicationController.helpers`) answer
50
+ `<name>_show`, so the element is then the app's. The archived files are
51
+ written in the old top-level `def` style; wrap them in a helper module
52
+ (`module GeoCodeCuracaoHelper … end`) and replace any jQuery/UJS they use.
53
+
42
54
  ## Adding a new archive entry
43
55
 
44
56
  When retiring a form element:
@@ -70,17 +70,23 @@ module InlineForms
70
70
  }
71
71
  }.freeze
72
72
 
73
- def self.validate_no_archived_form_elements_for!(klass)
73
+ # An app that vendors an archived element (copies its helper into its own
74
+ # app/helpers, see archived/README.md) defines `<element>_show` itself: the
75
+ # element is then the app's, and allowed. `helpers` is the view helper
76
+ # proxy to ask (default: ApplicationController's, with all app helpers).
77
+ def self.validate_no_archived_form_elements_for!(klass, helpers: nil)
74
78
  return unless klass.instance_methods.include?(:inline_forms_attribute_list)
75
79
 
76
80
  klass.new.inline_forms_attribute_list.each do |attribute, form_element|
77
81
  key = form_element.to_sym
78
82
  next unless ARCHIVED_FORM_ELEMENTS.key?(key)
83
+ next if vendored_form_element?(key, helpers)
79
84
 
80
85
  meta = ARCHIVED_FORM_ELEMENTS[key]
81
86
  version = meta[:archived_in_version] || meta[:removed_in_version]
82
87
  hint = if meta[:archive_path]
83
- "Restore from #{meta[:archive_path]}/README.md or vendor into your app."
88
+ "Vendor it into your app: define #{key}_show (and _edit, _update) in an app helper " \
89
+ "(#{meta[:archive_path]}/README.md, archived/README.md)."
84
90
  else
85
91
  "See archived/README.md and CHANGELOG #{version}."
86
92
  end
@@ -90,4 +96,11 @@ module InlineForms
90
96
  "which was retired in inline_forms #{version} (#{meta[:summary]}). #{hint}"
91
97
  end
92
98
  end
99
+
100
+ def self.vendored_form_element?(key, helpers = nil)
101
+ helpers ||= ::ApplicationController.helpers if defined?(::ApplicationController)
102
+ !!helpers&.respond_to?(:"#{key}_show")
103
+ rescue StandardError
104
+ false
105
+ end
93
106
  end
@@ -7,7 +7,7 @@ module InlineForms
7
7
 
8
8
  # date
9
9
  def date_select_show(object, attribute)
10
- link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).to_date.strftime("%d-%m-%Y"), from_callee: __callee__
10
+ link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).to_date.strftime(InlineForms::DATE_FORMAT), from_callee: __callee__
11
11
  end
12
12
 
13
13
  # Native <input type="date"> (8.1.25; replaces jQuery UI datepicker).
@@ -23,7 +23,7 @@ module InlineForms
23
23
  end
24
24
 
25
25
  def date_select_info(object, attribute)
26
- object.send(attribute).nil? ? "-" : object.send(attribute).to_date
26
+ object.send(attribute).nil? ? "-" : object.send(attribute).to_date.strftime(InlineForms::DATE_FORMAT)
27
27
  end
28
28
  INLINE_FORMS_FORM_ELEMENT
29
29
  end
@@ -9,6 +9,7 @@ module InlineForms
9
9
  # show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
10
10
  o = object.send(attribute)
11
11
  o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
12
+ o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
12
13
  o = o._presentation if o.respond_to?(:_presentation)
13
14
  o
14
15
  end
@@ -16,6 +17,7 @@ module InlineForms
16
17
  def info_edit(object, attribute)
17
18
  o = object.send(attribute)
18
19
  o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
20
+ o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
19
21
  o = o._presentation if o.respond_to?(:_presentation)
20
22
  o
21
23
  end
@@ -28,6 +30,7 @@ module InlineForms
28
30
  # show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
29
31
  o = object.send(attribute)
30
32
  o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
33
+ o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
31
34
  o = o._presentation if o.respond_to?(:_presentation)
32
35
  o
33
36
  end
@@ -12,13 +12,17 @@ module InlineForms
12
12
  #
13
13
  # :contains anywhere in the value ("ma" finds Martina, Tinamart, Tima)
14
14
  # :start at the start of the value ("ma" finds Martina only)
15
- # :word at the start of any word ("ma" finds Martina, Anna Maria)
15
+ # :word at the start of any word ("ma" finds Martina, Anna Maria);
16
+ # a word starts after a space, a hyphen or an apostrophe
17
+ # ("marc" finds Jean-Marc, "brien" O'Brien and O’Brien)
16
18
  #
17
19
  # The answer: at most `limit` values, each once (compared stripped and in any
18
20
  # case, the first in A-Z order kept), in case-insensitive A-Z order. An empty
19
21
  # term gives [].
20
22
  module Suggestions
21
23
  MATCHES = %i[contains start word].freeze
24
+ # What starts a word for match: :word, besides the start of the value.
25
+ WORD_STARTS = [ " ", "-", "'", "’" ].freeze
22
26
  LIMIT = 12
23
27
 
24
28
  module_function
@@ -77,7 +81,7 @@ module InlineForms
77
81
  case match
78
82
  when :contains then [ "%#{escaped}%" ]
79
83
  when :start then [ "#{escaped}%" ]
80
- when :word then [ "#{escaped}%", "% #{escaped}%" ]
84
+ when :word then [ "#{escaped}%", *WORD_STARTS.map { |start| "%#{start}#{escaped}%" } ]
81
85
  end
82
86
  end
83
87
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module InlineForms
4
- VERSION = "8.1.79"
4
+ VERSION = "8.1.81"
5
5
  end
data/lib/inline_forms.rb CHANGED
@@ -70,6 +70,14 @@ module InlineForms
70
70
  # Is this user the superadmin? An app that has its own answer
71
71
  # (`User#superadmin?`, e.g. only user 1) is asked first; otherwise it is
72
72
  # whoever holds the role. A user class with neither is not a superadmin.
73
+ # True when the app has Action Text and its table. An app may load the
74
+ # Action Text railtie (rails/all) without ever installing it, and then has
75
+ # no action_text_rich_texts table: the versions panel and the undo of a
76
+ # delete look for rich text versions only when the table is there.
77
+ def self.action_text_table?
78
+ defined?(ActionText::RichText) ? ActionText::RichText.table_exists? : false
79
+ end
80
+
73
81
  def self.superadmin?(user)
74
82
  return !!user.superadmin? if user.respond_to?(:superadmin?)
75
83
 
@@ -201,6 +209,8 @@ module InlineForms
201
209
  # Version and file timestamps: time.formats.inline_forms in the gem's en
202
210
  # and nl locales, and the default where a locale lacks it.
203
211
  TIME_FORMAT = "%d %b %Y %H:%M"
212
+ # A date as the engine shows it (date_select, info, the versions panel).
213
+ DATE_FORMAT = "%d-%m-%Y"
204
214
 
205
215
  # The application's name for the gem's titles and the Devise pages: the
206
216
  # host's `application_name` translation, else its
@@ -4,6 +4,7 @@ en:
4
4
  # models that declare inline_forms_search_on.
5
5
  search:
6
6
  placeholder: "search..."
7
+ label: search
7
8
  submit: search
8
9
  reset: reset
9
10
  # general.application_title, devise.title_for_devise and devise.welcome
@@ -4,6 +4,7 @@ nl:
4
4
  # models that declare inline_forms_search_on.
5
5
  search:
6
6
  placeholder: "zoeken..."
7
+ label: zoeken
7
8
  submit: zoek
8
9
  reset: wissen
9
10
  # general.application_title, devise.title_for_devise and devise.welcome
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.79
4
+ version: 8.1.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares
@@ -113,6 +113,7 @@ files:
113
113
  - app/assets/stylesheets/inline_forms_fonts.css.erb
114
114
  - app/controllers/concerns/cancan_concern.rb
115
115
  - app/controllers/concerns/file_slots_concern.rb
116
+ - app/controllers/concerns/suggestion_request_concern.rb
116
117
  - app/controllers/concerns/suggestions_concern.rb
117
118
  - app/controllers/concerns/versions_concern.rb
118
119
  - app/controllers/inline_forms/file_trash_controller.rb