roadforest 0.1 → 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/file-management.rb +12 -13
- data/lib/roadforest-client.rb +3 -0
- data/lib/roadforest-common.rb +2 -0
- data/lib/roadforest-server.rb +7 -0
- data/lib/roadforest-testing.rb +1 -0
- data/lib/roadforest/application.rb +9 -7
- data/lib/roadforest/application/dispatcher.rb +39 -63
- data/lib/roadforest/application/parameters.rb +1 -1
- data/lib/roadforest/application/path-provider.rb +2 -2
- data/lib/roadforest/application/route-adapter.rb +130 -18
- data/lib/roadforest/application/services-host.rb +0 -4
- data/lib/roadforest/augment/affordance.rb +78 -0
- data/lib/roadforest/augment/augmentation.rb +97 -0
- data/lib/roadforest/augment/augmenter.rb +54 -0
- data/lib/roadforest/augmentations.rb +1 -0
- data/lib/roadforest/content-handling.rb +1 -0
- data/lib/roadforest/content-handling/common-engines.rb +67 -0
- data/lib/roadforest/content-handling/engine.rb +2 -14
- data/lib/roadforest/content-handling/handler-wrap.rb +29 -31
- data/lib/roadforest/content-handling/media-type.rb +6 -0
- data/lib/roadforest/{rdf.rb → graph.rb} +1 -1
- data/lib/roadforest/{rdf → graph}/access-manager.rb +12 -74
- data/lib/roadforest/{rdf → graph}/document.rb +1 -1
- data/lib/roadforest/{rdf → graph}/etagging.rb +2 -2
- data/lib/roadforest/{rdf → graph}/focus-list.rb +1 -9
- data/lib/roadforest/{rdf → graph}/graph-copier.rb +2 -2
- data/lib/roadforest/{rdf → graph}/graph-focus.rb +5 -7
- data/lib/roadforest/{rdf → graph}/normalization.rb +1 -1
- data/lib/roadforest/{rdf → graph}/post-focus.rb +2 -3
- data/lib/roadforest/graph/vocabulary.rb +96 -0
- data/lib/roadforest/http/graph-transfer.rb +2 -2
- data/lib/roadforest/interface/application.rb +145 -0
- data/lib/roadforest/interface/blob.rb +38 -0
- data/lib/roadforest/interface/rdf.rb +77 -0
- data/lib/roadforest/interfaces.rb +2 -0
- data/lib/roadforest/remote-host.rb +17 -17
- data/lib/roadforest/resource.rb +4 -0
- data/lib/roadforest/resource/{rdf/leaf-item.rb → leaf-item.rb} +1 -1
- data/lib/roadforest/resource/{rdf/list.rb → list.rb} +1 -1
- data/lib/roadforest/resource/{rdf/parent-item.rb → parent-item.rb} +1 -1
- data/lib/roadforest/resource/{rdf/read-only.rb → read-only.rb} +18 -18
- data/lib/roadforest/resource/role/has-children.rb +1 -1
- data/lib/roadforest/resource/role/writable.rb +2 -2
- data/lib/roadforest/server.rb +1 -1
- data/lib/roadforest/source-rigor.rb +9 -0
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/credence-annealer.rb +2 -2
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/credence.rb +5 -5
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/credence/any.rb +1 -1
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/credence/none-if-role-absent.rb +1 -1
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/credence/role-if-available.rb +1 -1
- data/lib/roadforest/source-rigor/engine.rb +45 -0
- data/lib/roadforest/{rdf → source-rigor}/graph-store.rb +9 -9
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/http-investigator.rb +2 -2
- data/lib/roadforest/{rdf → source-rigor}/investigation.rb +2 -2
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/investigator.rb +3 -3
- data/lib/roadforest/{rdf/source-rigor → source-rigor}/null-investigator.rb +3 -2
- data/lib/roadforest/{rdf → source-rigor}/parcel.rb +5 -5
- data/lib/roadforest/{rdf → source-rigor}/resource-pattern.rb +6 -6
- data/lib/roadforest/{rdf → source-rigor}/resource-query.rb +2 -2
- data/lib/roadforest/source-rigor/rigorous-access.rb +101 -0
- data/lib/roadforest/templates/affordance-doc.haml +23 -0
- data/lib/roadforest/templates/affordance-property-values.haml +13 -0
- data/lib/roadforest/templates/affordance-subject.haml +9 -0
- data/lib/roadforest/templates/affordance-uri-object.haml +2 -0
- data/lib/roadforest/templates/base/{property_value.haml → property-value.haml} +0 -0
- data/lib/roadforest/templates/base/{property_values.haml → property-values.haml} +0 -0
- data/lib/roadforest/templates/distiller/{property_value.haml → property-value.haml} +0 -0
- data/lib/roadforest/templates/distiller/{property_values.haml → property-values.haml} +0 -0
- data/lib/roadforest/templates/min/{property_values.haml → property-values.haml} +0 -0
- data/lib/roadforest/templates/rdfpost-curie.haml +6 -0
- data/lib/roadforest/test-support/dispatcher-facade.rb +2 -0
- data/lib/roadforest/test-support/matchers.rb +169 -5
- data/lib/roadforest/test-support/remote-host.rb +2 -2
- data/lib/roadforest/type-handlers/handler.rb +74 -0
- data/lib/roadforest/type-handlers/jsonld.rb +34 -0
- data/lib/roadforest/type-handlers/rdf-handler.rb +36 -0
- data/lib/roadforest/{content-handling/type-handlers → type-handlers}/rdfa-writer.rb +2 -2
- data/lib/roadforest/{content-handling/type-handlers → type-handlers}/rdfa-writer/document-environment.rb +9 -8
- data/lib/roadforest/type-handlers/rdfa-writer/environment-decorator.rb +312 -0
- data/lib/roadforest/{content-handling/type-handlers → type-handlers}/rdfa-writer/object-environment.rb +3 -3
- data/lib/roadforest/{content-handling/type-handlers → type-handlers}/rdfa-writer/property-environment.rb +5 -11
- data/lib/roadforest/type-handlers/rdfa-writer/render-engine.rb +427 -0
- data/lib/roadforest/{content-handling/type-handlers → type-handlers}/rdfa-writer/render-environment.rb +33 -26
- data/lib/roadforest/{content-handling/type-handlers → type-handlers}/rdfa-writer/subject-environment.rb +7 -23
- data/lib/roadforest/type-handlers/rdfa.rb +73 -0
- data/lib/roadforest/type-handlers/rdfpost.rb +301 -0
- data/lib/roadforest/utility/class-registry.rb +23 -5
- data/spec/.ctrlp-root +0 -0
- data/spec/affordance-augmenter.rb +75 -0
- data/spec/affordances-flow.rb +438 -0
- data/spec/authorization.rb +34 -0
- data/spec/client.rb +13 -12
- data/spec/credence-annealer.rb +5 -5
- data/spec/focus-list.rb +8 -8
- data/spec/full-integration.rb +3 -3
- data/spec/graph-copier.rb +4 -4
- data/spec/graph-store.rb +19 -31
- data/spec/keychain.rb +82 -0
- data/spec/rdf-normalization.rb +2 -2
- data/spec/rdf-parcel.rb +3 -3
- data/spec/rdfa-handler.rb +514 -0
- data/spec/rdfpost.rb +96 -0
- data/spec/source-rigor.rb +57 -0
- data/spec/update-focus.rb +11 -10
- metadata +91 -66
- data/lib/roadforest/blob-model.rb +0 -53
- data/lib/roadforest/content-handling/type-handler.rb +0 -76
- data/lib/roadforest/content-handling/type-handlers/jsonld.rb +0 -36
- data/lib/roadforest/content-handling/type-handlers/rdf-handler.rb +0 -38
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/render-engine.rb +0 -574
- data/lib/roadforest/content-handling/type-handlers/rdfa.rb +0 -175
- data/lib/roadforest/content-handling/type-handlers/rdfpost.rb +0 -297
- data/lib/roadforest/model.rb +0 -209
- data/lib/roadforest/models.rb +0 -2
- data/lib/roadforest/rdf/source-rigor.rb +0 -44
- data/lib/roadforest/rdf/vocabulary.rb +0 -11
- data/lib/roadforest/resource/http/form-parsing.rb +0 -81
- data/lib/roadforest/resource/rdf.rb +0 -4
- data/spec/form-parsing.rb +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require 'roadforest/
|
|
2
|
-
module RoadForest::
|
|
1
|
+
require 'roadforest/type-handlers/rdfa-writer/render-environment'
|
|
2
|
+
module RoadForest::TypeHandlers
|
|
3
3
|
class RDFaWriter
|
|
4
4
|
class ObjectEnvironment < RenderEnvironment
|
|
5
|
-
attr_accessor :predicate, :object, :inlist
|
|
5
|
+
attr_accessor :predicate, :object, :inlist
|
|
6
6
|
|
|
7
7
|
def simple_attrs
|
|
8
8
|
{:property => get_curie(predicate), :content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object), :inlist => inlist}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
require 'roadforest/
|
|
2
|
-
module RoadForest::
|
|
1
|
+
require 'roadforest/type-handlers/rdfa-writer/render-environment'
|
|
2
|
+
module RoadForest::TypeHandlers
|
|
3
3
|
class RDFaWriter
|
|
4
4
|
class PropertyEnvironment < RenderEnvironment
|
|
5
5
|
attr_accessor :object_terms, :predicate, :inlist
|
|
6
6
|
|
|
7
|
-
def yielded(item)
|
|
8
|
-
@_engine.render(item)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
7
|
def objects
|
|
12
8
|
enum_for(:each_object)
|
|
13
9
|
end
|
|
14
10
|
|
|
15
11
|
def each_object
|
|
16
12
|
object_terms.each do |term|
|
|
17
|
-
env =
|
|
13
|
+
env = object_env(predicate, term)
|
|
18
14
|
env.inlist = inlist
|
|
19
|
-
#XXX Remove element=
|
|
20
|
-
env.element = :li if object_terms.length > 1 || inlist
|
|
21
15
|
yield(env)
|
|
22
16
|
end
|
|
23
17
|
end
|
|
@@ -36,9 +30,9 @@ module RoadForest::MediaType
|
|
|
36
30
|
|
|
37
31
|
def template_kinds
|
|
38
32
|
if objects.to_a.length > 1
|
|
39
|
-
%w{
|
|
33
|
+
%w{property-values}
|
|
40
34
|
else
|
|
41
|
-
%w{
|
|
35
|
+
%w{property-value property-values}
|
|
42
36
|
end
|
|
43
37
|
end
|
|
44
38
|
end
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
require 'roadforest/type-handlers/rdfa-writer'
|
|
2
|
+
require 'roadforest/type-handlers/rdfa-writer/document-environment'
|
|
3
|
+
require 'roadforest/type-handlers/rdfa-writer/subject-environment'
|
|
4
|
+
require 'roadforest/type-handlers/rdfa-writer/property-environment'
|
|
5
|
+
require 'roadforest/type-handlers/rdfa-writer/object-environment'
|
|
6
|
+
require 'roadforest/type-handlers/rdfa-writer/environment-decorator'
|
|
7
|
+
require 'haml'
|
|
8
|
+
|
|
9
|
+
module RoadForest::TypeHandlers
|
|
10
|
+
class RDFaWriter
|
|
11
|
+
class TemplateHandler
|
|
12
|
+
attr_accessor :haml_options, :valise
|
|
13
|
+
attr_accessor :resource_name
|
|
14
|
+
attr_writer :style_name, :template_cache
|
|
15
|
+
|
|
16
|
+
def template_cache
|
|
17
|
+
@template_cache ||= ::Tilt::Cache.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def style_name
|
|
21
|
+
@style_name ||= "base"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def templates
|
|
25
|
+
@templates ||= [resource_name, style_name, nil].uniq.map do |name|
|
|
26
|
+
valise.sub_set(["templates", name].compact.join("/"))
|
|
27
|
+
end.inject do |left, right|
|
|
28
|
+
left + right
|
|
29
|
+
end.handle_templates do |config|
|
|
30
|
+
#At some point, should look into using HTML entities to preserve
|
|
31
|
+
#whitespace in XMLLiterals
|
|
32
|
+
config.add_type("haml", { :template_cache => template_cache, :template_options => haml_options || {:ugly => true} })
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def find_template(kinds)
|
|
37
|
+
kind = kinds.shift
|
|
38
|
+
templates.contents(kind)
|
|
39
|
+
rescue Valise::Errors::NotFound
|
|
40
|
+
if kinds.empty?
|
|
41
|
+
raise
|
|
42
|
+
else
|
|
43
|
+
retry
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class RenderEngine
|
|
50
|
+
attr_accessor :top_classes
|
|
51
|
+
|
|
52
|
+
attr_accessor :predicate_order
|
|
53
|
+
|
|
54
|
+
attr_accessor :heading_predicates
|
|
55
|
+
|
|
56
|
+
attr_accessor :prefixes, :base_uri, :lang, :standard_prefixes, :graph, :titles, :doc_title, :graph_name
|
|
57
|
+
attr_accessor :template_handler
|
|
58
|
+
attr_reader :debug
|
|
59
|
+
|
|
60
|
+
attr_reader :decoration_set
|
|
61
|
+
|
|
62
|
+
def initialize(graph, debug=nil)
|
|
63
|
+
@debug = debug
|
|
64
|
+
@graph = graph
|
|
65
|
+
@graph_name = nil
|
|
66
|
+
@decoration_set = DecorationSet.new
|
|
67
|
+
@render_stack = []
|
|
68
|
+
|
|
69
|
+
reset
|
|
70
|
+
|
|
71
|
+
yield self
|
|
72
|
+
|
|
73
|
+
setup
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Reset parser to run again
|
|
77
|
+
def reset
|
|
78
|
+
@debug_indent = 0
|
|
79
|
+
@uri_to_term_or_curie = {}
|
|
80
|
+
@uri_to_prefix = {}
|
|
81
|
+
@references = Hash.new{|h,k| h[k] = 0}
|
|
82
|
+
@prefixes = {}
|
|
83
|
+
@serialized = {}
|
|
84
|
+
@subjects = {}
|
|
85
|
+
@ordered_subjects = []
|
|
86
|
+
@titles = {}
|
|
87
|
+
@doc_title = ""
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def depth
|
|
91
|
+
@debug_indent += 1
|
|
92
|
+
ret = yield
|
|
93
|
+
@debug_indent -= 1
|
|
94
|
+
ret
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def bump_reference(resource)
|
|
98
|
+
@references[resource] += 1
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def ref_count(node)
|
|
102
|
+
@references[node]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def add_debug(message = nil)
|
|
106
|
+
return unless ::RoadForest.debug_io || @debug
|
|
107
|
+
message ||= ""
|
|
108
|
+
message = message + yield if block_given?
|
|
109
|
+
msg = "#{' ' * @debug_indent}#{message}"
|
|
110
|
+
RoadForest::debug(msg)
|
|
111
|
+
@debug << msg.force_encoding("utf-8") if @debug.is_a?(Array)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def setup
|
|
115
|
+
add_debug {"\nserialize setup: graph size: #{@graph.size}"}
|
|
116
|
+
|
|
117
|
+
@base_uri = ::RDF::URI.intern(@base_uri) unless @base_uri.nil? or @base_uri.is_a?(::RDF::URI)
|
|
118
|
+
|
|
119
|
+
preprocess
|
|
120
|
+
|
|
121
|
+
@ordered_subjects = order_subjects
|
|
122
|
+
|
|
123
|
+
# Take title from first subject having a heading predicate
|
|
124
|
+
@doc_title = nil
|
|
125
|
+
heading_predicates.each do |pred|
|
|
126
|
+
@graph.query(:predicate => pred) do |statement|
|
|
127
|
+
titles[statement.subject] ||= statement.object
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
title_subject = @ordered_subjects.detect {|subject| titles[subject]}
|
|
131
|
+
@doc_title = titles[title_subject]
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def preprocess
|
|
135
|
+
[RDF::RDFa::XML_RDFA_CONTEXT, RDF::RDFa::HTML_RDFA_CONTEXT].each do |uri|
|
|
136
|
+
ctx = RDF::RDFa::Context.find(uri)
|
|
137
|
+
ctx.prefixes.each_pair do |k, v|
|
|
138
|
+
@uri_to_prefix[v] = k unless k.to_s == "dcterms"
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
ctx.terms.each_pair do |k, v|
|
|
142
|
+
@uri_to_term_or_curie[v] = k
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
@vocabulary = ctx.vocabulary.to_s if ctx.vocabulary
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Load defined prefixes
|
|
149
|
+
(@prefixes || {}).each_pair do |k, v|
|
|
150
|
+
@uri_to_prefix[v.to_s] = k
|
|
151
|
+
end
|
|
152
|
+
@prefixes = {} # Will define actual used when matched
|
|
153
|
+
|
|
154
|
+
# Process each statement to establish CURIEs and Terms
|
|
155
|
+
@graph.each {|statement| preprocess_statement(statement)}
|
|
156
|
+
add_debug{ "preprocess prefixes: #{@prefixes.inspect}" }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def order_subjects
|
|
160
|
+
seen = {}
|
|
161
|
+
subjects = []
|
|
162
|
+
|
|
163
|
+
# Start with base_uri
|
|
164
|
+
if base_uri && @subjects.keys.include?(base_uri)
|
|
165
|
+
subjects << base_uri
|
|
166
|
+
seen[base_uri] = true
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Add distinguished classes
|
|
170
|
+
top_classes.select do |s|
|
|
171
|
+
!seen.include?(s)
|
|
172
|
+
end.each do |class_uri|
|
|
173
|
+
graph.query(:predicate => RDF.type, :object => class_uri).map {|st| st.subject}.sort.uniq.each do |subject|
|
|
174
|
+
#add_debug {"order_subjects: #{subject.inspect}"}
|
|
175
|
+
subjects << subject
|
|
176
|
+
seen[subject] = true
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Sort subjects by resources over nodes, ref_counts and the subject URI itself
|
|
181
|
+
recursable = @subjects.keys.select do |s|
|
|
182
|
+
!seen.include?(s)
|
|
183
|
+
end.map do |r|
|
|
184
|
+
[r.is_a?(RDF::Node) ? 1 : 0, ref_count(r), r]
|
|
185
|
+
end.sort
|
|
186
|
+
|
|
187
|
+
add_debug {"order_subjects: #{recursable.inspect}"}
|
|
188
|
+
|
|
189
|
+
subjects += recursable.map{|r| r.last}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def order_properties(properties)
|
|
193
|
+
# Make sorted list of properties
|
|
194
|
+
prop_list = []
|
|
195
|
+
|
|
196
|
+
predicate_order.each do |prop|
|
|
197
|
+
next unless properties[prop.to_s]
|
|
198
|
+
prop_list << prop.to_s
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
properties.keys.sort.each do |prop|
|
|
202
|
+
next if prop_list.include?(prop.to_s)
|
|
203
|
+
prop_list << prop.to_s
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
add_debug {"order_properties: #{prop_list.join(', ')}"}
|
|
207
|
+
prop_list
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# Perform any statement preprocessing required. This is used to perform reference counts and determine required prefixes.
|
|
211
|
+
# @param [RDF::Statement] statement
|
|
212
|
+
# @return [ignored]
|
|
213
|
+
def preprocess_statement(statement)
|
|
214
|
+
#add_debug {"preprocess: #{statement.inspect}"}
|
|
215
|
+
return unless statement.context == graph_name
|
|
216
|
+
bump_reference(statement.subject)
|
|
217
|
+
bump_reference(statement.object)
|
|
218
|
+
@subjects[statement.subject] = true
|
|
219
|
+
get_curie(statement.subject)
|
|
220
|
+
get_curie(statement.predicate)
|
|
221
|
+
get_curie(statement.object)
|
|
222
|
+
get_curie(statement.object.datatype) if statement.object.literal? && statement.object.has_datatype?
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def get_curie(resource)
|
|
226
|
+
raise RDF::WriterError, "Getting CURIE for #{resource.inspect}, which must be an RDF value" unless resource.is_a? RDF::Value
|
|
227
|
+
return resource.to_s unless resource.uri?
|
|
228
|
+
|
|
229
|
+
uri = resource.to_s
|
|
230
|
+
|
|
231
|
+
curie =
|
|
232
|
+
case
|
|
233
|
+
when @uri_to_term_or_curie.has_key?(uri)
|
|
234
|
+
add_debug {"get_curie(#{uri}): uri_to_term_or_curie #{@uri_to_term_or_curie[uri].inspect}"}
|
|
235
|
+
return @uri_to_term_or_curie[uri]
|
|
236
|
+
when base_uri && uri.index(base_uri.to_s) == 0
|
|
237
|
+
add_debug {"get_curie(#{uri}): base_uri (#{uri.sub(base_uri.to_s, "")})"}
|
|
238
|
+
uri.sub(base_uri.to_s, "")
|
|
239
|
+
when @vocabulary && uri.index(@vocabulary) == 0
|
|
240
|
+
add_debug {"get_curie(#{uri}): vocabulary"}
|
|
241
|
+
uri.sub(@vocabulary, "")
|
|
242
|
+
when u = @uri_to_prefix.keys.detect {|u| uri.index(u.to_s) == 0}
|
|
243
|
+
add_debug {"get_curie(#{uri}): uri_to_prefix"}
|
|
244
|
+
prefix = @uri_to_prefix[u]
|
|
245
|
+
@prefixes[prefix] = u
|
|
246
|
+
uri.sub(u.to_s, "#{prefix}:")
|
|
247
|
+
when @standard_prefixes && vocab = RDF::Vocabulary.detect {|v| uri.index(v.to_uri.to_s) == 0}
|
|
248
|
+
add_debug {"get_curie(#{uri}): standard_prefixes"}
|
|
249
|
+
prefix = vocab.__name__.to_s.split('::').last.downcase
|
|
250
|
+
@prefixes[prefix] = vocab.to_uri
|
|
251
|
+
uri.sub(vocab.to_uri.to_s, "#{prefix}:")
|
|
252
|
+
else
|
|
253
|
+
add_debug {"get_curie(#{uri}): none"}
|
|
254
|
+
uri
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
add_debug {"get_curie(#{resource}) => #{curie}"}
|
|
258
|
+
|
|
259
|
+
@uri_to_term_or_curie[uri] = curie
|
|
260
|
+
rescue ArgumentError => e
|
|
261
|
+
raise RDF::WriterError, "Invalid URI #{uri.inspect}: #{e.message}"
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def type_of(type, subject)
|
|
265
|
+
# Find appropriate template
|
|
266
|
+
curie = case
|
|
267
|
+
when subject.node?
|
|
268
|
+
subject.to_s if ref_count(subject) > 1
|
|
269
|
+
else
|
|
270
|
+
get_curie(subject)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
typeof = Array(type).map {|r| get_curie(r)}.join(" ")
|
|
274
|
+
typeof = nil if typeof.empty?
|
|
275
|
+
|
|
276
|
+
# Nodes without a curie need a blank @typeof to generate a subject
|
|
277
|
+
typeof ||= "" unless curie
|
|
278
|
+
|
|
279
|
+
add_debug {"subject: #{curie.inspect}, typeof: #{typeof.inspect}" }
|
|
280
|
+
|
|
281
|
+
typeof.freeze
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def find_environment_template(env)
|
|
285
|
+
template_handler.find_template(env.template_kinds)
|
|
286
|
+
rescue Valise::Errors::NotFound
|
|
287
|
+
raise RDF::WriterError, "No template found for #{env.class} in #{template_handler.inspect}"
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def render(context)
|
|
291
|
+
#puts "\n#{__FILE__.sub(/^#{Dir.pwd}/,'')}:#{__LINE__} =>
|
|
292
|
+
##{context.class.inspect}"
|
|
293
|
+
add_debug "render"
|
|
294
|
+
if context.render_checked
|
|
295
|
+
return ""
|
|
296
|
+
end
|
|
297
|
+
template = find_environment_template(context)
|
|
298
|
+
depth do
|
|
299
|
+
add_debug{ "template: #{template.file}" }
|
|
300
|
+
add_debug{ "context: #{context.class.name}"}
|
|
301
|
+
|
|
302
|
+
begin
|
|
303
|
+
@render_stack.push context
|
|
304
|
+
template.render(context) do |item|
|
|
305
|
+
context.yielded(item)
|
|
306
|
+
end.sub(/\n\Z/,'')
|
|
307
|
+
ensure
|
|
308
|
+
@render_stack.pop
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def is_list?(object)
|
|
314
|
+
!(object == RDF.nil || (l = RDF::List.new(object, @graph)).invalid?)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def subject_done(subject)
|
|
318
|
+
@serialized[subject] = true
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def is_done?(subject)
|
|
322
|
+
@serialized.include?(subject)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
def properties_for_subject(subject)
|
|
326
|
+
properties = {}
|
|
327
|
+
@graph.query(:subject => subject, :context => false) do |st|
|
|
328
|
+
key = st.predicate.to_s.freeze
|
|
329
|
+
properties[key] ||= []
|
|
330
|
+
properties[key] << st.object
|
|
331
|
+
end
|
|
332
|
+
properties
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def document_env
|
|
336
|
+
build_env(DocumentEnvironment) do |env|
|
|
337
|
+
env.subject_terms = @ordered_subjects
|
|
338
|
+
env.title = doc_title
|
|
339
|
+
env.prefixes = prefixes
|
|
340
|
+
env.lang = lang
|
|
341
|
+
env.base = base_uri
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def subject_env(subject)
|
|
346
|
+
return unless @subjects.include?(subject)
|
|
347
|
+
properties = properties_for_subject(subject)
|
|
348
|
+
|
|
349
|
+
build_env(SubjectEnvironment) do |env|
|
|
350
|
+
env.base = base_uri
|
|
351
|
+
env.predicate_terms = order_properties(properties)
|
|
352
|
+
env.property_objects = properties
|
|
353
|
+
env.subject = subject
|
|
354
|
+
env.typeof = type_of(properties.delete(RDF.type.to_s), subject)
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def simple_property_env(predicate, objects)
|
|
359
|
+
return nil if objects.to_a.empty?
|
|
360
|
+
|
|
361
|
+
build_env(PropertyEnvironment) do |env|
|
|
362
|
+
env.object_terms = objects
|
|
363
|
+
env.predicate = predicate
|
|
364
|
+
env.inlist = nil
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def build_env(klass)
|
|
369
|
+
env = klass.new(self)
|
|
370
|
+
env.heading_predicates = heading_predicates
|
|
371
|
+
env.lang = lang
|
|
372
|
+
env.parent = @render_stack.last
|
|
373
|
+
yield(env)
|
|
374
|
+
return decoration_set.decoration_for(env)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def object_env(predicate, object)
|
|
378
|
+
subj = subject_env(object)
|
|
379
|
+
unless subj.nil?
|
|
380
|
+
subj.rel = get_curie(predicate)
|
|
381
|
+
return subj
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
env_klass =
|
|
385
|
+
if get_curie(object) == 'rdf:nil'
|
|
386
|
+
NilObjectEnvironment
|
|
387
|
+
elsif object.node?
|
|
388
|
+
NodeObjectEnvironment
|
|
389
|
+
elsif object.uri?
|
|
390
|
+
UriObjectEnvironment
|
|
391
|
+
elsif object.datatype == RDF.XMLLiteral
|
|
392
|
+
XMLLiteralObjectEnvironment
|
|
393
|
+
else
|
|
394
|
+
ObjectEnvironment
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
build_env(env_klass) do |env|
|
|
398
|
+
env.predicate = predicate
|
|
399
|
+
env.object = object
|
|
400
|
+
env.inlist = nil
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
def list_property_envs(predicate, list_objects)
|
|
405
|
+
return list_objects.map do |object|
|
|
406
|
+
# Render each list as multiple properties and set :inlist to true
|
|
407
|
+
list = RDF::List.new(object, @graph)
|
|
408
|
+
list.each_statement {|st| subject_done(st.subject)}
|
|
409
|
+
|
|
410
|
+
add_debug {"list: #{list.inspect} #{list.to_a}"}
|
|
411
|
+
env = simple_property_env(predicate, list.to_a)
|
|
412
|
+
env.inlist = "true"
|
|
413
|
+
env
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
def render_document
|
|
418
|
+
add_debug{ "engine prefixes: #{prefixes.inspect}"}
|
|
419
|
+
env = document_env
|
|
420
|
+
|
|
421
|
+
yield env if block_given?
|
|
422
|
+
|
|
423
|
+
render(env)
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
end
|