mirror of
https://github.com/Shopify/liquid.git
synced 2026-01-26 20:19:26 +00:00
liquid-spec main changed the adapter API: - compile block now receives (ctx, source, options) and should store the template in ctx[:template] - render block now receives (ctx, assigns, options) and retrieves the template from ctx[:template] Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
37 lines
1.1 KiB
Ruby
37 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Liquid Spec Adapter for Shopify/liquid (Ruby reference implementation)
|
|
#
|
|
# Run with: bundle exec liquid-spec run spec/ruby_liquid.rb
|
|
|
|
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
|
require 'liquid'
|
|
|
|
LiquidSpec.configure do |config|
|
|
# Run core Liquid specs
|
|
config.features = [:core]
|
|
end
|
|
|
|
# Compile a template string into a Liquid::Template
|
|
LiquidSpec.compile do |ctx, source, options|
|
|
ctx[:template] = Liquid::Template.parse(source, **options)
|
|
end
|
|
|
|
# Render a compiled template with the given context
|
|
# @param ctx [Hash] adapter context containing :template
|
|
# @param assigns [Hash] environment variables
|
|
# @param options [Hash] :registers, :strict_errors, :exception_renderer
|
|
LiquidSpec.render do |ctx, assigns, options|
|
|
registers = Liquid::Registers.new(options[:registers] || {})
|
|
|
|
context = Liquid::Context.build(
|
|
static_environments: assigns,
|
|
registers: registers,
|
|
rethrow_errors: options[:strict_errors],
|
|
)
|
|
|
|
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
|
|
|
|
ctx[:template].render(context)
|
|
end
|