Class: Archangel::Liquid::Tags::CollectionTag
- Inherits:
-
ApplicationTag
- Object
- Liquid::Tag
- ApplicationTag
- Archangel::Liquid::Tags::CollectionTag
- Defined in:
- lib/archangel/liquid/tags/collection_tag.rb
Overview
Collection custom tag for Liquid to set a variable for Collections
Example
{% collection things = 'my-collection' %}
{% for item in things %}
{{ forloop.index }}: {{ item.name }}
{% endfor %}
{% collection things = 'my-collection' limit:5 offset:25 %}
{% for item in things %}
{{ forloop.index }}: {{ item.name }}
{% endfor %}
Constant Summary collapse
- SYNTAX =
Regex for tag syntax
/ (?<key>#{::Liquid::VariableSignature}+) \s* = \s* (?<value>#{::Liquid::QuotedFragment}+) \s* (?<attributes>.*) \s* /omx.freeze
Constants inherited from ApplicationTag
ApplicationTag::ASSET_ATTRIBUTES_SYNTAX, ApplicationTag::ASSET_SYNTAX, ApplicationTag::KEY_VALUE_ATTRIBUTES_SYNTAX, ApplicationTag::SLUG_ATTRIBUTES_SYNTAX, ApplicationTag::SLUG_SYNTAX, ApplicationTag::URL_ATTRIBUTES_SYNTAX
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(tag_name, markup, options) ⇒ CollectionTag
constructor
Collection for Liquid.
-
#render(context) ⇒ Hash
Render the collection object.
Constructor Details
#initialize(tag_name, markup, options) ⇒ CollectionTag
Collection for Liquid
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/archangel/liquid/tags/collection_tag.rb', line 42 def initialize(tag_name, markup, ) super match = SYNTAX.match(markup) if match.blank? raise ::Liquid::SyntaxError, Archangel.t("errors.syntax.collection") end @key = match[:key] @value = ::Liquid::Variable.new(match[:value], ).name @attributes = {} match[:attributes].scan(KEY_VALUE_ATTRIBUTES_SYNTAX) do |key, value| @attributes[key.to_sym] = ::Liquid::Expression.parse(value) end end |
Instance Method Details
#blank? ⇒ Boolean
75 76 77 |
# File 'lib/archangel/liquid/tags/collection_tag.rb', line 75 def blank? true end |
#render(context) ⇒ Hash
Render the collection object
66 67 68 69 70 71 72 73 |
# File 'lib/archangel/liquid/tags/collection_tag.rb', line 66 def render(context) val = load_collection(context["site"].object) context.scopes.last[key] = val context.resource_limits.assign_score << assign_score_of(val) "" end |