Class: ComfortableMexicanSofa::Tag::Collection
- Inherits:
-
Object
- Object
- ComfortableMexicanSofa::Tag::Collection
- Includes:
- ComfortableMexicanSofa::Tag
- Defined in:
- lib/comfortable_mexican_sofa/tags/collection.rb
Constant Summary
Constants included from ComfortableMexicanSofa::Tag
Instance Attribute Summary
Attributes included from ComfortableMexicanSofa::Tag
#identifier, #page, #params, #parent
Class Method Summary collapse
-
.regex_tag_signature(identifier = nil) ⇒ Object
Here’s a full tag signature: cms:collection:label:collection_class:collection_partial:collection_title:collection_identifier:collection_params } Most minimal tag can look like this: cms:collection:album:foo/my_album } A more complete example of the above: cms:collection:album:foo/my_album:albums/show:title:slug:param_a:param_b }.
Instance Method Summary collapse
-
#collection_class ⇒ Object
Class definitition.
-
#collection_identifier ⇒ Object
Identifier that will be used to find selected collection object.
-
#collection_objects ⇒ Object
Array of objects used in the collection You may set up a scope on the model ‘scope :cms_collection, lambda|*args| do …
-
#collection_params ⇒ Object
Extra params that will be passed to the partial AND ALSO will be passed as parameters for the ‘cms_collection` scope you can define for your Collection object.
-
#collection_partial ⇒ Object
Path to the partial.
-
#collection_title ⇒ Object
Title method for the Collection objects.
- #content ⇒ Object
- #render ⇒ Object
Class Method Details
.regex_tag_signature(identifier = nil) ⇒ Object
Here’s a full tag signature:
{{ cms:collection:label:collection_class:collection_partial:collection_title:collection_identifier:collection_params }}
Most minimal tag can look like this:
{{ cms:collection:album:foo/my_album }}
A more complete example of the above:
{{ cms:collection:album:foo/my_album:albums/show:title:slug:param_a:param_b }}
10 11 12 13 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 10 def self.regex_tag_signature(identifier = nil) identifier ||= /[\w\/\-]+/ /\{\{\s*cms:collection:(#{identifier}):(.*?)\s*\}\}/ end |
Instance Method Details
#collection_class ⇒ Object
Class definitition. It’s basically ‘Herp::DerpityDerp.undescore` so an example of valid definition is: `herp/derpity_derp`
17 18 19 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 17 def collection_class self.params[0].classify end |
#collection_identifier ⇒ Object
Identifier that will be used to find selected collection object. Defaults to ‘id`
32 33 34 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 32 def collection_identifier self.params[3] || 'id' end |
#collection_objects ⇒ Object
Array of objects used in the collection You may set up a scope on the model ‘scope :cms_collection, lambda|*args| do … end ` `args` will be the set of `collection_params`
45 46 47 48 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 45 def collection_objects klass = self.collection_class.constantize klass.respond_to?(:cms_collection) ? klass.cms_collection(*collection_params).all : klass.all end |
#collection_params ⇒ Object
Extra params that will be passed to the partial AND ALSO will be passed as parameters for the ‘cms_collection` scope you can define for your Collection object
38 39 40 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 38 def collection_params self.params[4..-1] || [] end |
#collection_partial ⇒ Object
Path to the partial. Example: ‘path/to/partial`
22 23 24 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 22 def collection_partial self.params[1] || "partials/#{self.collection_class.underscore.pluralize}" end |
#collection_title ⇒ Object
Title method for the Collection objects. Default is ‘label`
27 28 29 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 27 def collection_title self.params[2] || 'label' end |
#content ⇒ Object
50 51 52 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 50 def content block.content end |
#render ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/comfortable_mexican_sofa/tags/collection.rb', line 54 def render if self.content.present? ps = collection_params.collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ') ps = ps.present?? ", #{ps}" : '' "<%= render :partial => '#{collection_partial}', :locals => {:model => '#{collection_class}', :identifier => '#{content}'#{ps}} %>" else '' end end |