Class: Liquid::TableRow
Defined Under Namespace
Classes: ParseTreeVisitor
Constant Summary collapse
- Syntax =
/(\w+)\s+in\s+(#{QuotedFragment}+)/o
Constants inherited from Block
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#collection_name ⇒ Object
readonly
Returns the value of attribute collection_name.
-
#variable_name ⇒ Object
readonly
Returns the value of attribute variable_name.
Attributes inherited from Tag
#line_number, #nodelist, #parse_context, #tag_name
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ TableRow
constructor
A new instance of TableRow.
- #render_to_output_buffer(context, output) ⇒ Object
Methods inherited from Block
#blank?, #block_delimiter, #block_name, #nodelist, #parse, #raise_tag_never_closed, raise_unknown_tag, #render, #unknown_tag
Methods inherited from Tag
#blank?, disable_tags, #name, parse, #parse, #raw, #render
Methods included from ParserSwitching
#parse_with_selected_parser, #strict_parse_with_error_mode_fallback
Constructor Details
#initialize(tag_name, markup, options) ⇒ TableRow
Returns a new instance of TableRow.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/liquid/tags/table_row.rb', line 9 def initialize(tag_name, markup, ) super if markup =~ Syntax @variable_name = Regexp.last_match(1) @collection_name = parse_expression(Regexp.last_match(2)) @attributes = {} markup.scan(TagAttributes) do |key, value| @attributes[key] = parse_expression(value) end else raise SyntaxError, [:locale].t("errors.syntax.table_row") end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/liquid/tags/table_row.rb', line 7 def attributes @attributes end |
#collection_name ⇒ Object (readonly)
Returns the value of attribute collection_name.
7 8 9 |
# File 'lib/liquid/tags/table_row.rb', line 7 def collection_name @collection_name end |
#variable_name ⇒ Object (readonly)
Returns the value of attribute variable_name.
7 8 9 |
# File 'lib/liquid/tags/table_row.rb', line 7 def variable_name @variable_name end |
Instance Method Details
#render_to_output_buffer(context, output) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/liquid/tags/table_row.rb', line 23 def render_to_output_buffer(context, output) (collection = context.evaluate(@collection_name)) || (return '') from = @attributes.key?('offset') ? context.evaluate(@attributes['offset']).to_i : 0 to = @attributes.key?('limit') ? from + context.evaluate(@attributes['limit']).to_i : nil collection = Utils.slice_collection(collection, from, to) length = collection.length cols = context.evaluate(@attributes['cols']).to_i output << "<tr class=\"row1\">\n" context.stack do tablerowloop = Liquid::TablerowloopDrop.new(length, cols) context['tablerowloop'] = tablerowloop collection.each do |item| context[@variable_name] = item output << "<td class=\"col#{tablerowloop.col}\">" super output << '</td>' if tablerowloop.col_last && !tablerowloop.last output << "</tr>\n<tr class=\"row#{tablerowloop.row + 1}\">" end tablerowloop.send(:increment!) end end output << "</tr>\n" output end |