Class: LiquidPlus::CaptureTag
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- LiquidPlus::CaptureTag
- Defined in:
- lib/jekyll-liquid-plus/tags/capture.rb
Constant Summary collapse
- WORD_REGEX =
'[[:word:]]'
- SYNTAX =
/(#{WORD_REGEX}+)\s*(\+=|\|\|=)?/o
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ CaptureTag
constructor
A new instance of CaptureTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ CaptureTag
Returns a new instance of CaptureTag.
8 9 10 11 |
# File 'lib/jekyll-liquid-plus/tags/capture.rb', line 8 def initialize(tag_name, markup, tokens) @markup = markup super end |
Instance Method Details
#render(context) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll-liquid-plus/tags/capture.rb', line 13 def render(context) if @markup = Conditional.parse(@markup, context) if @markup.strip =~ SYNTAX @to = $1 @operator = $2 output = super if @operator == '+=' and !context.scopes.last[@to].nil? context.scopes.last[@to] += output.strip elsif @operator.nil? or (@operator == '||=' and context.scopes.last[@to].nil?) context.scopes.last[@to] = output.strip end else raise SyntaxError.new("Syntax Error in 'capture' - Valid syntax: capture [var]") end end '' end |