Sha256: 42b42fcf5ef8288ee94711d498455fa1f3c2cdaba0707d3e01205f4f604126c2
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
module Liquid class Case < Block Syntax = /(#{QuotedFragment})/o WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/o def initialize(tag_name, markup, tokens, options) @blocks = [] if markup =~ Syntax @left = $1 else raise SyntaxError.new(options[:locale].t("errors.syntax.case"), options[:line]) end super end def unknown_tag(tag, markup, tokens) @nodelist = [] case tag when 'when' record_when_condition(markup) when 'else' record_else_condition(markup) else super end end def render(context) context.stack do execute_else_block = true output = '' @blocks.each do |block| if block.else? return render_all(block.attachment, context) if execute_else_block elsif block.evaluate(context) execute_else_block = false output << render_all(block.attachment, context) end end output end end private def record_when_condition(markup) while markup # Create a new nodelist and assign it to the new block if not markup =~ WhenSyntax raise SyntaxError.new(options[:locale].t("errors.syntax.case_invalid_when"), line) end markup = $2 block = Condition.new(@left, '==', $1) block.attach(@nodelist) @blocks.push(block) end end def record_else_condition(markup) if not markup.strip.empty? raise SyntaxError.new(options[:locale].t("errors.syntax.case_invalid_else"), line) end block = ElseCondition.new block.attach(@nodelist) @blocks << block end end Template.register_tag('case', Case) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
locomotivecms-liquid-2.6.0 | lib/liquid/tags/case.rb |