class Locomotive::Steam::Liquid::Drops::ContentEntryCollection

Public Class Methods

new(content_type, repository = nil) click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 10
def initialize(content_type, repository = nil)
  @content_type = content_type
  @repository   = repository
end

Public Instance Methods

all() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 15
def all
  collection.map do |entry|
    entry.to_liquid.tap do |drop|
      if drop && drop.respond_to?(:context=)
        drop.context = @context
      end
    end
  end
end
api() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 36
def api
  Locomotive::Common::Logger.warn "[Liquid template] the api for content_types has been deprecated and replaced by public_submission_url instead."
  { 'create' => public_submission_url }
end
count() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 25
def count
  repository.count(conditions)
end
Also aliased as: size, length
length()
Alias for: count
liquid_method_missing(meth) click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 41
def liquid_method_missing(meth)
  if (meth.to_s =~ /^group_by_(.+)$/) == 0
    repository.group_by_select_option($1)
  elsif (meth.to_s =~ /^(.+)_options$/) == 0
    select_options($1)
  else
    Locomotive::Common::Logger.warn "[Liquid template] trying to call #{meth} on a content_type object"
    nil
  end
end
public_submission_url() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 32
def public_submission_url
  services.url_builder.public_submission_url_for(@content_type)
end
size()
Alias for: count

Protected Instance Methods

collection() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 58
def collection
  @collection ||= repository.all(conditions)
end
conditions() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 62
def conditions
  _slug = (@context['with_scope_content_type'] ||= @content_type.slug)
  _slug == @content_type.slug ? @context['with_scope'] : {}
end
content_type_repository() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 71
def content_type_repository
  services.repositories.content_type
end
repository() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 75
def repository
  @repository || services.repositories.content_entry.with(@content_type)
end
select_options(name) click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 79
def select_options(name)
  locale          = @context.registers[:locale]
  default_locale  = @context.registers[:site].try(:default_locale)

  (content_type_repository.select_options(@content_type, name) || []).map do |option|
    _option = Locomotive::Steam::Decorators::I18nDecorator.new(option, locale, default_locale)
    ContentTypeFieldSelectOption.new(_option)
  end
end
services() click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 67
def services
  @context.registers[:services]
end
slice(index, length) click to toggle source
# File lib/locomotive/steam/liquid/drops/content_entry_collection.rb, line 54
def slice(index, length)
  repository.all(conditions) { offset(index).limit(length) }
end