Class: Locomotive::Steam::Liquid::Tags::Paginate
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Locomotive::Steam::Liquid::Tags::Paginate
- Includes:
- Concerns::Attributes
- Defined in:
- lib/locomotive/steam/liquid/tags/paginate.rb
Overview
Paginate a collection (array or from a DB).
Usage:
paginate contents.projects by 5 %
{% for project in paginate.collection %}
{{ project.name }}
{% endfor %}
{% endpaginate %}
Constant Summary collapse
Instance Attribute Summary collapse
-
#collection_name ⇒ Object
readonly
Returns the value of attribute collection_name.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Attributes included from Concerns::Attributes
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Paginate
constructor
A new instance of Paginate.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, options) ⇒ Paginate
Returns a new instance of Paginate.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/locomotive/steam/liquid/tags/paginate.rb', line 24 def initialize(tag_name, markup, ) if markup =~ Syntax @collection_name = $1 @per_page = $2 parse_attributes(markup) else raise ::Liquid::SyntaxError.new('Valid syntax: paginate <collection> by <number>') end super end |
Instance Attribute Details
#collection_name ⇒ Object (readonly)
Returns the value of attribute collection_name.
22 23 24 |
# File 'lib/locomotive/steam/liquid/tags/paginate.rb', line 22 def collection_name @collection_name end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
22 23 24 |
# File 'lib/locomotive/steam/liquid/tags/paginate.rb', line 22 def per_page @per_page end |
Instance Method Details
#render(context) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/locomotive/steam/liquid/tags/paginate.rb', line 37 def render(context) evaluate_attributes(context) context.stack do pagination = context['paginate'] = paginate_collection(context) path = sanitize_path(context['fullpath']) build_next_previous_links(pagination, path) if pagination['total_pages'] > 1 build_parts(pagination, path) end super end end |