File: ruby_liquid_yjit.rb

package info (click to toggle)
ruby-liquid 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,444 kB
  • sloc: ruby: 14,571; makefile: 6
file content (41 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

# Liquid Spec Adapter for Shopify/liquid with YJIT + strict mode + ActiveSupport
#
# Run with: bundle exec liquid-spec run spec/ruby_liquid_yjit.rb

$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))

# Enable YJIT if available
if defined?(RubyVM::YJIT) && RubyVM::YJIT.respond_to?(:enable)
  RubyVM::YJIT.enable
end

require 'active_support/all'
require 'liquid'

LiquidSpec.configure do |config|
  config.features = [:core, :activesupport]
end

# Compile a template string into a Liquid::Template
LiquidSpec.compile do |ctx, source, options|
  # Force strict mode
  options = { error_mode: :strict }.merge(options)
  ctx[:template] = Liquid::Template.parse(source, **options)
end

# Render a compiled template with the given context
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