Class: RoadForest::TypeHandlers::RDFaWriter
- Inherits:
-
RDF::Writer
- Object
- RDF::Writer
- RoadForest::TypeHandlers::RDFaWriter
- Defined in:
- lib/roadforest/type-handlers/rdfa-writer.rb,
lib/roadforest/type-handlers/rdfa-writer/render-engine.rb,
lib/roadforest/type-handlers/rdfa-writer/object-environment.rb,
lib/roadforest/type-handlers/rdfa-writer/render-environment.rb,
lib/roadforest/type-handlers/rdfa-writer/subject-environment.rb,
lib/roadforest/type-handlers/rdfa-writer/document-environment.rb,
lib/roadforest/type-handlers/rdfa-writer/property-environment.rb,
lib/roadforest/type-handlers/rdfa-writer/environment-decorator.rb
Overview
An RDFa 1.1 serialiser in Ruby. The RDFa serializer makes use of Haml templates, allowing runtime-replacement with alternate templates. Note, however, that templates should be checked against the W3C test suite to ensure that valid RDFa is emitted.
Note that the natural interface is to write a whole graph at a time. Writing statements or Triples will create a graph to add them to and then serialize the graph.
The writer will add prefix definitions, and use them for creating @prefix definitions, and minting CURIEs
Defined Under Namespace
Classes: AffordanceDecorator, DecorationSet, DocumentAffordanceDecorator, DocumentEnvironment, EnvironmentDecorator, NilObjectEnvironment, NodeObjectEnvironment, ObjectAffordanceDecorator, ObjectEnvironment, PropertyAffordanceDecorator, PropertyEnvironment, RDFPostCurie, RenderEngine, RenderEnvironment, SubjectAffordanceDecorator, SubjectEnvironment, TemplateHandler, UriObjectEnvironment, XMLLiteralObjectEnvironment
Constant Summary collapse
- HAML_OPTIONS =
{ :ugly => true, # to preserve whitespace without using entities }
Instance Attribute Summary collapse
-
#base_uri ⇒ RDF::URI
Base URI used for relativizing URIs.
-
#graph ⇒ Graph
Graph of statements serialized.
Instance Method Summary collapse
-
#initialize(output = $stdout, options = {}) {|writer| ... } ⇒ RDFaWriter
constructor
Initializes the RDFa writer instance.
-
#write_epilogue ⇒ void
Outputs the XHTML+RDFa representation of all stored triples.
-
#write_graph(graph) ⇒ void
Write whole graph.
-
#write_statement(statement) ⇒ void
Addes a statement to be serialized.
-
#write_triple(subject, predicate, object) ⇒ void
abstract
Addes a triple to be serialized.
Constructor Details
#initialize(output = $stdout, options = {}) {|writer| ... } ⇒ RDFaWriter
Initializes the RDFa writer instance.
91 92 93 94 95 96 97 98 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 91 def initialize(output = $stdout, = {}, &block) super do @graph = RDF::Graph.new @valise = nil block.call(self) if block_given? end end |
Instance Attribute Details
#base_uri ⇒ RDF::URI
Returns Base URI used for relativizing URIs.
59 60 61 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 59 def base_uri @base_uri end |
#graph ⇒ Graph
Returns Graph of statements serialized.
56 57 58 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 56 def graph @graph end |
Instance Method Details
#write_epilogue ⇒ void
This method returns an undefined value.
Outputs the XHTML+RDFa representation of all stored triples.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 136 def write_epilogue require 'roadforest/type-handlers/rdfa-writer/render-engine' @base_uri = RDF::URI(@options[:base_uri]) if @options[:base_uri] @lang = @options[:lang] @debug = @options[:debug] engine = RenderEngine.new(@graph, @debug) do |engine| engine.valise = Valise.define do ro up_to("lib") + "roadforest" end engine.style_name = @options[:haml] engine.base_uri = base_uri engine.lang = @lang engine.standard_prefixes = @options[:standard_prefixes] engine.top_classes = @options[:top_classes] || [RDF::RDFS.Class] engine.predicate_order = @options[:predicate_order] || [RDF.type, RDF::RDFS.label, RDF::DC.title] engine.heading_predicates = @options[:heading_predicates] || [RDF::RDFS.label, RDF::DC.title] engine. = @options[:haml_options] end engine.prefixes.merge! @options[:prefixes] unless @options[:prefixes].nil? # Generate document rendered = engine.render_document @output.write(rendered) end |
#write_graph(graph) ⇒ void
This method returns an undefined value.
Write whole graph
105 106 107 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 105 def write_graph(graph) @graph = graph end |
#write_statement(statement) ⇒ void
This method returns an undefined value.
Addes a statement to be serialized
114 115 116 117 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 114 def write_statement(statement) raise RDF::WriterError, "Statement #{statement.inspect} is invalid" if validate? && statement.invalid? @graph.insert(statement) end |
#write_triple(subject, predicate, object) ⇒ void
This method returns an undefined value.
Addes a triple to be serialized
128 129 130 |
# File 'lib/roadforest/type-handlers/rdfa-writer.rb', line 128 def write_triple(subject, predicate, object) write_statement Statement.new(subject, predicate, object) end |