Introduce :rigid parsing mode

This commit is contained in:
Guilherme Carreiro
2025-10-27 16:33:31 +01:00
committed by Guilherme Carreiro
parent 1c1e711906
commit edf06c2882
9 changed files with 335 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
<table>
{% tablerow i in (1..10) limit: foo=>bar %}
{{ i }}
{% endtablerow %}
</table>
Executable
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/setup'
require 'liquid'
class VirtualFileSystem
def initialize
snippet_1 = '<h1>{{ greating | default: "Hello" }}, {{ name | default: "world" }}!</h1>'
snippet_2 = '{% for i in (1..5) %} > {{ i }}{% endfor %}'
@templates = {
'snippet_1' => snippet_1,
'snippet_2' => snippet_2,
}
end
def read_template_file(key)
@templates[key] || raise(Liquid::FileSystemError, "No such template '#{key}'")
end
end
error_mode = :strict
# error_mode = :rigid
file = File.read(ARGV[0])
template = Liquid::Template.parse(file, error_mode: error_mode)
template.registers[:file_system] = VirtualFileSystem.new
puts template.render