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_boolean_field, #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, lang, fragments, broken, target = nil) ⇒ DocumentLink

Returns a new instance of DocumentLink.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/prismic/fragments/link.rb', line 112

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

Instance Attribute Details

#brokenObject Also known as: broken?

Returns the value of attribute broken.



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

def broken
  @broken
end

#fragmentsObject

Returns the value of attribute fragments.



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

def fragments
  @fragments
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#langObject

Returns the value of attribute lang.



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

def lang
  @lang
end

#slugObject

Returns the value of attribute slug.



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

def slug
  @slug
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#uidObject

Returns the value of attribute uid.



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

def uid
  @uid
end

Instance Method Details

#as_html(link_resolver = nil) ⇒ Object



132
133
134
# File 'lib/prismic/fragments/link.rb', line 132

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

#end_htmlObject



128
129
130
# File 'lib/prismic/fragments/link.rb', line 128

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


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

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

#start_html(link_resolver, target = nil) ⇒ Object



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

def start_html(link_resolver, target = nil)
  broken? ? %(<span>) : super
end

#url(link_resolver) ⇒ Object

Returns the URL of the link

Parameters:

See Also:



148
149
150
151
# File 'lib/prismic/fragments/link.rb', line 148

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