Sha256: 5ae17894dcc0d259c696ac6cfa19ab6e65e2dbb305512bdf03608dd99d89d6ab

Contents?: true

Size: 1 KB

Versions: 34

Compression:

Stored size: 1 KB

Contents

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

34 entries across 34 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.4.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.3.3 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.3.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.3.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.3.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.2.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.2.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.1.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0.rc6 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0.rc5 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0.rc4 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0.rc3 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0.rc2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-2.0.0.rc1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-1.5.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-1.4.1 app/serializers/spotlight/page_representer.rb