Class: Arrays::ArrayReplaceTag
- Inherits:
-
ArrayTag
- Object
- Liquid::Tag
- ArrayTag
- Arrays::ArrayReplaceTag
show all
- Defined in:
- lib/liquid-arrays/array_replace_tag.rb
Instance Method Summary
collapse
Methods inherited from ArrayTag
#get_array, #out_of_bounds?
Instance Method Details
#parse(tokens) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/liquid-arrays/array_replace_tag.rb', line 3
def parse(tokens)
super
parser = AttributeParser.new(@parse_context, @markup)
@array_name = parser.consume_attribute('array', :id)
@index = parser.consume_required_attribute('index', :integer)
@value = parser.consume_required_attribute('value')
parser.finish
end
|
#render(context) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/liquid-arrays/array_replace_tag.rb', line 12
def render(context)
array = get_array(context, false)
index = @index.render(context)
unless array.nil? || !index.is_a?(Integer) || out_of_bounds?(array, index)
array[index] = @value.render(context)
end
''
end
|