trek 2.4.0 → 2.5.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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +6 -5
  3. data/CHANGELOG.md +25 -0
  4. data/Gemfile.lock +192 -171
  5. data/Makefile +26 -1
  6. data/README.md +2 -2
  7. data/app/components/trek/form/image_field_component.rb +1 -5
  8. data/app/components/trek/list/item_component.rb +1 -1
  9. data/app/components/trek/list/tree/item_component.rb +2 -2
  10. data/app/components/trek/search_component/search_component.html.slim +2 -1
  11. data/app/components/trek/search_component.rb +9 -1
  12. data/app/content/trek/content/bullet_list.rb +10 -0
  13. data/app/content/trek/content/document.rb +33 -0
  14. data/app/content/trek/content/image_block.rb +52 -0
  15. data/app/content/trek/content/link_resolver.rb +33 -0
  16. data/app/content/trek/content/list_item.rb +19 -0
  17. data/app/content/trek/content/ordered_list.rb +10 -0
  18. data/app/content/trek/content/paragraph.rb +10 -0
  19. data/app/content/trek/content/prompts_block.rb +22 -0
  20. data/app/content/trek/content.rb +32 -0
  21. data/app/controllers/concerns/trek/reorderable.rb +14 -3
  22. data/app/controllers/trek/csp_reports_controller.rb +3 -6
  23. data/app/controllers/trek/panels/base_controller.rb +3 -0
  24. data/app/controllers/trek/panels/links_controller.rb +1 -1
  25. data/app/controllers/trek/panels/prompts_controller.rb +1 -1
  26. data/app/helpers/trek/thumbnail_helper.rb +11 -0
  27. data/app/models/concerns/trek/contentable.rb +9 -14
  28. data/app/models/concerns/trek/pageable.rb +10 -1
  29. data/app/views/trek/panels/images/_form.html.slim +1 -1
  30. data/app/views/trek/panels/images/create.turbo_stream.slim +1 -1
  31. data/app/views/trek/panels/links/_form.html.slim +1 -1
  32. data/app/views/trek/panels/prompts/_form.html.slim +1 -1
  33. data/config/locales/trek.en.yml +23 -0
  34. data/config/locales/trek.fr.yml +23 -0
  35. data/docs/getting-started.md +3 -3
  36. data/docs/reference/concerns/contentable.md +2 -1
  37. data/docs/reference/controllers.md +1 -1
  38. data/docs/reference/formatters.md +31 -8
  39. data/docs/reference/models/fragment.md +1 -0
  40. data/docs/what-is-trek.md +4 -4
  41. data/lib/generators/trek/helpers.rb +13 -5
  42. data/lib/generators/trek/install/admin_generator.rb +8 -0
  43. data/lib/generators/trek/install/appsignal_generator.rb +1 -1
  44. data/lib/generators/trek/install/authentication_generator.rb +1 -1
  45. data/lib/generators/trek/install/authorization_generator.rb +1 -1
  46. data/lib/generators/trek/install/postmark_generator.rb +2 -2
  47. data/lib/generators/trek/install/specs_generator.rb +11 -0
  48. data/lib/generators/trek/install/user_generator.rb +1 -1
  49. data/lib/generators/trek/scaffold_generator.rb +13 -5
  50. data/lib/generators/trek/templates/Makefile +1 -1
  51. data/lib/generators/trek/templates/controllers/admin/fragments_controller.rb +7 -0
  52. data/lib/generators/trek/templates/controllers/admin/panels/images_controller.rb +8 -0
  53. data/lib/generators/trek/templates/controllers/admin/panels/links_controller.rb +8 -0
  54. data/lib/generators/trek/templates/controllers/admin/panels/prompts_controller.rb +8 -0
  55. data/lib/generators/trek/templates/models/fragment.rb +14 -0
  56. data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +2 -1
  57. data/lib/generators/trek/templates/spec/requests/admin/active_sessions_spec.rb +1 -0
  58. data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +26 -2
  59. data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +8 -0
  60. data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +54 -0
  61. data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +5 -3
  62. data/lib/generators/trek/templates/views/admin/fragments/index.html.slim +14 -3
  63. data/lib/trek/engine.rb +8 -3
  64. data/lib/trek/saved_attachments_reload.rb +2 -1
  65. data/lib/trek/version.rb +1 -1
  66. data/lib/trek.rb +1 -1
  67. data/package.json +1 -1
  68. data/renovate.json +1 -0
  69. data/trek.gemspec +3 -3
  70. data/yarn.lock +842 -880
  71. metadata +29 -14
  72. data/app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb +0 -19
  73. data/app/formatters/prosemirror_to_html/nodes/image_block.rb +0 -44
  74. data/app/formatters/prosemirror_to_html/nodes/prompts_block.rb +0 -28
  75. data/app/formatters/prosemirror_to_html/remove_empty_paragraphs_formatter.rb +0 -11
  76. data/app/models/prosemirror.rb +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6b28d4e87e1861c153d7530027c8168d8c7a045ad7c9c7183dd9be51b6dea00
