class PrismicRails::Document

The PrismicRails::Document is a wrapper class around Prismic::Document to support custom features like to_html, to_text and to handle nil documents.

Attributes

document[R]

Public Class Methods

new(document) click to toggle source

Creates a new PrismicRails::Document

+document+ A Prismic::Document
# File lib/prismic_rails/content/document.rb, line 11
def initialize(document)
  @document = document || PrismicRails::NilDocument.new
end

Public Instance Methods

as_html(serializer = nil) click to toggle source

Returns the document as safe html

# File lib/prismic_rails/content/document.rb, line 16
def as_html(serializer = nil)
  @document.as_html(serializer)
end
as_text() click to toggle source

Returns only the text of a document

# File lib/prismic_rails/content/document.rb, line 21
def as_text
  @document.as_text
end
find_fragment(type) click to toggle source

Finds a fragment of a specific type in a document

+type+ 'text', 'image' etc
# File lib/prismic_rails/content/document.rb, line 28
def find_fragment(type)
  fragment = @document.fragments[type]
  if fragment
    PrismicRails::Fragment.new(fragment)
  else
    NilDocument.new
  end
end
is_type?(type) click to toggle source

Tests if the document has the type type.

+type+ 'text', 'image' etc
# File lib/prismic_rails/content/document.rb, line 40
def is_type? type
  type == @document.type
end