Class: AssetDataTag

Inherits:
Cms::DataTag show all
Defined in:
app/liquid/tags/asset_search_tag.rb

Overview

Syntax asset_data tag’test’, as:‘sale_vehicles’ %

Instance Attribute Summary

Attributes inherited from Cms::DataTag

#context, #options

Attributes inherited from Liquid::Tag

#nodelist

Instance Method Summary collapse

Methods inherited from Cms::DataTag

#context_object, #initialize, #params, #render, #uses_random

Methods inherited from Liquid::Tag

#initialize, #name, #parse, #render

Constructor Details

This class inherits a constructor from Cms::DataTag

Instance Method Details

#get_data {|'assets', collection| ... } ⇒ Object

Yields:

  • ('assets', collection)

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/liquid/tags/asset_search_tag.rb', line 5

def get_data
  raise Liquid::ArgumentError.new("The required 'tag' parameter is missing.") if options[:tag].blank?

  collection = uses_random do |random_func|
    assets = context_object.assets.tagged_with(options[:tag])

    assets = if options[:random] == true
      assets.order(random_func)
    else
      assets.order('cms_assets.created_at ASC')
    end

    assets = assets.limit(options[:limit]) if options[:limit]

    assets.all
  end

  yield 'assets', collection
end