Module: Octopress::TagHelpers::Conditional
- Defined in:
- lib/octopress-tag-helpers/conditional.rb
Constant Summary collapse
- SYNTAX =
/(?<tag>.*)\s(?<condition>if|unless)\s(?<expression>.+)/
Class Method Summary collapse
Class Method Details
.parse(markup, context) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/octopress-tag-helpers/conditional.rb', line 6 def self.parse(markup, context) matched = markup.strip.match(SYNTAX) if matched case matched['condition'].strip when 'if' tag = Liquid::Template.parse("{% if #{matched['expression']} %}true{% endif %}") when 'unless' tag = Liquid::Template.parse("{% unless #{matched['expression']} %}true{% endunless %}") end tag.render!(context) != '' ? matched['tag'] : false else markup end end |