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
@@ -16,15 +16,38 @@ include Trek::Formattable
16
16
  format_attributes Trek::TypographyFormatter, :title
17
17
  ```
18
18
 
19
- ## ProseMirror → HTML pipeline
19
+ ## Rich text rendering
20
20
 
21
- `formatted_content` (from [Contentable](/reference/concerns/contentable)) renders ProseMirror JSON to safe HTML through the `prosemirror_to_html` gem, extended with:
21
+ `formatted_content` (from [Contentable](/reference/concerns/contentable)) renders the content editor's ProseMirror JSON to HTML with the [`prosemirror`](https://github.com/etaminstudio/prosemirror) gem. HTML is escaped as it is built, attributes are typed, and links and images only allow `http`, `https`, `mailto`, `tel` and relative URLs. Invalid content is fixed and reported to `Rails.error`.
22
22
 
23
- | Piece | Role |
23
+ `Trek::Content.schema` is Tiptap's schema, with:
24
+
25
+ | Node type | Role |
24
26
  | --- | --- |
25
- | `Nodes::ImageBlock` | renders `image_block` nodes as figures (Shrine image, alt, caption, size) |
26
- | `Nodes::PromptsBlock` | renders `prompts_block` nodes as call-to-action buttons |
27
- | `RemoveEmptyParagraphsFormatter` | strips empty `<p></p>` tags |
28
- | `GlobalIdToLinksFormatter` | resolves `gid://` references in links to real record URLs |
27
+ | `Trek::Content::Paragraph` | skips empty paragraphs |
28
+ | `Trek::Content::ListItem` | skips empty list items, with no content or only empty paragraphs |
29
+ | `Trek::Content::BulletList`, `OrderedList` | skip lists with only empty items |
30
+ | `Trek::Content::ImageBlock` | renders image blocks as a `<figure>`: the image, its caption and credit |
31
+ | `Trek::Content::PromptsBlock` | renders prompt blocks as a link |
32
+
33
+ Links to records are stored as GlobalIDs (`gid://app/Page/1`). `Trek::Content::LinkResolver` turns them into the record's URL with `url_for`, loading the records of a document's links at once, with one query per model; a link to a deleted record is removed and its text kept, and reported to `Rails.error` as a `Prosemirror::UnresolvedURL`. Problems in content are reported with the record holding it in their context (`trek_content: "Page#12"`), which AppSignal shows as a tag.
34
+
35
+ ### Custom blocks
36
+
37
+ Node types are [Phlex](https://www.phlex.fun) components with [Literal](https://literal.fun) properties (see the [`prosemirror` README](https://github.com/etaminstudio/prosemirror#custom-nodes-and-marks)). To render the image block with the app's own component, subclass it and register it in an initializer:
38
+
39
+ ```ruby
40
+ # app/content/image_block.rb
41
+ class ImageBlock < Trek::Content::ImageBlock
42
+ def view_template
43
+ render Components::Figure.new(src: image&.url, alt: @alt, caption: @text, credit: @credit)
44
+ end
45
+ end
46
+
47
+ # config/initializers/trek.rb
48
+ Rails.application.config.to_prepare do
49
+ Trek::Content.schema = Trek::Content.default_schema.with(ImageBlock)
50
+ end
51
+ ```
29
52
 
30
- The pipeline is orchestrated by the `Prosemirror` model — extend it with your own node renderers when you add custom blocks to the editor.
53
+ The same works for a node type of your own, added to the editor with a Tiptap extension.
@@ -16,6 +16,7 @@ Reusable chunks of content — a footer text, a hero tagline, a contact blurb
16
16
 
17
17
  - Includes [Contentable](/reference/concerns/contentable), [Translatable](/reference/concerns/translatable) (`title`, `content`), [Keyable](/reference/concerns/keyable) and `strip_attributes`
18
18
  - `acts_as_list scope: [:namespace]` with an `ordered` scope
19
+ - A `search(query)` scope, case-insensitive, matching the key (`namespace.key`), the title or the text of the content in the current locale. The admin's fragments index searches with it.
19
20
  - `to_s` returns `"namespace.key"`
20
21
 
21
22
  ## Usage
data/docs/what-is-trek.md CHANGED
@@ -27,11 +27,11 @@ Trek follows the Rails way:
27
27
 
28
28
  | Dependency | Version |
29
29
  | --- | --- |
30
- | Ruby | 3.1+ |
31
- | Rails | 7.0+ |
30
+ | Ruby | 3.3+ |
31
+ | Rails | 8.0+ |
32
32
  | PostgreSQL | 12+ |
33
- | Node | 20+ |
34
- | Yarn | 3.x |
33
+ | Node | 22+ |
34
+ | Yarn | 4.x |
35
35
  | libvips | — |
36
36
 
37
37
  Ready to try it? Head over to the [quick start](/getting-started).
@@ -30,11 +30,7 @@ module Trek
30
30
  end
31
31
 
32
32
  def migration_class_name
33
- if Rails::VERSION::MAJOR >= 5
34
- "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
35
- else
36
- "ActiveRecord::Migration"
37
- end
33
+ "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
38
34
  end
39
35
 
40
36
  def in_gemfile?(gem_name)
@@ -60,6 +56,18 @@ module Trek
60
56
  copy_file filename, filename
61
57
  end
62
58
 
59
+ # Runs `rubocop --autocorrect` on the files a step just changed. Quiet unless an offense is left
60
+ # uncorrected, which stops the generator: the offenses it corrects are the expected result of
61
+ # injecting code.
62
+ def rubocop_autocorrect(paths, only: nil)
63
+ return unless behavior == :invoke
64
+
65
+ say_status :autocorrect, paths
66
+ command = "rubocop --autocorrect --format quiet --display-only-fail-level-offenses"
67
+ command += " --only #{only}" if only
68
+ run "#{command} #{paths}", abort_on_failure: true, verbose: false
69
+ end
70
+
63
71
  def install_npm_dependencies(dependencies, dev: false)
64
72
  run "yarn add #{dependencies.map { |name, version| "#{name}@#{version}" }.join(" ")} #{dev ? "--dev" : ""}", abort_on_failure: true
65
73
  end
@@ -53,6 +53,14 @@ module Trek
53
53
  template "controllers/admin/uploads_controller.rb",
54
54
  "app/controllers/admin/uploads_controller.rb"
55
55
  end
56
+
57
+ # The content editor's panels, which the admin routes point to (trek:install:admin:routes)
58
+ def add_panels_controllers
59
+ %w[links images prompts].each do |panel|
60
+ template "controllers/admin/panels/#{panel}_controller.rb",
61
+ "app/controllers/admin/panels/#{panel}_controller.rb"
62
+ end
63
+ end
56
64
  end
57
65
  end
58
66
  end
@@ -64,7 +64,7 @@ module Trek
64
64
  inject_into_class "app/controllers/application_controller.rb",
65
65
  "ApplicationController",
66
66
  " include AppsignalContext\n"
67
- run "rubocop --autocorrect app/controllers/application_controller.rb", abort_on_failure: true
67
+ rubocop_autocorrect "app/controllers/application_controller.rb"
68
68
  end
69
69
 
70
70
  def include_context_in_trek_controllers
@@ -117,7 +117,7 @@ module Trek
117
117
  end
118
118
 
119
119
  def autocorrect_user_model
120
- run "rubocop --autocorrect #{user_model_path}"
120
+ rubocop_autocorrect user_model_path
121
121
  end
122
122
 
123
123
  private
@@ -27,7 +27,7 @@ module Trek
27
27
  inject_into_class application_policy_file_path,
28
28
  "ApplicationPolicy",
29
29
  application_policy_injection
30
- run "rubocop --autocorrect #{application_policy_file_path}", abort_on_failure: true
30
+ rubocop_autocorrect application_policy_file_path
31
31
  end
32
32
 
33
33
  def copy_policy_files
@@ -24,7 +24,7 @@ module Trek
24
24
  "ApplicationMailer",
25
25
  application_mailer_injection,
26
26
  after: ' layout "mailer"\n'
27
- run "rubocop --autocorrect app/mailers/application_mailer.rb", abort_on_failure: true
27
+ rubocop_autocorrect "app/mailers/application_mailer.rb"
28
28
  end
29
29
 
30
30
  def inject_postmark_to_config
@@ -33,7 +33,7 @@ module Trek
33
33
  inject_into_file "config/environments/production.rb",
34
34
  config_injection,
35
35
  after: %r{# Specify outgoing SMTP server\. Remember to add smtp/\* credentials via (?:bin/)?rails credentials:edit\.\n}
36
- run "rubocop --autocorrect config/environments/production.rb", abort_on_failure: true
36
+ rubocop_autocorrect "config/environments/production.rb"
37
37
  end
38
38
 
39
39
  def inject_postmark_to_credentials
@@ -27,6 +27,17 @@ module Trek
27
27
  generate "rspec:install"
28
28
  end
29
29
 
30
+ # `have_tag` and `with_tag`, from the rspec-html-matchers gem added above
31
+ def include_html_matchers
32
+ rails_helper = File.join(destination_root, "spec/rails_helper.rb")
33
+ return unless File.exist?(rails_helper)
34
+ return if File.read(rails_helper).include?("RSpecHtmlMatchers")
35
+
36
+ inject_into_file "spec/rails_helper.rb",
37
+ " config.include RSpecHtmlMatchers\n",
38
+ after: /^RSpec\.configure do \|config\|\n/
39
+ end
40
+
30
41
  def create_rspec_config
31
42
  create_file ".rspec", <<~TEXT
32
43
  --format documentation
@@ -45,7 +45,7 @@ module Trek
45
45
  end
46
46
 
47
47
  def autocorrect_user_model
48
- run "rubocop --autocorrect #{user_model_path}"
48
+ rubocop_autocorrect user_model_path
49
49
  end
50
50
 
51
51
  private
@@ -1,3 +1,4 @@
1
+ require "shellwords"
1
2
  require "rails/generators/actions"
2
3
  require "rails/generators/migration"
3
4
  require "rails/generators/resource_helpers"
@@ -15,6 +16,13 @@ module Trek
15
16
 
16
17
  source_root File.expand_path("templates", __dir__)
17
18
 
19
+ def initialize(args, *)
20
+ # The attributes as given, for the model generator: once parsed, `attributes` loses their indexes,
21
+ # references' options or decimals' precision
22
+ @given_attributes = args.drop(1)
23
+ super
24
+ end
25
+
18
26
  # `rails g model Shop::Product` writes app/models/shop.rb as a `module Shop`
19
27
  # namespace file; if a `Shop` model already lives there, it gets replaced.
20
28
  def warn_about_shadowed_models
@@ -28,14 +36,15 @@ module Trek
28
36
  end
29
37
 
30
38
  def create_model
31
- generate :model, class_name, attributes.map { |a| "#{a.name}:#{a.type}" }
39
+ # Escaped for the shell `generate` runs: it would expand `price:decimal{10,2}`'s braces
40
+ generate :model, class_name, @given_attributes.map { Shellwords.escape(it) }
32
41
  end
33
42
 
34
43
  def inject_trek_to_model
35
44
  inject_into_class model_file_path,
36
45
  class_name,
37
46
  model_injection
38
- run "rubocop --autocorrect #{model_file_path}", abort_on_failure: true
47
+ rubocop_autocorrect model_file_path
39
48
  end
40
49
 
41
50
  def add_model_message
@@ -61,7 +70,7 @@ module Trek
61
70
  inject_into_file dashboard_file_path,
62
71
  "\n::#{class_name},",
63
72
  after: "MODELS_IN_MENU = ["
64
- run "rubocop --autocorrect #{dashboard_file_path}", abort_on_failure: true
73
+ rubocop_autocorrect dashboard_file_path
65
74
  end
66
75
 
67
76
  def add_routes
@@ -134,8 +143,7 @@ module Trek
134
143
  # without re-indenting the body; the indentation cops are forced with
135
144
  # --only because rubocop-rails-omakase leaves them disabled.
136
145
  def reindent(path)
137
- run "rubocop --autocorrect --only Layout/IndentationWidth,Layout/IndentationConsistency #{path}",
138
- abort_on_failure: true
146
+ rubocop_autocorrect path, only: "Layout/IndentationWidth,Layout/IndentationConsistency"
139
147
  end
140
148
 
141
149
  def controller_file_path
@@ -15,7 +15,7 @@ admin:
15
15
 
16
16
  lint:
17
17
  bundle exec rubocop
18
- bundle exec slim-lint app/**/*.slim
18
+ bundle exec slim-lint "app/**/*.slim"
19
19
  yarn eslint "app/**/*.js"
20
20
  yarn stylelint "app/**/*.css"
21
21
  yarn prettier --check "{app,config,lib,spec}/**/*.{css,js,json,md,yml}"
@@ -1,5 +1,12 @@
1
1
  module Admin
2
2
  class FragmentsController < Trek::ResourceController
3
+ include Trek::Search
4
+
5
+ def index
6
+ super
7
+ search_in_objects!
8
+ end
9
+
3
10
  private
4
11
 
5
12
  def model
@@ -0,0 +1,8 @@
1
+ module Admin
2
+ module Panels
3
+ # The content editor's image panel, served under the app's routes: Trek's isolated engine only gives
4
+ # its own controllers the engine's routes, which can't reach the admin's.
5
+ class ImagesController < Trek::Panels::ImagesController
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Admin
2
+ module Panels
3
+ # The content editor's link panel, served under the app's routes: Trek's isolated engine only gives
4
+ # its own controllers the engine's routes, which can't reach the admin's.
5
+ class LinksController < Trek::Panels::LinksController
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Admin
2
+ module Panels
3
+ # The content editor's prompt panel, served under the app's routes: Trek's isolated engine only gives
4
+ # its own controllers the engine's routes, which can't reach the admin's.
5
+ class PromptsController < Trek::Panels::PromptsController
6
+ end
7
+ end
8
+ end
@@ -18,6 +18,20 @@ class Fragment < ApplicationRecord
18
18
 
19
19
  scope :ordered, -> { order(:position) }
20
20
 
21
+ # Matches the key (namespace.key), the title, or the text of the content, in the current locale.
22
+ scope :search, ->(query) do
23
+ next all if query.blank?
24
+
25
+ where(<<~SQL, pattern: "%#{sanitize_sql_like(query)}%", locale: Mobility.locale.to_s)
26
+ concat_ws('.', namespace, key) ILIKE :pattern
27
+ OR title ->> :locale ILIKE :pattern
28
+ OR EXISTS (
29
+ SELECT 1 FROM jsonb_path_query(content -> :locale, '$.**.text') AS text
30
+ WHERE text #>> '{}' ILIKE :pattern
31
+ )
32
+ SQL
33
+ end
34
+
21
35
  def to_s
22
36
  [namespace, key].join(".")
23
37
  end
@@ -15,7 +15,8 @@ RSpec.describe AdminMailer do
15
15
  end
16
16
 
17
17
  describe "the new sign-in email" do
18
- let(:user) { users.create(role: :editor) }
18
+ # In English whatever the app's default locale: the examples read English words
19
+ let(:user) { users.create(role: :editor, locale: "en") }
19
20
  let(:mail) do
20
21
  described_class.new_sign_in(
21
22
  user,
@@ -62,6 +62,7 @@ RSpec.describe "Admin active sessions", type: :request do
62
62
  before { sign_in(editor) }
63
63
 
64
64
  it "lists the user's sessions with their browser and IP address" do
65
+ editor.update!(locale: "en") # the browsers' descriptions are in English
65
66
  get admin_user_path(editor)
66
67
 
67
68
  expect(response.body).to include("Safari on macOS").and include("Firefox on Windows").and include("203.0.113.7")
@@ -8,10 +8,34 @@ RSpec.describe "Admin fragments", type: :request do
8
8
  post admin_user_session_path, params: { email: editor.email, password: users.password }
9
9
  end
10
10
 
11
- it "lists the fragments" do
11
+ it "lists the fragments with their key and an excerpt of their content" do
12
+ footer.update!(content: { type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text: "All rights reserved" }] }] })
13
+
12
14
  get admin_fragments_path
