Class: Cms::DataTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Cms::DataTag
- Defined in:
- app/liquid/tags/cms/data_tag.rb
Direct Known Subclasses
Defined Under Namespace
Modules: TagMethods
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from Liquid::Tag
Instance Method Summary collapse
- #context_object ⇒ Object
-
#initialize(tag_name, markup, tokens) ⇒ DataTag
constructor
A new instance of DataTag.
- #params ⇒ Object
- #render(context) ⇒ Object
- #uses_random(&block) ⇒ Object
Methods inherited from Liquid::Tag
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ DataTag
Returns a new instance of DataTag.
9 10 11 12 |
# File 'app/liquid/tags/cms/data_tag.rb', line 9 def initialize(tag_name, markup, tokens) @markup = markup super end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'app/liquid/tags/cms/data_tag.rb', line 6 def context @context end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'app/liquid/tags/cms/data_tag.rb', line 7 def end |
Instance Method Details
#context_object ⇒ Object
14 15 16 |
# File 'app/liquid/tags/cms/data_tag.rb', line 14 def context_object TagMethods.context_object(@context) end |
#params ⇒ Object
18 19 20 |
# File 'app/liquid/tags/cms/data_tag.rb', line 18 def params TagMethods.params(@context) end |
#render(context) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/liquid/tags/cms/data_tag.rb', line 22 def render(context) @context = context = TagMethods.(context, @markup) get_data do |name, data| context[[:as] || name] = data end '' end |
#uses_random(&block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/liquid/tags/cms/data_tag.rb', line 32 def uses_random(&block) collection = [] # random sql func supported by postgresql and sqlite (perhaps others) random_func = "random()" begin collection = yield random_func rescue ActiveRecord::StatementInvalid => e if [:random] == true # the random function used was invalid, so we'll try an alternative syntax for mysql (perhaps others) mysql_func = "rand()" if random_func != mysql_func random_func = mysql_func else # set random to false and just use the default order since the alt didn't work either [:random] = false end # retry the query retry end end collection end |