Class: Prismic::Fragments::CompositeSlice
- Defined in:
- lib/prismic/fragments/slices.rb
Overview
A fragment of type CompositeSlice, an item in a SliceZone
Instance Attribute Summary collapse
-
#non_repeat ⇒ Object
Returns the value of attribute non_repeat.
-
#repeat ⇒ Object
Returns the value of attribute repeat.
-
#slice_label ⇒ Object
Returns the value of attribute slice_label.
-
#slice_type ⇒ Object
Returns the value of attribute slice_type.
Instance Method Summary collapse
-
#as_html(link_resolver = nil) ⇒ String
Generate an HTML representation of the group.
-
#as_text ⇒ String
Generate an text representation of the group.
-
#initialize(slice_type, slice_label, non_repeat, repeat) ⇒ CompositeSlice
constructor
A new instance of CompositeSlice.
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_repeat ⇒ Object
Returns the value of attribute non_repeat.
9 10 11 |
# File 'lib/prismic/fragments/slices.rb', line 9 def non_repeat @non_repeat end |
#repeat ⇒ Object
Returns the value of attribute repeat.
10 11 12 |
# File 'lib/prismic/fragments/slices.rb', line 10 def repeat @repeat end |
#slice_label ⇒ Object
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_type ⇒ Object
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
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_text ⇒ String
Generate an text representation of the group
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 |