Skip to content

Instantly share code, notes, and snippets.

@tallakt
Created January 30, 2015 21:26
Show Gist options
  • Save tallakt/ee9bb1ad84e08a9a2e5b to your computer and use it in GitHub Desktop.
Save tallakt/ee9bb1ad84e08a9a2e5b to your computer and use it in GitHub Desktop.
require 'liquid'
class SetClrCondition < Liquid::Tag
include Liquid
def initialize(tag_name, condition, tokens)
super
@condition = condition
end
def render(context)
t = Template.parse "{% if #{@condition} %}SET{% else %}CLR{% endif %}"
t.render context
end
end
Liquid::Template.register_tag('setclr', SetClrCondition)
@template = Liquid::Template.parse("{% setclr a <> c %}")
locals = Hash[%w(a b c d e f).each_slice(2).to_a]
p @template.render locals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment