Created
January 30, 2015 21:26
-
-
Save tallakt/ee9bb1ad84e08a9a2e5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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