Skip to content

Commit 6ba5e02

Browse files
committed
Added a config property to add an additional line between each triple. This improves readability of documents with many definitions.
1 parent 88cad0b commit 6ba5e02

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/iq_rdf/document.rb

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def initialize(default_namespace_uri_prefix = nil, *args)
2525
@document_language = options[:lang]
2626

2727
@nodes = []
28+
@config = {}
2829
end
2930

3031
def namespaces(namespaces)
@@ -39,6 +40,10 @@ def namespaces(namespaces)
3940
self
4041
end
4142

43+
def config(config = {})
44+
@config = config
45+
end
46+
4247
def <<(node)
4348
return if node.nil?
4449
raise ArgumentError, "Node must be an IqRdf::Uri and a Subject!" unless node.is_a?(IqRdf::Uri) and node.is_subject?
@@ -163,6 +168,9 @@ def to_turtle
163168
pref = ";\n" + indent
164169
end
165170
s << ".\n"
171+
if @config[:empty_line_between_triples]
172+
s << "\n"
173+
end
166174
end
167175
s
168176
end

test/turtle_test.rb

+18
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ def test_blank_nodes_with_different_ns
241241
qb:order 1;
242242
eg:cost 2.25
243243
].
244+
rdf
245+
end
246+
247+
def test_config
248+
document = IqRdf::Document.new('http://www.test.de/')
249+
document.config(empty_line_between_triples: true)
250+
251+
document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en)
252+
document << IqRdf::testemann.myCustomNote("Zweites Beispiel", :lang => :de)
253+
254+
assert_equal(<<rdf, document.to_turtle)
255+
@prefix : <http://www.test.de/>.
256+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
257+
258+
:testemann :myCustomNote "This is an example"@en.
259+
260+
:testemann :myCustomNote "Zweites Beispiel"@de.
261+
244262
rdf
245263
end
246264

0 commit comments

Comments
 (0)