From 131b18d7090009ed297b8f03aead5236106a7413 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 17 Aug 2026 20:29:51 +1200 Subject: [PATCH] Expose the content link resolver. Assisted-By: devx/cbdeae41-9308-4071-ad53-58cd92db2946 --- lib/utopia/content/middleware.rb | 6 +----- lib/utopia/content/node.rb | 6 +++--- releases.md | 1 + test/utopia/content.rb | 4 ++++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/utopia/content/middleware.rb b/lib/utopia/content/middleware.rb index e12fb9dd..ccfd0b01 100644 --- a/lib/utopia/content/middleware.rb +++ b/lib/utopia/content/middleware.rb @@ -65,11 +65,7 @@ def freeze end attr :root - - # TODO we should remove this method and expose `@links` directly. - def links(path, **options) - @links.index(path, **options) - end + attr :links # Load and cache a content template. # @parameter path [Utopia::Path | String] The path. diff --git a/lib/utopia/content/node.rb b/lib/utopia/content/node.rb index 7672cfb3..593e020a 100644 --- a/lib/utopia/content/node.rb +++ b/lib/utopia/content/node.rb @@ -84,7 +84,7 @@ def parent_path def links(path = ".", **options, &block) path = uri_path.dirname + Path[path] - links = @controller.links(path, **options) + links = @controller.links.index(path, **options) if block_given? links.each(&block) @@ -96,7 +96,7 @@ def links(path = ".", **options, &block) # Return localized and indexed variants related to this node. # @returns [Array(Link)] The related links. def related_links - @controller.links(@uri_path.dirname, name: @uri_path.basename, indices: true) + @controller.links.index(@uri_path.dirname, name: @uri_path.basename, indices: true) end # Return the directory whose links are siblings of this node. @@ -113,7 +113,7 @@ def siblings_path # @parameter options [Hash] The options. # @returns [Array(Link)] The sibling links. def sibling_links(**options) - return @controller.links(siblings_path, **options) + return @controller.links.index(siblings_path, **options) end # Lookup the given tag which is being rendered within the given node. Invoked by {Document}. diff --git a/releases.md b/releases.md index 94ac571d..505f0403 100644 --- a/releases.md +++ b/releases.md @@ -3,6 +3,7 @@ ## Unreleased - **Breaking** Remove support for JavaScript packages installed in `lib/components`; use `node_modules` instead. + - **Breaking** Expose {ruby Utopia::Content::Middleware#links} as the content link resolver rather than an indexed lookup method. - **Security** Authenticate encrypted session cookies using AES-256-GCM. Existing session cookies are invalidated. - **Security** Redact sensitive exception report fields and make bounded request body attachments opt-in. diff --git a/test/utopia/content.rb b/test/utopia/content.rb index 19c7a53b..3728b571 100755 --- a/test/utopia/content.rb +++ b/test/utopia/content.rb @@ -127,6 +127,10 @@ let(:root) {File.expand_path(".content", __dir__)} let(:content) {Utopia::Content.new(Protocol::HTTP::Middleware::NotFound, root: root)} + it "exposes its link resolver" do + expect(content.links).to be_a Utopia::Content::Links + end + it "should parse file and expand variables" do path = Utopia::Path.create("/index") node = content.lookup_node(path)