13
15
 
14
- expect(response.body).to include("footer")
16
+ expect(response.body).to include("Footer", "<code>layout.footer</code>", "All rights reserved")
17
+ end
18
+
19
+ describe "searching" do
20
+ before do
21
+ footer.update!(content: { type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text: "All rights reserved" }] }] })
22
+ fragments.create(key: "tagline", namespace: "home", title: "Tagline")
23
+ end
24
+
25
+ it "finds fragments by key, title or content text", :aggregate_failures do
26
+ ["layout.foot", "FOOTER", "rights"].each do |search|
27
+ get admin_fragments_path(search:)
28
+
29
+ expect(response.body).to include("layout.footer")
30
+ expect(response.body).not_to include("home.tagline")
31
+ end
32
+ end
33
+
34
+ it "ignores the content's structure" do
35
+ get admin_fragments_path(search: "paragraph")
36
+
37
+ expect(response.body).not_to include("layout.footer")
38
+ end
15
39
  end
16
40
 
17
41
  it "renders the new fragment form" do
@@ -13,6 +13,14 @@ RSpec.describe "Admin pages", type: :request do
13
13
  expect(response.body).to include("Company").and include("Our team")
14
14
  end
15
15
 
16
+ it "lists a page with an image" do
17
+ pages.company.update!(image: file_fixture("image.png").open)
18
+
19
+ get admin_pages_path
20
+
21
+ expect(response).to have_http_status(:ok)
22
+ end
23
+
16
24
  it "renders the new page form" do
