Sha256: dad24c32843a24285184241c19dfb576094e457d51f9d6469f1678b9d9c03a8e

Contents?: true

Size: 698 Bytes

Versions: 3

Compression:

Stored size: 698 Bytes

Contents

module Slices
  # We keep this method in here to facilate easier overriding when re-opening Page.
  module PageAsJSON
    include Slices::LocalizedFields

    def as_json(options = {})
      options ||= {}

      hash = attributes.symbolize_keys.except(:_id, :_type, :_keywords, :set_slices).merge(
        id:        id,
        permalink: permalink,
        slices:    ordered_slices_for(options[:slice_embed]).map {|slice| slice.as_json },
        available_layouts: available_layouts,
        author: author
      )

      localized_field_names.each do |name|
        hash.merge!(name => send(name))
      end

      keys = options[:only]
      keys ? hash.slice(keys) : hash
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slices-2.0.2 lib/slices/page_as_json.rb
slices-2.0.1 lib/slices/page_as_json.rb
slices-2.0.0 lib/slices/page_as_json.rb