Class: Liquid::TableRow

### Home Classes Methods

### In Files

- lib/liquid/htmltags.rb

### Parent

Liquid::Block

### Methods

- ::new
- #render

### Class/Module Index

Quicksearch

- Liquid
- Liquid::ArgumentError
- Liquid::Assign
- Liquid::BlankFileSystem
- Liquid::Block
- Liquid::Break
- Liquid::BreakInterrupt
- Liquid::Capture
- Liquid::Case
- Liquid::Comment
- Liquid::Context
- Liquid::ContextError
- Liquid::Continue
- Liquid::ContinueInterrupt
- Liquid::Cycle
- Liquid::Decrement
- Liquid::Document
- Liquid::Drop
- Liquid::ElseCondition
- Liquid::Error
- Liquid::FileSystemError
- Liquid::FilterNotFound
- Liquid::For
- Liquid::If
- Liquid::Ifchanged
- Liquid::Include
- Liquid::Increment
- Liquid::Interrupt
- Liquid::LocalFileSystem
- Liquid::MemoryError
- Liquid::Raw
- Liquid::StackLevelError
- Liquid::StandardError
- Liquid::StandardFilters
- Liquid::SyntaxError
- Liquid::TableRow
- Liquid::Tag
- Liquid::Template
- Liquid::Unless
- Liquid::Utils
- Liquid::Variable
- FalseClass
- LiquidView
- Module
- NilClass
- TrueClass

No matching classes.

# Liquid::TableRow

### Constants

Syntax

### Public Class Methods

new(tag_name, markup, tokens) click to toggle source

    # File lib/liquid/htmltags.rb, line 5
    def initialize(tag_name, markup, tokens)
      if markup =~ Syntax
        @variable_name = $1
        @collection_name = $2
        @attributes = {}
        markup.scan(TagAttributes) do |key, value|
          @attributes[key] = value
        end
      else
        raise SyntaxError.new("Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3")
      end

      super
    end

### Public Instance Methods

render(context) click to toggle source

    # File lib/liquid/htmltags.rb, line 20
    def render(context)
      collection = context[@collection_name] or return ''

      from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
      to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil

      collection = Utils.slice_collection_using_each(collection, from, to)

      length = collection.length

      cols = context[@attributes['cols']].to_i

      row = 1
      col = 0

      result = "<tr class=\"row1\">\n"
      context.stack do

        collection.each_with_index do |item, index|
          context[@variable_name] = item
          context['tablerowloop'] = {
            'length'  => length,
            'index'   => index + 1,
            'index0'  => index,
            'col'     => col + 1,
            'col0'    => col,
            'rindex'  => length - index,
            'rindex0' => length - index - 1,
            'first'   => (index == 0),
            'last'    => (index == length - 1),
            'col_first' => (col == 0),
            'col_last'  => (col == cols - 1)
          }

          col += 1

          result << "<td class=\"col#{col}\">" << render_all(@nodelist, context) << '</td>'

          if col == cols and (index != length - 1)
            col  = 0
            row += 1
            result << "</tr>\n<tr class=\"row#{row}\">"
          end

        end
      end
      result << "</tr>\n"
      result
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.