Permalink
Browse files

Added etc/foaf.html and etc/xhv.html.

  • Loading branch information...
1 parent 858d11f commit 64b0febac8bb6d21971cfa1a9436d91fa083a22f @gkellogg gkellogg committed Jun 3, 2010
Showing with 44 additions and 15 deletions.
  1. +1 −0 AUTHORS
  2. +3 −2 Rakefile
  3. +11 −12 lib/rdf/rdfa/reader.rb
  4. +29 −1 spec/{rdfa_parser_spec.rb → rdfa_reader_spec.rb}
View
1 AUTHORS
@@ -0,0 +1 @@
+* Gregg Kellogg <gregg@kellogg-assoc.com>
View
5 Rakefile
@@ -12,12 +12,13 @@ begin
gemspec.email = "gregg@kellogg-assoc.com"
gemspec.homepage = "http://github.com/gkellogg/rdf-rdfa"
gemspec.authors = ["Gregg Kellogg", "Nicholas Humfrey"]
- gemspec.add_dependency('nokogiri', '>= 1.3.3')
gemspec.add_dependency('rdf', '>= 0.1.6')
+ gemspec.add_dependency('nokogiri', '>= 1.3.3')
+ gemspec.add_dependency('patron', '>= 0.4.6')
gemspec.add_development_dependency('rspec')
gemspec.add_development_dependency('rdf-spec')
gemspec.add_development_dependency('activesupport', '>= 2.3.0')
- gemspec.extra_rdoc_files = %w(README.rdoc History.txt)
+ gemspec.extra_rdoc_files = %w(README.rdoc History.txt AUTHORS)
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
23 lib/rdf/rdfa/reader.rb
@@ -12,7 +12,6 @@ module RDF::RDFa
# 2009-08-04
class Reader < RDF::Reader
format Format
- autoload :Namespace, 'rdf/rdfa/reader/namespace'
autoload :VERSION, 'rdf/rdfa/version'
NC_REGEXP = Regexp.new(
@@ -328,12 +327,12 @@ def extract_mappings(element, uri_mappings, term_mappings)
# object literal of the rdfa:uri predicate. Add or update this mapping in the local list of
# URI mappings after transforming the 'prefix' component to lower-case.
# For every extracted
- um[prefix.to_s.downcase] = uri.to_s if prefix
+ um[prefix.to_s.downcase] = RDF::URI.new(uri) if prefix
# triple that is the common subject of an rdfa:term and an rdfa:uri predicate, create a
# mapping from the object literal of the rdfa:term predicate to the object literal of the
# rdfa:uri predicate. Add or update this mapping in the local term mappings.
- tm[term.to_s] = RDF::URI.new(uri.to_s) if term
+ tm[term.to_s] = RDF::URI.new(uri) if term
end
rescue ParserException
add_debug(element, "extract_mappings: profile subject #{subject.to_s}: #{e.message}")
@@ -357,7 +356,7 @@ def extract_mappings(element, uri_mappings, term_mappings)
element.namespaces.each do |attr_name, attr_value|
begin
abbr, prefix = attr_name.split(":")
- uri_mappings[prefix.to_s.downcase] = attr_value if abbr.downcase == "xmlns" && prefix
+ uri_mappings[prefix.to_s.downcase] = RDF::URI.new(attr_value) if abbr.downcase == "xmlns" && prefix
# FIXME: rescue RdfException => e
rescue Exception => e
add_debug(element, "extract_mappings raised #{e.class}: #{e.message}")
@@ -376,7 +375,7 @@ def extract_mappings(element, uri_mappings, term_mappings)
next unless prefix.match(/:$/)
prefix.chop!
- uri_mappings[prefix] = uri
+ uri_mappings[prefix] = RDF::URI.new(uri)
end
add_debug(element, "uri_mappings: #{uri_mappings.values.map{|ns|ns.to_s}.join(", ")}")
@@ -432,7 +431,7 @@ def traverse(element, evaluation_context)
# Set default_vocabulary to host language default
@host_defaults.fetch(:voabulary, nil)
else
- vocab.to_s
+ RDF::URI.new(vocab)
end
add_debug(element, "[Step 2] traverse, default_vocaulary: #{default_vocabulary.inspect}")
end
@@ -686,7 +685,7 @@ def process_uri(element, value, evaluation_context, options = {})
add_debug(element, "process_uri: #{value} => CURIE => <#{uri}>")
else
#FIXME: uri = URIRef.new(value, evaluation_context.base)
- uri = RDF::URI.new(value)
+ uri = RDF::URI.new(evaluation_context.base + value)
add_debug(element, "process_uri: #{value} => URI => <#{uri}>")
end
uri
@@ -707,7 +706,7 @@ def process_term(value, options)
options[:term_mappings][value.to_s.downcase]
when options[:vocab]
# Otherwise, if there is a local default vocabulary the URI is obtained by concatenating that value and the term.
- options[:vocab] + value
+ options[:vocab].join(value)
else
# Finally, if there is no local default vocabulary, the term has no associated URI and must be ignored.
nil
@@ -727,18 +726,18 @@ def curie_to_resource_or_bnode(element, curie, uri_mappings, subject)
elsif curie.to_s.match(/^:/)
# Default prefix
if uri_mappings[""]
- uri_mappings[""].send("#{reference}_")
+ uri_mappings[""].join(reference)
elsif @host_defaults[:prefix]
- @host_defaults[:prefix].send("#{reference}_")
+ @host_defaults[:prefix].join(reference)
end
elsif !curie.to_s.match(/:/)
# No prefix, undefined (in this context, it is evaluated as a term elsewhere)
nil
else
- # XXX Spec Confusion, are prefixes always downcased?
+ # Prefixes always downcased
ns = uri_mappings[prefix.to_s.downcase]
if ns
- ns + reference
+ ns.join(reference)
else
add_debug(element, "curie_to_resource_or_bnode No namespace mapping for #{prefix.downcase}")
nil
View
30 spec/rdfa_parser_spec.rb → spec/rdfa_reader_spec.rb
@@ -1,6 +1,34 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
-describe "RDFa parser" do
+describe RDF::RDFa::Format do
+ it "should be discoverable" do
+ formats = [
+ RDF::Format.for(:rdfa),
+ RDF::Format.for("etc/foaf.html"),
+ RDF::Format.for(:file_name => "etc/foaf.html"),
+ RDF::Format.for(:file_extension => "html"),
+ RDF::Format.for(:file_extension => "xhtml"),
+ RDF::Format.for(:content_type => "text/html"),
+ RDF::Format.for(:content_type => "application/xhtml+xml"),
+ ]
+ formats.each { |format| format.should == RDF::RDFa::Format }
+ end
+end
+
+describe "RDF::RDFa::Reader" do
+ it "should be discoverable" do
+ readers = [
+ RDF::Reader.for(:rdfa),
+ RDF::Reader.for("etc/foaf.html"),
+ RDF::Reader.for(:file_name => "etc/foaf.html"),
+ RDF::Reader.for(:file_extension => "html"),
+ RDF::Reader.for(:file_extension => "xhtml"),
+ RDF::Reader.for(:content_type => "text/html"),
+ RDF::Reader.for(:content_type => "application/xhtml+xml"),
+ ]
+ readers.each { |reader| reader.should == RDF::RDFa::Reader }
+ end
+
it "should parse simple doc" do
sampledoc = <<-EOF;
<?xml version="1.0" encoding="UTF-8"?>

0 comments on commit 64b0feb

Please sign in to comment.