Class: ThemeCheck::Tags::Paginate

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/theme_check/tags.rb

Defined Under Namespace

Classes: ParseTreeVisitor

Constant Summary collapse

SYNTAX =
/(?<liquid_variable_name>#{Liquid::QuotedFragment})\s*((?<by>by)\s*(?<page_size>#{Liquid::QuotedFragment}))?/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ Paginate

Returns a new instance of Paginate.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/theme_check/tags.rb', line 85

def initialize(tag_name, markup, options)
  super
  if (matches = markup.match(SYNTAX))
    @liquid_variable_name = matches[:liquid_variable_name]
    @page_size = parse_expression(matches[:page_size])
    @window_size = nil # determines how many pagination links are shown

    @liquid_variable_count_expr = parse_expression("#{@liquid_variable_name}_count")

    var_parts = @liquid_variable_name.rpartition('.')
    @source_drop_expr = parse_expression(var_parts[0].empty? ? var_parts.last : var_parts.first)
    @method_name = var_parts.last.to_sym

    markup.scan(Liquid::TagAttributes) do |key, value|
      case key
      when 'window_size'
        @window_size = value.to_i
      end
    end
  else
    raise(Liquid::SyntaxError, "in tag 'paginate' - Valid syntax: paginate [collection] by number")
  end
end

Instance Attribute Details

#page_sizeObject (readonly)

Returns the value of attribute page_size.



83
84
85
# File 'lib/theme_check/tags.rb', line 83

def page_size
  @page_size
end