Class: Prismic::Fragments::DocumentLink

Inherits:
Link show all
Includes:
WithFragments
Defined in:
lib/prismic/fragments/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WithFragments

#[], #as_text, #each, #first_title, #get_color, #get_date, #get_embed, #get_geopoint, #get_group, #get_image, #get_link, #get_number, #get_slice_zone, #get_structured_text, #get_text, #get_timestamp, #length, #linked_documents

Methods inherited from Fragment

#as_text

Constructor Details

#initialize(id, uid, type, tags, slug, fragments, broken) ⇒ DocumentLink

Returns a new instance of DocumentLink



101
102
103
104
105
106
107
108
109
# File 'lib/prismic/fragments/link.rb', line 101

def initialize(id, uid, type, tags, slug, fragments, broken)
  @id = id
  @uid = uid
  @type = type
  @tags = tags
  @slug = slug
  @fragments = fragments
  @broken = broken
end

Instance Attribute Details

#brokenObject Also known as: broken?

Returns the value of attribute broken



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def broken
  @broken
end

#fragmentsObject

Returns the value of attribute fragments



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def fragments
  @fragments
end

#idObject

Returns the value of attribute id



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def id
  @id
end

#slugObject

Returns the value of attribute slug



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def slug
  @slug
end

#tagsObject

Returns the value of attribute tags



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def tags
  @tags
end

#typeObject

Returns the value of attribute type



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def type
  @type
end

#uidObject

Returns the value of attribute uid



99
100
101
# File 'lib/prismic/fragments/link.rb', line 99

def uid
  @uid
end

Instance Method Details

#as_html(link_resolver = nil) ⇒ Object



119
120
121
# File 'lib/prismic/fragments/link.rb', line 119

def as_html(link_resolver=nil)
  %(#{start_html(link_resolver)}#{slug}#{end_html})
end

#end_htmlObject



115
116
117
# File 'lib/prismic/fragments/link.rb', line 115

def end_html
  broken? ? %(</span>) : super
end


123
124
125
126
# File 'lib/prismic/fragments/link.rb', line 123

def link_type
  warn('WARNING: DocumentLink.link_type is deprecated, use DocumentLink.type instead')
  self.type
end

#start_html(link_resolver) ⇒ Object



111
112
113
# File 'lib/prismic/fragments/link.rb', line 111

def start_html(link_resolver)
  broken? ? %(<span>) : super
end

#url(link_resolver) ⇒ Object

Returns the URL of the link

Parameters:

See Also:



135
136
137
138
# File 'lib/prismic/fragments/link.rb', line 135

def url(link_resolver = nil)
  raise "A link_resolver method is needed to serialize document links into a correct URL on your website. If you're using a starter kit, a trivial one is provided out-of-the-box, that you can update later." if link_resolver == nil
  link_resolver.link_to(self)
end