Class: LiquidPlus::Var
- Inherits:
-
Object
- Object
- LiquidPlus::Var
- Defined in:
- lib/jekyll-liquid-plus/helpers/var.rb
Constant Summary collapse
- SYNTAX =
/(#{Liquid::VariableSignature}+)\s*(=|\+=|\|\|=)\s*(.*)\s*/o
Class Method Summary collapse
- .determine_value(vars, context) ⇒ Object
- .get_value(vars, context) ⇒ Object
- .parse(markup, context) ⇒ Object
Class Method Details
.determine_value(vars, context) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/jekyll-liquid-plus/helpers/var.rb', line 29 def determine_value(vars, context) vars.each do |var| rendered = var.render(context) return rendered unless rendered.nil? end nil end |
.get_value(vars, context) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/jekyll-liquid-plus/helpers/var.rb', line 37 def get_value(vars, context) vars = vars.gsub(/ or /, ' || ') vars = vars.strip.split(/ \|\| /).map do |v| Liquid::Variable.new(v.strip) end determine_value(vars, context) end |
.parse(markup, context) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll-liquid-plus/helpers/var.rb', line 8 def parse(markup, context) if markup = Conditional.parse(markup, context) if markup =~ SYNTAX @to = $1 @operator = $2 @from = $3 value = get_value(@from, context) if @operator == '+=' and !context.scopes.last[@to].nil? context.scopes.last[@to] += value elsif @operator == '=' or (@operator == '||=' and context.scopes.last[@to].nil?) context.scopes.last[@to] = value end context else raise SyntaxError.new("Syntax Error in 'assign' - Valid syntax: assign [var] = [source]") end end end |