17
25
  get new_admin_page_path
18
26
 
@@ -0,0 +1,54 @@
1
+ require "rails_helper"
2
+
3
+ # The content editor's side panels (link, image, prompt), which its toolbar loads into the layout's
4
+ # stacked panel frame
5
+ RSpec.describe "Admin content editor panels", type: :request do
6
+ before do
7
+ editor = users.create(role: :editor)
8
+ post admin_user_session_path, params: { email: editor.email, password: users.password }
9
+ end
10
+
11
+ # A missing translation in a panel fails the request, instead of showing "Translation missing"
12
+ around do |example|
13
+ raise_on_missing = ActionView::Helpers::TranslationHelper.raise_on_missing_translations
14
+ ActionView::Helpers::TranslationHelper.raise_on_missing_translations = true
15
+ example.run
16
+ ensure
17
+ ActionView::Helpers::TranslationHelper.raise_on_missing_translations = raise_on_missing
18
+ end
19
+
20
+ def stacked_panel
21
+ Nokogiri::HTML5(response.body).at_css("turbo-frame#trek--layout-stacked-panel")
22
+ end
23
+
24
+ {
25
+ "link" => [:new_admin_panels_link_path, :link, :admin_panels_links_path],
26
+ "image" => [:new_admin_panels_image_path, :image, :admin_panels_images_path],
27
+ "prompt" => [:new_admin_panels_prompt_path, :prompt, :admin_panels_prompts_path]
28
+ }.each do |panel, (path, param, form_path)|
29
+ it "opens the #{panel} panel" do
30
+ get public_send(path, param => { turbo_frame_id: "page_1_content" })
31
+
32
+ expect(stacked_panel.at_css("form")["action"]).to eq(public_send(form_path))
33
+ end
34
+
35
+ it "titles the #{panel} panel" do
36
+ get public_send(path, param => { turbo_frame_id: "page_1_content" })
37
+
38
+ expect(stacked_panel.at_css("h1").text.squish).to eq(I18n.t("admin.panels.#{panel}s.form.title"))
39
+ end
40
+ end
41
+
42
+ it "opens the link panel on a link to another site" do
43
+ get new_admin_panels_link_path(link: { turbo_frame_id: "page_1_content", href: "https://example.com/", text: "Example" })
44
+
45
+ expect(stacked_panel.at_css("form")["action"]).to eq(admin_panels_links_path)
46
+ end
47
+
48
+ it "inserts a link into the editor" do
49
+ post admin_panels_links_path(format: :turbo_stream),
50
+ params: { link: { turbo_frame_id: "page_1_content", href: "https://example.com/", text: "Example" } }
51
+
52
+ expect(response).to have_http_status(:ok)
53
+ end
54
+ end
@@ -4,6 +4,8 @@ RSpec.describe "Admin sign-in notices", type: :request do
4
4
  include ActiveSupport::Testing::TimeHelpers
