Class: Locomotive::Steam::Liquid::Drops::ContentEntry
Instance Method Summary collapse
- #_id ⇒ Object
- #_label ⇒ Object
- #as_json(options = nil) ⇒ Object
- #before_method(meth) ⇒ Object
- #errors ⇒ Object
-
#next ⇒ Object
Returns the next content for the parent content type.
-
#previous ⇒ Object
Returns the previous content for the parent content type.
- #to_hash ⇒ Object
Methods inherited from I18nBase
Methods inherited from Base
Constructor Details
This class inherits a constructor from Locomotive::Steam::Liquid::Drops::I18nBase
Instance Method Details
#_id ⇒ Object
11 12 13 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 11 def _id @_source._id.to_s end |
#_label ⇒ Object
15 16 17 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 15 def _label @_label ||= @_source._label end |
#as_json(options = nil) ⇒ Object
82 83 84 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 82 def as_json( = nil) self.to_hash.as_json() end |
#before_method(meth) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 53 def before_method(meth) return '' if @_source.nil? if not @@forbidden_attributes.include?(meth.to_s) repository(@_source).value_for(@_source, meth, conditions_for(meth)) else nil end end |
#errors ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 45 def errors if @_source.errors.blank? false else @_source.errors..to_hash.stringify_keys end end |
#next ⇒ Object
Returns the next content for the parent content type. If no content is found, nil is returned.
Usage:
if article.next % <a href=“path_to article.next %”>Read next article</a> endif %
28 29 30 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 28 def next @next ||= repository(@_source).next(@_source).to_liquid end |
#previous ⇒ Object
Returns the previous content for the parent content type. If no content is found, nil is returned.
Usage:
if article.previous % <a href=“path_to article.previous %”>Read previous article</a> endif %
41 42 43 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 41 def previous @previous ||= repository(@_source).previous(@_source).to_liquid end |
#to_hash ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/locomotive/steam/liquid/drops/content_entry.rb', line 63 def to_hash @_source.to_hash.tap do |hash| hash['id'] = hash['_id'] @_source.content_type.fields_by_name.each do |name, field| case field.type when :belongs_to hash[name] = liquify_entry(@_source.send(name))._slug if hash["#{name}_id"].present? when :many_to_many hash[name] = (@_source.send(name) || []).all.map { |e| liquify_entry(e)._slug }.compact when :file hash[name] = hash["#{name}_url"] = file_field_to_url(hash[name.to_s]) if hash[name.to_s].present? when :select hash[name] = @_source.send(name) if hash["#{name}_id"].present? end end end end |