Class: Arrays::AttributeParser
- Inherits:
-
Liquid::Parser
- Object
- Liquid::Parser
- Arrays::AttributeParser
- Defined in:
- lib/liquid-arrays/attribute_parser.rb
Instance Method Summary collapse
- #consume_attribute(key, type = nil) ⇒ Object
- #consume_required_attribute(key, type = nil) ⇒ Object
- #finish ⇒ Object
-
#initialize(parse_context, default_key = nil, markup) ⇒ AttributeParser
constructor
A new instance of AttributeParser.
Constructor Details
#initialize(parse_context, default_key = nil, markup) ⇒ AttributeParser
Returns a new instance of AttributeParser.
3 4 5 6 7 |
# File 'lib/liquid-arrays/attribute_parser.rb', line 3 def initialize(parse_context, default_key = nil, markup) super(markup) @parse_context = parse_context parse(default_key, markup) end |
Instance Method Details
#consume_attribute(key, type = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/liquid-arrays/attribute_parser.rb', line 9 def consume_attribute(key, type = nil) return nil unless @attributes.key?(key) value = @attributes.delete(key) if type == :id return value[0] == :id ? value[1].raw : nil elsif type == :array && value[0] != :array return ArrayVariable.new([value[1]]) end return type.nil? || value[0] == type || value[0] == :id ? value[1] : nil end |
#consume_required_attribute(key, type = nil) ⇒ Object
20 21 22 23 24 |
# File 'lib/liquid-arrays/attribute_parser.rb', line 20 def consume_required_attribute(key, type = nil) attribute = consume_attribute(key, type) raise Liquid::SyntaxError, "#{key} not specified" if attribute == nil attribute end |
#finish ⇒ Object
26 27 28 29 30 |
# File 'lib/liquid-arrays/attribute_parser.rb', line 26 def finish unless @attributes.empty? raise Liquid::SyntaxError, "invalid arguments #{@attributes.keys.join(',')}" end end |