Class: Prismic::Fragments::Slice

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

Overview

A fragment of type Slice, an item in a SliceZone

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slice_type, slice_label, value) ⇒ Slice

Returns a new instance of Slice



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

def initialize(slice_type, slice_label, value)
  @slice_type = slice_type
  @slice_label = slice_label
  @value = value
end

Instance Attribute Details

#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

#valueObject

Returns the value of attribute value



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

def value
  @value
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



30
31
32
33
34
35
36
# File 'lib/prismic/fragments/slices.rb', line 30

def as_html(link_resolver=nil)
  classes = ['slice']
  unless (@slice_label.nil?)
    classes.push(@slice_label)
  end
  %[<div data-slicetype="#{@slice_type}" class="#{classes.join(' ')}">#{@value.as_html(link_resolver)}</div>]
end

#as_textString

Generate an text representation of the group

Returns:

  • (String)

    the text representation



20
21
22
# File 'lib/prismic/fragments/slices.rb', line 20

def as_text
  @value.as_text
end