4
- data.tar.gz: dcc8a94c84e5d9b12b435d179e9b1ee4c11403417017b1a48a642b466ee93514
3
+ metadata.gz: 83354e52923bd77162639c74f5e45fcdfbeed812c4b2cbbad7c6b28c987ef8e0
4
+ data.tar.gz: 6a9d8038dbc513ecf9e7fdc119f874532e0c422e9aeb9fd6bb158d335542e839
5
5
  SHA512:
6
- metadata.gz: 7802978221fd22ae6b4658fca4daf2507f59397846880eb54627e41c84a1a6892d6fbb1ef68de18ec97b587b06da06ccbfc4585296e399e14e4e59a870173779
7
- data.tar.gz: 4a7c2ea62d3c03f99dd03f148fc7af401a339661f031e50e7d4a844d28374aae1641a8a76102067cc93e2f3e471a8475eac8ee8306befe9b4882d0248d695059
6
+ metadata.gz: c9ad87bb1b169ede12d9efce481f385aa2aaf10a76381ccb652ff048846ce7924a0d1db97eb358b0c5e968960d658683b5b4449d4304401cd387e1d9c635c257
7
+ data.tar.gz: 4cadf24ff3c2ff45fd419ea97100add550d6e0d6431913b2b07fb94f597eaffb861174648c8f23803056fb87b5ed09ff4426add34aba2be92b6ae772884e0264
data/AGENTS.md CHANGED
@@ -8,7 +8,7 @@ Trek is a customizable CMS for Ruby on Rails, shipped as a **Ruby gem** (`trek`)
8
8
 
9
9
  ## Tech stack
10
10
 
11
- - **Ruby** `>= 3.1` (RuboCop targets 3.4) · **Rails** `>= 6.0, < 8.2` (lockfile 8.1.3; host apps need 7.0+)
11
+ - **Ruby** `>= 3.3` (RuboCop targets 3.4) · **Rails** `>= 8.0, < 8.2` (lockfile 8.1.4)
12
12
  - **Node** 24.22.0 (`.node-version`) · **Yarn** 4.18.1 with its defaults: no install scripts, no package published less than a day ago · **PostgreSQL** 12+ · **libvips** for images
13
13
  - Backend: `action_policy`, `closure_tree`, `acts_as_list`, `mobility` + `i18n-tasks`, `shrine` (+ blurhash/image_processing/aws-sdk-s3), `view_component` + `slim-rails` + `lookbook`, `kaminari`, `deepl-rb`
14
14
  - Frontend: **esbuild** (`esbuild.config.js`) + **PostCSS** (`postcss.config.js`); Stimulus/Turbo, TipTap, Uppy, Tom Select, SortableJS
@@ -22,7 +22,8 @@ bin/console # IRB with trek loaded
22
22
  rake # default: spec + rubocop
23
23
  rake spec # run tests (or: bundle exec rspec)
24
24
  COVERAGE=1 bundle exec rspec # tests + SimpleCov report in coverage/ (fails under the minimum set in spec/spec_helper.rb)
25
- make lint # all linters below
25
+ make lint # all linters below (make -k lint to run them all despite a failure)
26
+ make security # brakeman + bundler-audit
26
27
  make fix # rubocop/eslint/stylelint/prettier autocorrect, then make i18n-normalize
27
28
  make i18n-normalize # sort the locale keys (i18n-tasks normalize), then Prettier them; CI checks it
28
29
  make release # bump version (version.rb + package.json), stamp CHANGELOG, tag, push gem + npm
@@ -50,7 +51,7 @@ Security: `bundle exec brakeman` · `bundle exec bundle-audit check --update`
50
51
  - `spec/` — RSpec suite, two kinds of spec:
51
52
  - **isolated** (`require_relative` the file under test, stub its host): concerns, helpers, simple components
52
53
  - **Rails** (`require "rails_helper"`): boots `spec/dummy`, a minimal host app on PostgreSQL (`trek_test`, or `DATABASE_URL`). Its models, migrations, Shrine initializer and the whole admin (controllers, views, routes, policies, mailers) are not committed: `spec/dummy/lib/generated_files.rb` runs Trek's own generator steps into `tmp/dummy` on every boot, and the database is rebuilt from them. A new model or migration template must be added to its `STEPS`, or `spec/dummy/generated_files_spec.rb` fails.
