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



544
545
546
547
# File 'lib/prismic.rb', line 544

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

Instance Attribute Details

#refObject (readonly)

Returns the value of attribute ref



540
541
542
# File 'lib/prismic.rb', line 540

def ref
  @ref
end

Instance Method Details



548
549
550
551
552
553
554
555
# File 'lib/prismic.rb', line 548

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.fragments, false)
    @blk.call(doc_link)
  end
end