Class: Prismic::Fragments::Group

Inherits:
Fragment
  • Object
show all
Includes:
Enumerable
Defined in:
lib/prismic/fragments/group.rb

Overview

A fragment of type Group, which contains an array of FragmentList (which itself is a Hash of fragments).

For instance, imagining this group is defined with two possible fragments: an image fragment "image", and a text fragment "caption"; then accessing the first image will look like this: group[0]['image'].

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_documents) ⇒ Group

Returns a new instance of Group



33
34
35
# File 'lib/prismic/fragments/group.rb', line 33

def initialize(group_documents)
  @group_documents = group_documents
end

Instance Attribute Details

#group_documentsObject

The array of group documents



31
32
33
# File 'lib/prismic/fragments/group.rb', line 31

def group_documents
  @group_documents
end

Instance Method Details

#[](index) ⇒ Prismic::WithFragments Also known as: get

Get the group document corresponding to index



39
40
41
# File 'lib/prismic/fragments/group.rb', line 39

def [](index)
  @group_documents[index]
end

#as_html(link_resolver = nil) ⇒ String

Generate an HTML representation of the group

Parameters:

  • link_resolver (LinkResolver) (defaults to: nil)

    The LinkResolver used to build application's specific URL

Returns:

  • (String)

    the HTML representation



61
62
63
# File 'lib/prismic/fragments/group.rb', line 61

def as_html(link_resolver = nil)
  @group_documents.map { |doc| doc.as_html(link_resolver) }.join("\n")
end

#as_textString

Generate an text representation of the group

Returns:

  • (String)

    the text representation



68
69
70
# File 'lib/prismic/fragments/group.rb', line 68

def as_text
  @group_documents.map { |doc| doc.as_text }.join("\n")
end

#each {|group_doc| ... } ⇒ Object

Yield Parameters:

  • group_doc (WithFragment)


45
46
47
# File 'lib/prismic/fragments/group.rb', line 45

def each(&blk)
  @group_documents.each(&blk)
end

#lengthObject Also known as: size



50
51
52
# File 'lib/prismic/fragments/group.rb', line 50

def length
  @group_documents.length
end