Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def liquid_context
site:,
page: payload["page"],
cached_partials: self.class.cached_partials,
resource: document,
Copy link
Copy Markdown
Contributor Author

@fpsvogel fpsvogel Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this becausepage is a Bridgetown::Drops::ResourceDrop, not the full resource that is needed to create a RubyTemplateView in the new tag below.

There's also context["resource"], but it too is a Bridgetown::Drops::ResourceDrop.

},
strict_filters: site.config["liquid"]["strict_filters"],
strict_variables: site.config["liquid"]["strict_variables"],
Expand Down
45 changes: 45 additions & 0 deletions bridgetown-core/lib/bridgetown-core/tags/ruby_render.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module Bridgetown
module Tags
class RubyRender < Liquid::Tag
using Bridgetown::Refinements

# @param tag_name [String] "ruby_render"
# @param input [String] The input to the tag: snake-case name of the
# Ruby component, plus initialize args. Example:
# '"card", title: "Hello", footer: "I am a card"'
# @param tokens [Hash] A hash of config tokens for Liquid
def initialize(tag_name, input, tokens)
super
@input = input

@attributes = {}
input.scan(Liquid::TagAttributes) do |key, value|
@attributes[key.to_sym] = parse_expression(value)
end
end

# @param context [Liquid::Context]
# @return [String]
def render(context)
view_context = Bridgetown::RubyTemplateView.new(context.registers[:resource])
component_class_name_snakecase = @input.split(",").first
component_class_name = component_class_name_snakecase.tr("\"'", "").camelize.strip
component_class = self.class.const_get(component_class_name)
@attributes.each do |key, value|
@attributes[key] = value.evaluate(context) if value.is_a?(Liquid::VariableLookup)
end
component_instance = component_class.new(**@attributes)

if component_instance.respond_to?(:render_in)
component_instance.render_in(view_context)
else
component_instance.to_s
end
end
end
end
end

Liquid::Template.register_tag("ruby_render", Bridgetown::Tags::RubyRender)
Loading