Sha256: 34b318a4cd673f0c1525f22435eccda43c833d50d0db194c7fcf4110b0be1515

Contents?: true

Size: 1.03 KB

Versions: 16

Compression:

Stored size: 1.03 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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
blacklight-spotlight-2.13.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.12.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.12.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.11.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.10.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.9.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.8.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.7.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.7.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.7.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.6.1.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.6.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.6.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.5.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.5.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.5.0 app/serializers/spotlight/page_representer.rb