Skip to content

Instantly share code, notes, and snippets.

@ridem
Last active January 10, 2018 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridem/0da7d8211cc38f1d4794fc23910c17f5 to your computer and use it in GitHub Desktop.
Save ridem/0da7d8211cc38f1d4794fc23910c17f5 to your computer and use it in GitHub Desktop.
Test a Liquid file's syntax

Checking a Liquid file's syntax

  1. Install liquid-validator: sudo gem install liquid-validator
  2. Put the contents of the liquid file you want to try in a file called liquid_to_test.liquid.
  3. Put the test_liquid.rb file in the same folder.
  4. From that folder, run ruby test_liquid.rb in the terminal
{% if product.title == 'Awesome Shoes' %}
These shoes are awesome!
{% endif %}
require 'liquid-validator'
template = File.open("liquid_to_test.liquid", "rb").read
validator = LiquidValidator::Validator.new(template)
if validator.valid?
puts "All fine!"
else
puts validator.errors.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment