Module: Iron::Entry::Presentable

Extended by:
ActiveSupport::Concern
Included in:
Iron::Entry
Defined in:
app/models/iron/entry/presentable.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/iron/entry/presentable.rb', line 5

def attributes
  locale = Iron::Current.locale || Iron::Locale.default

  Rails.cache.fetch("#{cache_key_with_version}/#{locale.code}/attributes") do
    result = OpenStruct.new(id: id)

    result. = OpenStruct.new(
      locale: locale,
      web: OpenStruct.new(
        title: web_title,
        path: path
      )
    )

    content_type.field_definitions.each do |field_definition|
      field = find_field_for_presentation(field_definition, locale)

      result[field_definition.handle] = if field.present?
        field.value
      elsif field_definition.is_a?(FieldDefinitions::BlockList)
        []
      else
        nil
      end
    end

    result
  end
end

#find_field_for_presentation(field_definition, locale) ⇒ Object



35
36
37
38
39
40
41
42
# File 'app/models/iron/entry/presentable.rb', line 35

def find_field_for_presentation(field_definition, locale)
  fields.find do |f|
    f.definition_id == field_definition.id &&
    f.definition_type == field_definition.class.base_class.to_s &&
    f.locale_id == locale.id &&
    f.parent.nil?
  end
end