Class: Prismic::LinkResolver

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

Overview

The LinkResolver will help to build URL specific to an application, based on a generic prismic.io's Document link.

The link_resolver function is the recommended way to create a LinkResolver.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref) {|doc_link| ... } ⇒ LinkResolver

Returns a new instance of LinkResolver.

Yield Parameters:

Yield Returns:

  • (String)

    The application specific URL of the given document



566
567
568
569
# File 'lib/prismic.rb', line 566

def initialize(ref, &blk)
  @ref = ref
  @blk = blk
end

Instance Attribute Details

#refObject (readonly)

Returns the value of attribute ref.



562
563
564
# File 'lib/prismic.rb', line 562

def ref
  @ref
end

Instance Method Details



570
571
572
573
574
575
576
577
# File 'lib/prismic.rb', line 570

def link_to(doc)
  if doc.is_a? Prismic::Fragments::DocumentLink
    @blk.call(doc)
  elsif doc.is_a? Prismic::Document
    doc_link = Prismic::Fragments::DocumentLink.new(doc.id, doc.uid, doc.type, doc.tags, doc.slug, doc.lang, doc.fragments, false)
    @blk.call(doc_link)
  end
end