Sha256: b22fcba8c6af2980dc32b4e7ae5c5b522b148d50f8a0ac21701ffffddf0bf34a

Contents?: true

Size: 697 Bytes

Versions: 3

Compression:

Stored size: 697 Bytes

Contents

# Syntax
# {% asset_data tag'test', as:'sale_vehicles' %}

class AssetDataTag < Cms::DataTag
  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.scoped(:order => random_func)
      else
        assets.scoped(:order => 'cms_assets.created_at ASC')
      end

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

      assets.all
    end

    yield 'assets', collection
  end
end

Liquid::Template.register_tag('asset_data', AssetDataTag)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
liquid_cms-0.2.2.0 app/liquid/tags/asset_search_tag.rb
liquid_cms-0.2.1.1 app/liquid/tags/asset_search_tag.rb
liquid_cms-0.2.1.0 app/liquid/tags/asset_search_tag.rb