53
- - **Host-app specs**: model, admin request, policy and mailer specs and their [Oaken](https://github.com/kaspth/oaken) seeds are templates (`lib/generators/trek/templates/{spec/models,spec/requests,spec/policies,spec/mailers,db/seeds}/`), installed in host apps by `trek:install:model_specs` and run by Trek's suite from `tmp/dummy` (`spec/dummy/generated_specs_spec.rb`); test data comes from `users.create`, `pages.create` and `seed "cases/…"`, not factories. Write specs for Trek's models there, in host-app style (no `frozen_string_literal`, Ruby 3.1-compatible — no bare `it` block parameter), so host apps get them too.
54
+ - **Host-app specs**: model, admin request, policy and mailer specs and their [Oaken](https://github.com/kaspth/oaken) seeds are templates (`lib/generators/trek/templates/{spec/models,spec/requests,spec/policies,spec/mailers,db/seeds}/`), installed in host apps by `trek:install:model_specs` and run by Trek's suite from `tmp/dummy` (`spec/dummy/generated_specs_spec.rb`); test data comes from `users.create`, `pages.create` and `seed "cases/…"`, not factories. Write specs for Trek's models there, in host-app style (no `frozen_string_literal`, Ruby 3.3-compatible — no bare `it` block parameter), so host apps get them too.
54
55
  - **Generators** (`spec/trek/generators_spec.rb`): every generator runs on a copy of a real `rails new` app (`spec/support/generators.rb`, built once per run into `tmp/generator_skeleton`), then again to check it changes nothing. Shell-outs are recorded in `shell_commands`, not run. A new generator is picked up automatically; if it needs arguments, an earlier Trek step or a starting file, add it to the spec's `arguments`, `prerequisites` or `setups`.
55
56
  - Both kinds run in one process, so an isolated spec must restore any global it changes (`I18n`, `Shrine` storages…). `spec_helper` loads Rails and Action View before Trek, as a host app does: several dependencies (ActionPolicy, Slim, ViewComponent) configure themselves from what is already loaded.
56
57
  - `docs/` — VitePress site
@@ -61,8 +62,8 @@ Security: `bundle exec brakeman` · `bundle exec bundle-audit check --update`
61
62
  - **Slim** linted via slim_lint; **JS/CSS** via ESLint + Stylelint + Prettier 2.8.8
62
63
  - **i18n**: keep English + French locales in sync (`config/locales/trek.*.yml`); DeepL auto-translation via `DEEPL_AUTH_KEY`
63
64
  - **Versioning**: version lives in both `lib/trek/version.rb` and `package.json` — keep in sync via `make release`
64
- - **CHANGELOG.md**: Keep-a-Changelog format. **Every MR must add an `[Unreleased]` entry.** Keep entries short: one or two sentences on what changed for host apps, not how it was found or fixed — the MR description holds the details. When the change requires action in the host app on upgrade, end the entry with a bold `**Upgrade note:**` label followed by what to do. Use the same label when the change lets host apps remove or simplify existing patches or custom implementations (e.g. "**Upgrade note:** you can now drop your custom …") — never as an unlabelled trailing sentence.
65
+ - **CHANGELOG.md**: Keep-a-Changelog format. **Every MR must add an `[Unreleased]` entry**, except one that only changes specs. Keep entries short: one or two sentences on what changed for host apps, not how it was found or fixed — the MR description holds the details. When the change requires action in the host app on upgrade, end the entry with a bold `**Upgrade note:**` label followed by what to do. Use the same label when the change lets host apps remove or simplify existing patches or custom implementations (e.g. "**Upgrade note:** you can now drop your custom …") — never as an unlabelled trailing sentence.
65
66
  - **Generated model names**: a new model template belonging to another model is nested under it, in `models/<owner>/` (`User::Session`, `User::PreviousPassword`), not prefixed (`UserSession`). Nested in an Active Record model, it keeps the prefixed table name (`user_sessions`) and its owner's `has_many` finds it without `class_name:`. The older `PagePath`, `PageVersion` and `TagCategory` move in Trek 3 (#248).
66
67
  - **Generators' npm packages**: the install generators' `NPM_DEPENDENCIES` (`lib/generators/trek/install/*_generator.rb`) add to host apps the packages needed by the config files they copy from Trek's root (`esbuild.config.js`, `postcss.config.js`, `.eslintrc.json`, `.stylelintrc.json`, `lefthook.yml`). When a package is bumped in Trek's `package.json` — by hand or by Renovate, which doesn't touch the generators — bump its range in the generator in the same MR, or new apps get a version the copied config may not work with (as esbuild 0.15 did). List only packages those configs or the generated scripts use.
67
68
  - **Public code**: Trek ships publicly (gem, npm, docs), so nothing committed may mention a client or project name, nor a client's domain models or business logic — not in code, comments, specs, templates, docs, CHANGELOG or commit messages. Use neutral examples (`Page`, `Shop::Product`, an engine's `Blog::Post`). Client context belongs in GitLab issues and MR descriptions only.
68
- - **CI**: GitLab CI (`.gitlab-ci.yml`), stages build → lint → security → test → deploy; docs deploy to Netlify; deps via Renovate
69
+ - **CI**: GitLab CI (`.gitlab-ci.yml`), stages build → lint (one job: `make -k lint security i18n-check`) → test → deploy, the test jobs starting without waiting for lint; docs deploy to Netlify; deps via Renovate
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.5.0] - 2026-10-25
4
+
5
+ ### Changed
6
+
7
+ - **Security:** rich text is rendered with the [`prosemirror`](https://github.com/etaminstudio/prosemirror) gem instead of `prosemirror_to_html`, which had two XSS advisories: HTML is escaped as it is built, attributes are typed, and links and images only allow `http`, `https`, `mailto`, `tel` and relative URLs. The content editor's image and prompt blocks render out of the box (`Trek::Content::ImageBlock`, `Trek::Content::PromptsBlock`), empty list items and lists are skipped like empty paragraphs, invalid content is reported to `Rails.error`, with the record holding it in the context (`trek_content: "Page#12"`, a tag in AppSignal), and the records that a page's links point to load at once, with one query per model. See [Rich text rendering](https://trek.etamin.studio/reference/formatters#rich-text-rendering). **Upgrade note:** the `Prosemirror` model and the `ProsemirrorToHtml` formatters are removed: call `formatted_content`, or `Trek::Content.schema.parse(content).to_html`, instead of `Prosemirror.new.format_content`, and rewrite the app's `ProsemirrorToHtml` nodes as node types registered in `Trek::Content.schema` (see [Custom blocks](https://trek.etamin.studio/reference/formatters#custom-blocks)).
8
+ - Trek requires **Rails 8.0** or later (was 6.0) and **Ruby 3.3** (was 3.1: Rails 8 needs 3.2, and the `prosemirror` gem 3.3). Its authentication already relied on Rails 8: `has_secure_password`'s `:password_reset` token and `password_reset_token`, without which a password reset fails on Rails 7.2 (`KeyError: key not found: :password_reset`) and so does a password renewal (`NoMethodError`). **Upgrade note:** an app on Rails 7 upgrades Rails before Trek (see the [Rails 8.0 upgrade guide](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-7-2-to-rails-8-0)); meanwhile, it can declare the token in `app/models/user.rb`, after `has_secure_password`: `generates_token_for(:password_reset, expires_in: 15.minutes) { password_salt&.last(10) }` and `def password_reset_token = generate_token_for(:password_reset)`.
9
+ - Trek is now developed and tested against **css_parser 3.3** (was 3.0), which Lookbook, a Trek dependency, brings in: 3.2 and 3.3 fix a ReDoS on an unclosed CSS function ([GHSA-84w7-hpvm-rxx2](https://github.com/premailer/css_parser/security/advisories/GHSA-84w7-hpvm-rxx2)) and a local file read through `@import` ([GHSA-w3mx-4vv9-hjpg](https://github.com/premailer/css_parser/security/advisories/GHSA-w3mx-4vv9-hjpg)). **Upgrade note:** run `bundle update css_parser` if the app's `Gemfile.lock` has an older one.
10
+ - Trek is now developed and tested against **crass 1.0.8** (was 1.0.7), which Loofah and rails-html-sanitizer bring in to sanitize CSS: it fixes a CSS sanitizer bypass through bad URLs ([GHSA-pq4g-8rxf-4g29](https://github.com/rgrove/crass/security/advisories/GHSA-pq4g-8rxf-4g29)). **Upgrade note:** run `bundle update crass` if the app's `Gemfile.lock` has an older one.
11
+ - The generators no longer print RuboCop's report when they autocorrect the files they inject code into, only an `autocorrect` line per file; an offense RuboCop can't correct is still shown, and stops the install.
12
+ - Trek's own CI is faster: its linters and security checks run in one job (`make -k lint security i18n-check`, with a `make` target per tool), the tests no longer wait for them, and the generated app's install keeps its gems and Rails in a cache, one per Ruby version, and is skipped for changes to the docs or the repository's tooling; it no longer installs Trek's own gems and packages first. Nothing changes for host apps.
13
+ - The admin's fragments index shows each fragment's title, its key (`namespace.key`) and the start of its content, with `Trek::EntriesComponent`, instead of only its key, and has a search box matching the key, the title or the content's text (`Fragment.search`). **Upgrade note:** to get them, copy from Trek's templates (`lib/generators/trek/templates/`) `views/admin/fragments/index.html.slim`, the `search` scope of `models/fragment.rb`, and `controllers/admin/fragments_controller.rb`.
14
+
15
+ ### Fixed
16
+
17
+ - Since 0.1.18, rendering rich text that links to a page raised `NoMethodError: undefined method 'page_url'`: page links are turned into URLs with `url_for`, which needs `Trek::PagePathHelper`, no longer included. An app's own `direct :page` route still takes precedence. **Upgrade note:** you can now drop initializers that include `Trek::PagePathHelper` in `ProsemirrorToHtml::GlobalIdToLinksFormatter`.
18
+ - Since 2.4.0, the site's links to pageable records (`Trek::Pageable`) used their id instead of their page's slug: `to_param` took the admin IP allowlist middleware, in the stack of every request, for an admin caller.
19
+ - The content editor's link, image and prompt panels opened empty ("Content missing"): the installer routed them to `Admin::Panels` controllers it didn't generate. It now generates them, subclasses of `Trek::Panels::*` that serve Trek's panels under the app's routes. The panels' titles, field labels and image sizes are translated, and the link panel no longer needs `OpenStruct`, which Ruby doesn't load by default since 3.5. **Upgrade note:** run `rails g trek:install:admin` and keep only its new `app/controllers/admin/panels/*_controller.rb`, or copy them from Trek's templates (`lib/generators/trek/templates/controllers/admin/panels`); you can then drop your own translations of `trek.panels.*.form.title`, of `activemodel.attributes.trek/content_editor/*` and of the image sizes, and the `ostruct` gem if nothing else needs it. Re-run `rails g trek:install:model_specs` for the new `spec/requests/admin/panels_spec.rb`.
20
+ - `Trek::Reorderable` gives the views `reorder_path`, which the scaffolded index's commented-out reorder form uses, and reorders without Prosopite taking acts_as_list's repeated queries for an N+1. **Upgrade note:** you can now drop your own `helper_method :reorder_path` and Prosopite pause around `reorder`.
21
+ - The admin's lists, the pages' tree and the content editor's image panel raised `NoMethodError: undefined method 'derivation_url'` on an image when the image uploader doesn't load Shrine's derivation endpoint, as the generated `ImageUploader` doesn't: they show the image itself instead, as the image field already did (`Trek::ThumbnailHelper.thumbnail_url`). **Upgrade note:** you can now drop the derivation endpoint if you enabled it only for these thumbnails.
22
+ - The specs installed by `trek:install:model_specs` pass in an app whose default locale isn't English: the three examples reading browser descriptions ("Firefox on Windows") use an English-speaking user. **Upgrade note:** re-run `rails g trek:install:model_specs`, or drop your own locale workarounds in `spec/mailers/admin_mailer_spec.rb`, `spec/requests/admin/sign_in_notices_spec.rb` and `spec/requests/admin/active_sessions_spec.rb`.
23
+ - `trek:scaffold` passes the attributes to the model generator as given: it dropped their indexes (`slug:string:uniq`, `isbn:string:index`), references' options (`author:references{polymorphic}`) and decimals' precision (`price:decimal{10,2}`).
24
+ - The generated `Makefile` lints every Slim template: unquoted, `make`'s shell expanded `app/**/*.slim` one directory deep only, so `make lint` skipped what CI caught. **Upgrade note:** quote the pattern in your `Makefile`'s `lint` target: `bundle exec slim-lint "app/**/*.slim"`.
25
+ - `trek:install:specs` includes the matchers of rspec-html-matchers (`have_tag`, `with_tag`), which it adds to the Gemfile, in `spec/rails_helper.rb`. **Upgrade note:** add `config.include RSpecHtmlMatchers` to the `RSpec.configure` block of `spec/rails_helper.rb` to use them.
26
+ - `Trek::SearchComponent` labels its field in the admin's language by default (it was always « Rechercher »), and its label is tied to the field, which has an id of its own: clicking the label focuses the field, and screen readers announce the field by its label.
27
+
3
28
  ## [2.4.0] - 2026-10-16
4
29
 
5
30
  ### Added