Sha256: 25dd389d4fbdefab508e11e6b731597d6dc7d30bb2e64dbff98a3b681f7ca21f

Contents?: true

Size: 1.01 KB

Versions: 33

Compression:

Stored size: 1.01 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, parse_strategy: ->(fragment, _i, 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

33 entries across 33 versions & 1 rubygems

Version Path
blacklight-spotlight-0.31.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.30.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.29.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.29.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.28.3 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.28.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.28.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.28.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.27.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.26.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.26.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.25.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.24.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.23.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.22.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.21.0 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.20.3 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.20.2 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.20.1 app/serializers/spotlight/page_representer.rb
blacklight-spotlight-0.20.0 app/serializers/spotlight/page_representer.rb