class Locomotive::Steam::Liquid::Drops::ContentEntry
Public Instance Methods
_id()
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 11 def _id @_source._id.to_s end
_label()
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 15 def _label @_label ||= @_source._label end
as_json(options = nil)
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 82 def as_json(options = nil) self.to_hash.as_json(options) end
errors()
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 45 def errors if @_source.errors.blank? false else @_source.errors.messages.to_hash.stringify_keys end end
liquid_method_missing(meth)
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 53 def liquid_method_missing(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
next()
click to toggle source
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 %}
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 28 def next @next ||= repository(@_source).next(@_source).to_liquid end
previous()
click to toggle source
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 %}
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 41 def previous @previous ||= repository(@_source).previous(@_source).to_liquid end
to_hash()
click to toggle source
# 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
Protected Instance Methods
conditions_for(name)
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 101 def conditions_for(name) # note: treat conditions only they apply to the content type (if it's a has_many/many_to_many relationships) _name = @context['with_scope_content_type'] !_name || _name == name ? @context['with_scope'] : nil end
file_field_to_url(field)
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 92 def file_field_to_url(field) field.to_liquid.tap { |drop| drop.context = @context }.url end
liquify_entry(entry)
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 88 def liquify_entry(entry) self.class.new(entry).tap { |drop| drop.context = @context } end
repository(entry)
click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry.rb, line 96 def repository(entry) repository = @context.registers[:services].repositories.content_entry repository.with(entry.content_type) end