5
5
 
6
6
  let(:editor) { users.create(role: :editor) }
7
+ # For examples reading English words, whatever the app's default locale
8
+ let(:english_editor) { users.create(role: :editor, locale: "en") }
7
9
  let(:firefox) { "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0" }
8
10
 
9
11
  def sign_in(user, user_agent: firefox)
@@ -43,11 +45,11 @@ RSpec.describe "Admin sign-in notices", type: :request do
43
45
  end
44
46
 
45
47
  it "shows the previous sign-in's date, browser and address on the sessions tab" do
46
- sign_in(editor)
48
+ sign_in(english_editor)
47
49
  sign_out
48
- sign_in(editor)
50
+ sign_in(english_editor)
49
51
 
50
- get admin_user_path(editor)
52
+ get admin_user_path(english_editor)
51
53
 
52
54
  expect(response.body).to include("Firefox on Windows").and include("127.0.0.1")
53
55
  end
@@ -12,8 +12,19 @@
12
12
  end
13
13
  end
14
14
 
15
- = render Trek::ListComponent.new do |c|
15
+ = render Trek::SearchComponent.new( \
16
+ action: admin_fragments_path,
17
+ value: params[:search],
18
+ )
19
+
20
+ = render Trek::EntriesComponent.new do |entries|
16
21
  ruby:
