mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Update liquid-spec adapters for new ctx-based API
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 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
7d90b524ea
commit
aa817c4cfd
@@ -32,7 +32,6 @@ group :test do
|
||||
end
|
||||
|
||||
group :spec do
|
||||
# Using feature branch until https://github.com/Shopify/liquid-spec/pull/97 is merged
|
||||
gem 'liquid-spec', github: 'Shopify/liquid-spec', branch: 'main'
|
||||
gem 'activesupport', require: false
|
||||
end
|
||||
|
||||
+5
-6
@@ -13,16 +13,15 @@ LiquidSpec.configure do |config|
|
||||
end
|
||||
|
||||
# Compile a template string into a Liquid::Template
|
||||
LiquidSpec.compile do |_ctx, source, options|
|
||||
Liquid::Template.parse(source, **options)
|
||||
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 (unused)
|
||||
# @param template [Liquid::Template] compiled template
|
||||
# @param ctx [Hash] adapter context containing :template
|
||||
# @param assigns [Hash] environment variables
|
||||
# @param options [Hash] :registers, :strict_errors, :exception_renderer
|
||||
LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
LiquidSpec.render do |ctx, assigns, options|
|
||||
registers = Liquid::Registers.new(options[:registers] || {})
|
||||
|
||||
context = Liquid::Context.build(
|
||||
@@ -33,5 +32,5 @@ LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
|
||||
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
|
||||
|
||||
template.render(context)
|
||||
ctx[:template].render(context)
|
||||
end
|
||||
|
||||
@@ -12,14 +12,14 @@ LiquidSpec.configure do |config|
|
||||
end
|
||||
|
||||
# Compile a template string into a Liquid::Template
|
||||
LiquidSpec.compile do |_ctx, source, options|
|
||||
LiquidSpec.compile do |ctx, source, options|
|
||||
# Force lax mode
|
||||
options = options.merge(error_mode: :lax)
|
||||
Liquid::Template.parse(source, **options)
|
||||
ctx[:template] = Liquid::Template.parse(source, **options)
|
||||
end
|
||||
|
||||
# Render a compiled template with the given context
|
||||
LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
LiquidSpec.render do |ctx, assigns, options|
|
||||
registers = Liquid::Registers.new(options[:registers] || {})
|
||||
|
||||
context = Liquid::Context.build(
|
||||
@@ -30,5 +30,5 @@ LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
|
||||
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
|
||||
|
||||
template.render(context)
|
||||
ctx[:template].render(context)
|
||||
end
|
||||
|
||||
@@ -14,16 +14,15 @@ LiquidSpec.configure do |config|
|
||||
end
|
||||
|
||||
# Compile a template string into a Liquid::Template
|
||||
LiquidSpec.compile do |_ctx, source, options|
|
||||
Liquid::Template.parse(source, **options)
|
||||
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 (unused)
|
||||
# @param template [Liquid::Template] compiled template
|
||||
# @param ctx [Hash] adapter context containing :template
|
||||
# @param assigns [Hash] environment variables
|
||||
# @param options [Hash] :registers, :strict_errors, :exception_renderer
|
||||
LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
LiquidSpec.render do |ctx, assigns, options|
|
||||
registers = Liquid::Registers.new(options[:registers] || {})
|
||||
|
||||
context = Liquid::Context.build(
|
||||
@@ -34,5 +33,5 @@ LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
|
||||
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
|
||||
|
||||
template.render(context)
|
||||
ctx[:template].render(context)
|
||||
end
|
||||
|
||||
@@ -19,14 +19,14 @@ LiquidSpec.configure do |config|
|
||||
end
|
||||
|
||||
# Compile a template string into a Liquid::Template
|
||||
LiquidSpec.compile do |_ctx, source, options|
|
||||
LiquidSpec.compile do |ctx, source, options|
|
||||
# Force strict mode
|
||||
options = { error_mode: :strict }.merge(options)
|
||||
Liquid::Template.parse(source, **options)
|
||||
ctx[:template] = Liquid::Template.parse(source, **options)
|
||||
end
|
||||
|
||||
# Render a compiled template with the given context
|
||||
LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
LiquidSpec.render do |ctx, assigns, options|
|
||||
registers = Liquid::Registers.new(options[:registers] || {})
|
||||
|
||||
context = Liquid::Context.build(
|
||||
@@ -37,5 +37,5 @@ LiquidSpec.render do |_ctx, template, assigns, options|
|
||||
|
||||
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
|
||||
|
||||
template.render(context)
|
||||
ctx[:template].render(context)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user