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.
- checksums.yaml +4 -4
- data/AGENTS.md +6 -5
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +192 -171
- data/Makefile +26 -1
- data/README.md +2 -2
- data/app/components/trek/form/image_field_component.rb +1 -5
- data/app/components/trek/list/item_component.rb +1 -1
- data/app/components/trek/list/tree/item_component.rb +2 -2
- data/app/components/trek/search_component/search_component.html.slim +2 -1
- data/app/components/trek/search_component.rb +9 -1
- data/app/content/trek/content/bullet_list.rb +10 -0
- data/app/content/trek/content/document.rb +33 -0
- data/app/content/trek/content/image_block.rb +52 -0
- data/app/content/trek/content/link_resolver.rb +33 -0
- data/app/content/trek/content/list_item.rb +19 -0
- data/app/content/trek/content/ordered_list.rb +10 -0
- data/app/content/trek/content/paragraph.rb +10 -0
- data/app/content/trek/content/prompts_block.rb +22 -0
- data/app/content/trek/content.rb +32 -0
- data/app/controllers/concerns/trek/reorderable.rb +14 -3
- data/app/controllers/trek/csp_reports_controller.rb +3 -6
- data/app/controllers/trek/panels/base_controller.rb +3 -0
- data/app/controllers/trek/panels/links_controller.rb +1 -1
- data/app/controllers/trek/panels/prompts_controller.rb +1 -1
- data/app/helpers/trek/thumbnail_helper.rb +11 -0
- data/app/models/concerns/trek/contentable.rb +9 -14
- data/app/models/concerns/trek/pageable.rb +10 -1
- data/app/views/trek/panels/images/_form.html.slim +1 -1
- data/app/views/trek/panels/images/create.turbo_stream.slim +1 -1
- data/app/views/trek/panels/links/_form.html.slim +1 -1
- data/app/views/trek/panels/prompts/_form.html.slim +1 -1
- data/config/locales/trek.en.yml +23 -0
- data/config/locales/trek.fr.yml +23 -0
- data/docs/getting-started.md +3 -3
- data/docs/reference/concerns/contentable.md +2 -1
- data/docs/reference/controllers.md +1 -1
- data/docs/reference/formatters.md +31 -8
- data/docs/reference/models/fragment.md +1 -0
- data/docs/what-is-trek.md +4 -4
- data/lib/generators/trek/helpers.rb +13 -5
- data/lib/generators/trek/install/admin_generator.rb +8 -0
- data/lib/generators/trek/install/appsignal_generator.rb +1 -1
- data/lib/generators/trek/install/authentication_generator.rb +1 -1
- data/lib/generators/trek/install/authorization_generator.rb +1 -1
- data/lib/generators/trek/install/postmark_generator.rb +2 -2
- data/lib/generators/trek/install/specs_generator.rb +11 -0
- data/lib/generators/trek/install/user_generator.rb +1 -1
- data/lib/generators/trek/scaffold_generator.rb +13 -5
- data/lib/generators/trek/templates/Makefile +1 -1
- data/lib/generators/trek/templates/controllers/admin/fragments_controller.rb +7 -0
- data/lib/generators/trek/templates/controllers/admin/panels/images_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/panels/links_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/panels/prompts_controller.rb +8 -0
- data/lib/generators/trek/templates/models/fragment.rb +14 -0
- data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +2 -1
- data/lib/generators/trek/templates/spec/requests/admin/active_sessions_spec.rb +1 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +26 -2
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +8 -0
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +54 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +5 -3
- data/lib/generators/trek/templates/views/admin/fragments/index.html.slim +14 -3
- data/lib/trek/engine.rb +8 -3
- data/lib/trek/saved_attachments_reload.rb +2 -1
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +1 -1
- data/package.json +1 -1
- data/renovate.json +1 -0
- data/trek.gemspec +3 -3
- data/yarn.lock +842 -880
- metadata +29 -14
- data/app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb +0 -19
- data/app/formatters/prosemirror_to_html/nodes/image_block.rb +0 -44
- data/app/formatters/prosemirror_to_html/nodes/prompts_block.rb +0 -28
- data/app/formatters/prosemirror_to_html/remove_empty_paragraphs_formatter.rb +0 -11
- data/app/models/prosemirror.rb +0 -23
data/Makefile
CHANGED
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
.PHONY: *
|
|
2
2
|
|
|
3
|
-
lint
|
|
3
|
+
# One target per tool: `make -k lint` runs them all and reports every failure, as CI does.
|
|
4
|
+
lint: lint-ruby lint-slim lint-js lint-css lint-prettier lint-i18n
|
|
5
|
+
|
|
6
|
+
lint-ruby:
|
|
4
7
|
bundle exec rubocop
|
|
8
|
+
|
|
9
|
+
lint-slim:
|
|
5
10
|
bundle exec slim-lint "app/**/*.slim"
|
|
11
|
+
|
|
12
|
+
lint-js:
|
|
6
13
|
yarn eslint "app/**/*.js"
|
|
14
|
+
|
|
15
|
+
lint-css:
|
|
7
16
|
yarn stylelint "app/**/*.css"
|
|
17
|
+
|
|
18
|
+
lint-prettier:
|
|
8
19
|
yarn prettier --check "{app,config,lib,spec}/**/*.{css,js,json,md,yml}"
|
|
20
|
+
|
|
21
|
+
# Locale parity: every base-locale key must be translated in the others. (Full `health` doesn't fit
|
|
22
|
+
# an engine: keys are used by host apps, and many components use relative keys that only resolve
|
|
23
|
+
# there.)
|
|
24
|
+
lint-i18n:
|
|
9
25
|
bundle exec i18n-tasks missing -t diff
|
|
10
26
|
|
|
27
|
+
# One target per tool, as for lint
|
|
28
|
+
security: security-brakeman security-bundler-audit
|
|
29
|
+
|
|
30
|
+
security-brakeman:
|
|
31
|
+
bundle exec brakeman --no-exit-on-error
|
|
32
|
+
|
|
33
|
+
security-bundler-audit:
|
|
34
|
+
bundle exec bundle-audit check --update
|
|
35
|
+
|
|
11
36
|
fix:
|
|
12
37
|
bundle exec rubocop --autocorrect
|
|
13
38
|
yarn eslint "app/**/*.js" --fix
|
data/README.md
CHANGED
|
@@ -57,10 +57,10 @@ module Trek
|
|
|
57
57
|
|
|
58
58
|
def image
|
|
59
59
|
if node.image&.exists?
|
|
60
|
-
image_tag node.image
|
|
60
|
+
image_tag Trek::ThumbnailHelper.thumbnail_url(node.image, 80, 60),
|
|
61
61
|
loading: "lazy"
|
|
62
62
|
elsif node.parent&.image&.exists?
|
|
63
|
-
image_tag node.parent.image
|
|
63
|
+
image_tag Trek::ThumbnailHelper.thumbnail_url(node.parent.image, 80, 60),
|
|
64
64
|
loading: "lazy"
|
|
65
65
|
else
|
|
66
66
|
render Trek::IconComponent.new("trek/pic")
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
= form_with url: action, method: "get", class: root_class
|
|
2
|
-
label(class=class_for("label") for=
|
|
2
|
+
label(class=class_for("label") for=input_id) = label_text
|
|
3
3
|
div(class=class_for("wrapper"))
|
|
4
4
|
input (
|
|
5
|
+
id=input_id
|
|
5
6
|
name="search"
|
|
6
7
|
type="text"
|
|
7
8
|
value=value
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
module Trek
|
|
4
4
|
class SearchComponent < Trek::Component
|
|
5
5
|
option :action
|
|
6
|
-
option :label,
|
|
6
|
+
option :label, optional: true
|
|
7
7
|
option :value, optional: true
|
|
8
|
+
|
|
9
|
+
def label_text
|
|
10
|
+
label || t(".search")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def input_id
|
|
14
|
+
@input_id ||= "search-#{SecureRandom.hex(4)}"
|
|
15
|
+
end
|
|
8
16
|
end
|
|
9
17
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# A document with the record holding it. Problems reported to `Rails.error` while parsing or rendering it
|
|
4
|
+
# name the record in their context (`trek_content: "Page#12"`), which error trackers like AppSignal show as
|
|
5
|
+
# a tag. Documents are often rendered later than they're parsed, in a view, so the renderer sets it too.
|
|
6
|
+
class Document < Prosemirror::Document
|
|
7
|
+
def self.parse(record, json)
|
|
8
|
+
with_context(record) { new(Trek::Content.schema.parse(json).root, schema: Trek::Content.schema, record:) }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.with_context(record, &)
|
|
12
|
+
ActiveSupport::ExecutionContext.set(trek_content: "#{record.class.name}##{record.id}", &)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attr_reader :record
|
|
16
|
+
|
|
17
|
+
def initialize(root, record:, schema: Trek::Content.schema)
|
|
18
|
+
super(root, schema:)
|
|
19
|
+
@record = record
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_phlex
|
|
23
|
+
Renderer.new(self)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Renderer < Prosemirror::HTMLRenderer
|
|
27
|
+
def around_template(&)
|
|
28
|
+
Document.with_context(@document.record) { super }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# An image added with the content editor's image panel: a figure with its caption and credit.
|
|
4
|
+
# Subclass it to render the app's own component, for example with `derivation_url`:
|
|
5
|
+
#
|
|
6
|
+
# class ImageBlock < Trek::Content::ImageBlock
|
|
7
|
+
# def view_template
|
|
8
|
+
# render Components::Figure.new(image: image&.derivation_url(:thumbnail, 930, 1200), caption: @text)
|
|
9
|
+
# end
|
|
10
|
+
# end
|
|
11
|
+
class ImageBlock < Prosemirror::NodeType
|
|
12
|
+
group :block
|
|
13
|
+
|
|
14
|
+
prop :file_data, _String?
|
|
15
|
+
prop :alt, _String?
|
|
16
|
+
prop :text, _String?
|
|
17
|
+
prop :credit, _String?
|
|
18
|
+
prop :size, _Union?(*Trek::ContentEditor::Image::SIZES.map(&:to_s))
|
|
19
|
+
|
|
20
|
+
def view_template
|
|
21
|
+
return unless (src = image && safe_url(image.url))
|
|
22
|
+
|
|
23
|
+
figure(data_size: @size) do
|
|
24
|
+
img(src:, alt: @alt.to_s)
|
|
25
|
+
figcaption { caption } if @text.present? || @credit.present?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# The uploaded file, or nil when the node has none or its data is invalid.
|
|
32
|
+
def image
|
|
33
|
+
return if @file_data.blank?
|
|
34
|
+
|
|
35
|
+
@image ||= begin
|
|
36
|
+
object = Trek::ContentEditor::Image.new(file_data: @file_data)
|
|
37
|
+
ModelImageUploader::Attacher.from_model(object, :file).load_model(object, :file)
|
|
38
|
+
object.file
|
|
39
|
+
rescue JSON::ParserError, Shrine::Error => e
|
|
40
|
+
Rails.error.report(e, handled: true)
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def caption
|
|
46
|
+
plain(@text) if @text.present?
|
|
47
|
+
whitespace if @text.present? && @credit.present?
|
|
48
|
+
span { @credit } if @credit.present?
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# Turns links to records, stored as GlobalIDs (`gid://app/Page/1`), into their URLs. Called with all the
|
|
4
|
+
# URLs of a document at once, it loads their records with one query per model. A record that doesn't
|
|
5
|
+
# exist resolves to nil, so its link is removed and its text kept.
|
|
6
|
+
class LinkResolver
|
|
7
|
+
# `url_for(page)` calls `page_url`. Included before the route helpers, so an app's own
|
|
8
|
+
# `direct :page` route takes precedence over Trek's helper.
|
|
9
|
+
include Trek::PagePathHelper
|
|
10
|
+
include Rails.application.routes.url_helpers
|
|
11
|
+
|
|
12
|
+
# A Hash from each URL to its resolved URL.
|
|
13
|
+
def call(urls)
|
|
14
|
+
records = locate(urls.select { |url| url.start_with?("gid://") })
|
|
15
|
+
urls.index_with { |url| url.start_with?("gid://") ? records[url]&.then { |record| url_for(record) } : url }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# The records of the GlobalIDs, by GlobalID. Records are matched by id rather than by their own
|
|
21
|
+
# GlobalID, which names their subclass. An unknown model raises NameError: its records are missing.
|
|
22
|
+
def locate(urls)
|
|
23
|
+
gids = urls.filter_map { |url| GlobalID.parse(url)&.then { |gid| [url, gid] } }
|
|
24
|
+
gids.group_by { |_url, gid| gid.model_name }.each_with_object({}) do |(_model, group), records|
|
|
25
|
+
found = GlobalID::Locator.locate_many(group.map(&:last), ignore_missing: true).index_by { |record| record.id.to_s }
|
|
26
|
+
group.each { |url, gid| records[url] = found[gid.model_id] }
|
|
27
|
+
rescue NameError
|
|
28
|
+
next
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# Empty list items, with no content or only empty paragraphs, render nothing, like empty paragraphs.
|
|
4
|
+
class ListItem < Prosemirror::Nodes::ListItem
|
|
5
|
+
def self.empty?(node)
|
|
6
|
+
node.content.all? { |child| child.type == :paragraph && child.content.empty? }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Whether a list has no item to render: only empty items, and whitespace.
|
|
10
|
+
def self.empty_list?(node)
|
|
11
|
+
node.content.all? { |child| child.text? ? child.text.strip.empty? : child.type == :list_item && empty?(child) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template(&)
|
|
15
|
+
li(&) unless self.class.empty?(node)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# A call to action added with the content editor's prompt panel, rendered as a link.
|
|
4
|
+
# Subclass it to render the app's own button component.
|
|
5
|
+
class PromptsBlock < Prosemirror::NodeType
|
|
6
|
+
group :block
|
|
7
|
+
|
|
8
|
+
prop :text, _String?
|
|
9
|
+
prop :href, _String?
|
|
10
|
+
prop :target, _String?
|
|
11
|
+
prop :title, _String?
|
|
12
|
+
prop :color, _String?(/\A[\w-]+\z/)
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
href = @href.present? && safe_url(@href)
|
|
16
|
+
return if !href || @text.blank?
|
|
17
|
+
|
|
18
|
+
a(href:, target: @target, title: @title, data_color: @color) { @text }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
# Renders ProseMirror content (see Trek::Contentable) with the `prosemirror` gem.
|
|
3
|
+
#
|
|
4
|
+
# The schema is Tiptap's, with Trek's blocks. To add or replace node types:
|
|
5
|
+
#
|
|
6
|
+
# # config/initializers/trek.rb
|
|
7
|
+
# Rails.application.config.to_prepare do
|
|
8
|
+
# Trek::Content.schema = Trek::Content.default_schema.with(Content::ImageBlock)
|
|
9
|
+
# end
|
|
10
|
+
module Content
|
|
11
|
+
class << self
|
|
12
|
+
attr_writer :schema
|
|
13
|
+
|
|
14
|
+
def schema
|
|
15
|
+
@schema || (@default_schema ||= default_schema)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Called after code reloading, as the default schema holds node type classes.
|
|
19
|
+
def clear_default_schema
|
|
20
|
+
@default_schema = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def default_schema
|
|
24
|
+
Prosemirror::Schema.tiptap(
|
|
25
|
+
case: :camel,
|
|
26
|
+
resolve_urls: LinkResolver.new,
|
|
27
|
+
on_invalid: ->(error) { Rails.error.report(error, handled: true) }
|
|
28
|
+
).with(Paragraph, ListItem, BulletList, OrderedList, ImageBlock, PromptsBlock)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -7,13 +7,20 @@ module Trek
|
|
|
7
7
|
before_action :set_mode, only: [:index]
|
|
8
8
|
# rubocop:enable Rails/LexicallyScopedActionFilter
|
|
9
9
|
|
|
10
|
+
# The index's reorder form posts there
|
|
11
|
+
helper_method :reorder_path
|
|
12
|
+
|
|
10
13
|
def reorder
|
|
11
14
|
authorize!
|
|
12
15
|
objects = reorderable_objects.index_by(&:id)
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
# Saving the positions one record at a time repeats acts_as_list's queries: Prosopite, in
|
|
18
|
+
# development and test, would take them for an N+1
|
|
19
|
+
without_n_plus_one_detection do
|
|
20
|
+
reorder_params.each do |id, position|
|
|
21
|
+
object = objects[id.to_i]
|
|
22
|
+
object.update(position:) unless object.position == position
|
|
23
|
+
end
|
|
17
24
|
end
|
|
18
25
|
|
|
19
26
|
redirect_to reorder_success_redirect, notice: reorder_notice
|
|
@@ -42,6 +49,10 @@ module Trek
|
|
|
42
49
|
[:admin, *model_collection_route]
|
|
43
50
|
end
|
|
44
51
|
|
|
52
|
+
def without_n_plus_one_detection(&)
|
|
53
|
+
defined?(Prosopite) ? Prosopite.pause(&) : yield
|
|
54
|
+
end
|
|
55
|
+
|
|
45
56
|
def reorder_notice
|
|
46
57
|
t("admin.#{model_collection}.reorder.success")
|
|
47
58
|
end
|
|
@@ -20,12 +20,9 @@ module Trek
|
|
|
20
20
|
|
|
21
21
|
# Browsers send no CSRF token; the endpoint only logs and reports, with no session nor user
|
|
22
22
|
skip_forgery_protection
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# Against a flood from many addresses
|
|
27
|
-
rate_limit to: 600, within: 1.minute, by: -> { "all" }, with: -> { head :too_many_requests }
|
|
28
|
-
end
|
|
23
|
+
rate_limit to: 60, within: 1.minute, with: -> { head :too_many_requests }
|
|
24
|
+
# Against a flood from many addresses
|
|
25
|
+
rate_limit to: 600, within: 1.minute, by: -> { "all" }, with: -> { head :too_many_requests }
|
|
29
26
|
|
|
30
27
|
def create
|
|
31
28
|
body = request.body.read(MAX_BODY + 1).to_s
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module Trek
|
|
2
2
|
module Panels
|
|
3
3
|
class BaseController < Trek::BaseController
|
|
4
|
+
# Stands in for a page in the link and prompt panels' choices when the current
|
|
5
|
+
# href isn't a page's global id (another site, a path, a mailto:…), so the select keeps it
|
|
6
|
+
HrefPlaceholder = Data.define(:to_global_id, :title)
|
|
4
7
|
end
|
|
5
8
|
end
|
|
6
9
|
end
|
|
@@ -29,7 +29,7 @@ module Trek
|
|
|
29
29
|
|
|
30
30
|
def set_pages
|
|
31
31
|
@pages = []
|
|
32
|
-
@pages <<
|
|
32
|
+
@pages << HrefPlaceholder.new(to_global_id: object_params[:href], title: object_params[:href]) if object_params[:href] && !object_params[:href].start_with?("gid")
|
|
33
33
|
@pages += Page.alpha_ordered if defined?(Page)
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -29,7 +29,7 @@ module Trek
|
|
|
29
29
|
|
|
30
30
|
def set_pages
|
|
31
31
|
@pages = []
|
|
32
|
-
@pages <<
|
|
32
|
+
@pages << HrefPlaceholder.new(to_global_id: object_params[:href], title: object_params[:href]) if object_params[:href] && !object_params[:href].start_with?("gid")
|
|
33
33
|
@pages += Page.alpha_ordered if defined?(Page)
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
# The URL of an uploaded image's thumbnail: through Shrine's derivation endpoint when the uploader loads
|
|
3
|
+
# it (the generated ImageUploader comments it out), or the image itself otherwise
|
|
4
|
+
module ThumbnailHelper
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
def thumbnail_url(file, width, height)
|
|
8
|
+
file.respond_to?(:derivation_url) ? file.derivation_url(:thumbnail, width, height) : file.url
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -8,16 +8,20 @@ module Trek
|
|
|
8
8
|
content.is_a?(Hash) ? content : JSON.parse(content)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
# The content as a Prosemirror::Document, built with Trek::Content.schema. Problems found while parsing
|
|
12
|
+
# or rendering it are reported with the record in their context (see Trek::Content::Document).
|
|
13
|
+
def content_document
|
|
12
14
|
return if content.blank?
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Trek::Content::Document.parse(self, parsed_content)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
+
def formatted_content
|
|
20
|
+
content_document&.to_html
|
|
21
|
+
end
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
def content_text
|
|
24
|
+
content_document&.text_content
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
def prosemirror_content?
|
|
@@ -27,14 +31,5 @@ module Trek
|
|
|
27
31
|
else false
|
|
28
32
|
end
|
|
29
33
|
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def extract_text(node)
|
|
34
|
-
return node["text"].to_s if node["type"] == "text"
|
|
35
|
-
return "" unless node["content"]
|
|
36
|
-
|
|
37
|
-
node["content"].map { |child| extract_text(child) }.join
|
|
38
|
-
end
|
|
39
34
|
end
|
|
40
35
|
end
|
|
@@ -21,9 +21,10 @@ module Trek
|
|
|
21
21
|
super || build_page(parent: default_parent_page)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# The admin links to records by id, the site by slug.
|
|
24
25
|
def to_param
|
|
25
26
|
# TODO: find a better way?
|
|
26
|
-
if
|
|
27
|
+
if called_from_admin?
|
|
27
28
|
id || super
|
|
28
29
|
else
|
|
29
30
|
page&.slug || super
|
|
@@ -96,5 +97,13 @@ module Trek
|
|
|
96
97
|
def apply_default_parent_page
|
|
97
98
|
page.parent = default_parent_page
|
|
98
99
|
end
|
|
100
|
+
|
|
101
|
+
# Whether an admin file (controller, view, layout, mailer…) is in the call stack. Trek::AdminIpAllowlist
|
|
102
|
+
# doesn't count: a middleware, it sits in the stack of every request, the site's included.
|
|
103
|
+
def called_from_admin?
|
|
104
|
+
caller_locations.any? do |location|
|
|
105
|
+
location.path.include?("admin") && !location.path.end_with?("/lib/trek/admin_ip_allowlist.rb")
|
|
106
|
+
end
|
|
107
|
+
end
|
|
99
108
|
end
|
|
100
109
|
end
|
data/config/locales/trek.en.yml
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
en:
|
|
3
|
+
activemodel:
|
|
4
|
+
attributes:
|
|
5
|
+
trek/content_editor/image:
|
|
6
|
+
alt: Alternative text
|
|
7
|
+
credit: Credit
|
|
8
|
+
file: Image
|
|
9
|
+
size: Size
|
|
10
|
+
text: Caption
|
|
11
|
+
trek/content_editor/link:
|
|
12
|
+
href: Address
|
|
13
|
+
target: Open in
|
|
14
|
+
text: Text
|
|
15
|
+
title: Title
|
|
16
|
+
trek/content_editor/prompt:
|
|
17
|
+
href: Address
|
|
18
|
+
target: Open in
|
|
19
|
+
text: Text
|
|
20
|
+
title: Title
|
|
21
|
+
options:
|
|
22
|
+
trek/content_editor/image:
|
|
23
|
+
size:
|
|
24
|
+
default: As wide as the text
|
|
25
|
+
larger: Wider
|
|
3
26
|
activerecord:
|
|
4
27
|
attributes:
|
|
5
28
|
audit_log:
|
data/config/locales/trek.fr.yml
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
fr:
|
|
3
|
+
activemodel:
|
|
4
|
+
attributes:
|
|
5
|
+
trek/content_editor/image:
|
|
6
|
+
alt: Texte alternatif
|
|
7
|
+
credit: Crédit
|
|
8
|
+
file: Image
|
|
9
|
+
size: Taille
|
|
10
|
+
text: Légende
|
|
11
|
+
trek/content_editor/link:
|
|
12
|
+
href: Adresse
|
|
13
|
+
target: Ouvrir dans
|
|
14
|
+
text: Texte
|
|
15
|
+
title: Titre
|
|
16
|
+
trek/content_editor/prompt:
|
|
17
|
+
href: Adresse
|
|
18
|
+
target: Ouvrir dans
|
|
19
|
+
text: Texte
|
|
20
|
+
title: Titre
|
|
21
|
+
options:
|
|
22
|
+
trek/content_editor/image:
|
|
23
|
+
size:
|
|
24
|
+
default: Comme la colonne de texte
|
|
25
|
+
larger: Plus large
|
|
3
26
|
activerecord:
|
|
4
27
|
attributes:
|
|
5
28
|
audit_log:
|
data/docs/getting-started.md
CHANGED
|
@@ -6,8 +6,8 @@ This guide takes you from an empty directory to a working Rails application with
|
|
|
6
6
|
|
|
7
7
|
Make sure the following are installed:
|
|
8
8
|
|
|
9
|
-
- Ruby 3.
|
|
10
|
-
- Rails
|
|
9
|
+
- Ruby 3.3+
|
|
10
|
+
- Rails 8.0+
|
|
11
11
|
- PostgreSQL 12+
|
|
12
12
|
- Node 22+
|
|
13
13
|
- Yarn 4.x
|
|
@@ -19,7 +19,7 @@ Check your Rails version:
|
|
|
19
19
|
rails -v
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
If it's older than
|
|
22
|
+
If it's older than 8.0, run `gem install rails` to upgrade.
|
|
23
23
|
|
|
24
24
|
Check your Yarn version:
|
|
25
25
|
|
|
@@ -7,7 +7,8 @@ Utilities for rich text stored as ProseMirror JSON in a `content` column — the
|
|
|
7
7
|
| Method | Returns |
|
|
8
8
|
| --- | --- |
|
|
9
9
|
| `parsed_content` | the content as a hash (parsing JSON strings if needed) |
|
|
10
|
-
| `
|
|
10
|
+
| `content_document` | the content as a `Prosemirror::Document`, to query or render it |
|
|
11
|
+
| `formatted_content` | safe HTML, rendered as described in [Rich text rendering](/reference/formatters#rich-text-rendering) |
|
|
11
12
|
| `content_text` | plain text extracted from all text nodes |
|
|
12
13
|
| `prosemirror_content?` | whether `content` is a valid ProseMirror document |
|
|
13
14
|
|
|
@@ -15,7 +15,7 @@ module Admin
|
|
|
15
15
|
end
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
- **Panel controllers** (`Trek::Panels::*`) — support endpoints used by the admin UI: image uploads (Uppy), link insertion and content editor prompts.
|
|
18
|
+
- **Panel controllers** (`Trek::Panels::*`) — support endpoints used by the admin UI: image uploads (Uppy), link insertion and content editor prompts. The installer generates their `Admin::Panels::*` subclasses in the app, which the admin routes point to: Trek's engine is isolated, so its own controllers only see the engine's routes, not the app's.
|
|
19
19
|
|
|
20
20
|
## Mixins
|
|
21
21
|
|