17
- @objects.each do |object|
18
- c.with_item(object:)
22
+ @objects.each do |fragment|
23
+ entries.with_item(item: fragment) do |entry|
24
+ entry.with_title(href: [:edit, :admin, fragment]) do
25
+ fragment.title.presence || fragment.to_s
26
+ end
27
+ entry.with_detail { tag.code(fragment.to_s) } if fragment.title.present?
28
+ entry.with_detail { truncate(fragment.content_text, length: 80) }
29
+ end
19
30
  end
data/lib/trek/engine.rb CHANGED
@@ -12,10 +12,10 @@ module Trek
12
12
 
13
13
  config.eager_load_paths = %W[
14
14
  #{root}/app/components
15
+ #{root}/app/content
15
16
  #{root}/app/controllers
16
17
  #{root}/app/controllers/concerns
17
18
  #{root}/app/forms
18
- #{root}/app/formatters
19
19
  #{root}/app/helpers
20
20
  #{root}/app/jobs
21
21
  #{root}/app/models
@@ -26,9 +26,14 @@ module Trek
26
26
  #{root}/app/validators
27
27
  ]
28
28
 
29
- # Lets apps configure Trek's deprecation warnings like Rails' own (Rails 7.1+)
29
+ # Lets apps configure Trek's deprecation warnings like Rails' own
30
30
  initializer "trek.deprecator" do |app|
