Skip to content

Commit

Permalink
Use custom document loader for oa.jsonld
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed May 13, 2016
1 parent 284c69d commit f49282e
Show file tree
Hide file tree
Showing 6 changed files with 1,133 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/active_annotations.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "active_annotations/version"
require "active_annotations/rdf_annotation"
require "active_annotations/document_loader"
require "active_annotations/engine"

module ActiveAnnotations
Expand Down
20 changes: 20 additions & 0 deletions lib/active_annotations/document_loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module ActiveAnnotations
module DocumentLoader
class << self
def local_document_loader(url, options={}, &block)
if RDF::URI(url) == RDF::URI(RDFAnnotation::CONTEXT_URI)
remote_document = JSON::LD::API::RemoteDocument.new(url, File.read(File.expand_path('../oa.jsonld',__FILE__)))
block_given? ? yield(remote_document) : remote_document
else
# :nocov:
JSON::LD::API.documentLoader(url, options, &block)
# :nocov:
end
end

def document_loader
ENV['NO_RDF_CACHE'] == '1' ? JSON::LD::API.method(:documentLoader) : self.method(:local_document_loader)
end
end
end
end
Loading

0 comments on commit f49282e

Please sign in to comment.