Sha256: 5dc0bba3b01adde8e691f1e1a231f0fbd98461203fde1024a289c7c6554f2171

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'roar/decorator'
require 'roar/json'
module Spotlight
  ##
  # Serialize an exhibit page
  class PageRepresenter < Roar::Decorator
    include Roar::JSON
    (Spotlight::Page.attribute_names - %w(id scope exhibit_id parent_page_id content thumbnail_id)).each do |prop|
      property prop
    end

    property :content, exec_context: :decorator

    def content
      # get the original data, bypassing any Sir-Trevor transformations
      represented.read_attribute(:content)
    end

    delegate :content=, to: :represented
  end

  ##
  # Serialize the page hierarchy (e.g. for Feature pages)
  class NestedPageRepresenter < PageRepresenter
    collection :child_pages, populator: ->(fragment, options) { options[:represented].child_pages.find_or_initialize_by(slug: fragment['slug']) },
                             class: Spotlight::FeaturePage,
                             extend: NestedPageRepresenter

    property :thumbnail, class: Spotlight::FeaturedImage, decorator: FeaturedImageRepresenter, if: Spotlight::ExhibitExportSerializer.config?(:attachments)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.alpha.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-3.0.0.alpha.1 app/serializers/spotlight/page_representer.rb