31
- app.deprecators[:trek] = Trek.deprecator if app.respond_to?(:deprecators)
31
+ app.deprecators[:trek] = Trek.deprecator
32
+ end
33
+
34
+ # The default content schema holds node type classes: rebuild it after code reloading
35
+ config.to_prepare do
36
+ Trek::Content.clear_default_schema
32
37
  end
33
38
 
34
39
  # Off unless ADMIN_ALLOWED_IPS lists addresses or ranges
@@ -6,7 +6,8 @@ module Trek
6
6
  # Shrine's `activerecord` plugin resets every attacher when the record is reloaded, which is
7
7
  # right for an explicit reload but loses a pending attachment when something reloads the record
8
8
  # *during* the save: closure_tree does exactly that in its `after_save` callback when it
9
- # reorders siblings (on create, or when the parent changes) on a numerically ordered tree.
9
+ # reorders siblings (on create, when the parent changes, or since closure_tree 9.8 when the
10
+ # position changes) on a numerically ordered tree.
10
11
  # The attacher is then no longer `changed?` when Shrine's `after_commit` runs, so the file is
11
12
  # never promoted from the temporary `cache` storage to `store` and breaks once the cache is
12
13
  # cleaned up.
data/lib/trek/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trek
4
- VERSION = "2.4.0"
4
+ VERSION = "2.5.0"
5
5
  end
data/lib/trek.rb CHANGED
@@ -14,7 +14,7 @@ require "kaminari"
14
14
  require "mobility"
15
15
  require "phonelib"
16
16
  require "postmark-rails"
17
- require "prosemirror_to_html"
17
+ require "prosemirror"
18
18
  require "rails-i18n"
19
19
  require "shrine"
20
20
  require "shrine/plugins/blurhash"
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trek",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A modern content management & back-office system for Ruby on Rails",
5
5
  "homepage": "https://trek.etamin.studio",
6
6
  "license": "MIT",
data/renovate.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
3
  "extends": ["local>devops/renovate-runner"],
4
+ "addLabels": ["feature::dependencies"],
4
5
  "customManagers": [
5
6
  {
6
7
  "customType": "regex",
data/trek.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "A modern content management & back-office system for Ruby on Rails"
12
12
  spec.homepage = "https://trek.etamin.studio"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 3.1.0"
14
+ spec.required_ruby_version = ">= 3.3.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["documentation_uri"] = spec.homepage
@@ -50,8 +50,8 @@ Gem::Specification.new do |spec|
50
50
  spec.add_dependency "mobility", "~> 1.3.2"
51
51
  spec.add_dependency "phonelib", "~> 0.8"
52
52
  spec.add_dependency "postmark-rails"
53
- spec.add_dependency "prosemirror_to_html", "~> 0.2"
54
- spec.add_dependency "rails", [">= 6.0", "< 8.2"]
53
+ spec.add_dependency "prosemirror", ">= 0.7.1", "< 2"
54
+ spec.add_dependency "rails", [">= 8.0", "< 8.2"]
55
55
  spec.add_dependency "rails-healthcheck"
56
56
  spec.add_dependency "rails-i18n", ">= 6.0"
57
57
  spec.add_dependency "shrine", "~> 3.0"