Class: Lifer::Builder::HTML::FromLiquid::Drops::CollectionsDrop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/lifer/builder/html/from_liquid/drops/collections_drop.rb

Overview

This drop allows users to iterate over their Lifer collections in Liquid templates.

Examples:

Usage

{% for collection in collections %}
  {{ collection.name }}
{% endfor %}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollectionsDrop

Returns a new instance of CollectionsDrop.



13
14
15
# File 'lib/lifer/builder/html/from_liquid/drops/collections_drop.rb', line 13

def initialize
  @collections = Lifer.collections.map { CollectionDrop.new _1 }
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



11
12
13
# File 'lib/lifer/builder/html/from_liquid/drops/collections_drop.rb', line 11

def collections
  @collections
end

Instance Method Details

#each {|CollectionDrop| ... } ⇒ Object

Allow collections to be iterable in Liquid templates.

Yields:



20
21
22
# File 'lib/lifer/builder/html/from_liquid/drops/collections_drop.rb', line 20

def each(&block)
  collections.each(&block)
end

#liquid_method_missing(arg) ⇒ CollectionDrop, NilClass

Dynamically define Liquid accessors based on the Lifer project’s collection names.

Examples:

Get the root collection’s name.

{{ collections.root.name }}

Parameters:

  • arg (String)

    The name of a collection.

Returns:



37
38
39
# File 'lib/lifer/builder/html/from_liquid/drops/collections_drop.rb', line 37

def liquid_method_missing(arg)
  collections.detect { arg.to_sym == _1.name }
end

#to_aArray

Allow collections to be rendered as an array in Liquid templates.

Returns:

  • (Array)


27
# File 'lib/lifer/builder/html/from_liquid/drops/collections_drop.rb', line 27

def to_a = @collections