Class: Prismic::Fragments::CompositeSlice

Inherits:
Fragment
  • Object
show all
Defined in:
lib/prismic/fragments/slices.rb

Overview

A fragment of type CompositeSlice, an item in a SliceZone

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slice_type, slice_label, non_repeat, repeat) ⇒ CompositeSlice

Returns a new instance of CompositeSlice.



12
13
14
15
16
17
# File 'lib/prismic/fragments/slices.rb', line 12

def initialize(slice_type, slice_label, non_repeat, repeat)
  @slice_type = slice_type
  @slice_label = slice_label
  @non_repeat = non_repeat
  @repeat = repeat
end

Instance Attribute Details

#non_repeatObject

Returns the value of attribute non_repeat.



9
10
11
# File 'lib/prismic/fragments/slices.rb', line 9

def non_repeat
  @non_repeat
end

#repeatObject

Returns the value of attribute repeat.



10
11
12
# File 'lib/prismic/fragments/slices.rb', line 10

def repeat
  @repeat
end

#slice_labelObject

Returns the value of attribute slice_label.



8
9
10
# File 'lib/prismic/fragments/slices.rb', line 8

def slice_label
  @slice_label
end

#slice_typeObject

Returns the value of attribute slice_type.



7
8
9
# File 'lib/prismic/fragments/slices.rb', line 7

def slice_type
  @slice_type
end

Instance Method Details

#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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/prismic/fragments/slices.rb', line 37

def as_html(link_resolver=nil)
  classes = ['slice']
  unless (@slice_label.nil?)
    classes.push(@slice_label)
  end

  non_repeat_html = ''
  @non_repeat.each do |fragment_key, fragment_value|
    non_repeat_html += fragment_value.as_html(link_resolver)
  end

  repeat_html = repeat.as_html(link_resolver)

  %[<div data-slicetype="#{@slice_type}" class="#{classes.join(' ')}">#{non_repeat_html + repeat_html}</div>]
end

#as_textString

Generate an text representation of the group

Returns:

  • (String)

    the text representation



22
23
24
25
26
27
28
29
# File 'lib/prismic/fragments/slices.rb', line 22

def as_text
  non_repeat_text = ''
  @non_repeat.each do |fragment_key, fragment_value|
    non_repeat_text += fragment_value.as_text
  end

  "#{non_repeat_text}\n#{@repeat.as_text}"
end