diff --git a/lib/jekyll/drops/rdf_literal.rb b/lib/jekyll/drops/rdf_literal.rb index 06b4a69e..457a6c84 100644 --- a/lib/jekyll/drops/rdf_literal.rb +++ b/lib/jekyll/drops/rdf_literal.rb @@ -44,7 +44,7 @@ def literal # rdf literals as well # source: https://github.com/eccenca/jekyll-rdf/commit/704dd98c5e457a81e97fcd011562f1f39fc3f813 # - def to_liquid + def to_s # Convert scientific notation term_str = term.to_s @@ -55,6 +55,17 @@ def to_liquid return term.to_s end + # allows filters like plus/subtract to work + def to_number + obj = to_s + #ripped from https://github.com/Shopify/liquid/blob/8dcc3191281478c4ba544d3c507fdb99aa512f75/lib/liquid/utils.rb + (obj.strip =~ /\A-?\d+\.\d+\z/) ? BigDecimal(obj) : obj.to_i + end + + # allows filters like date to work + def strftime format + Time.parse(to_s).strftime(format) + end end end end diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 0c7d853f..1c6b637a 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -57,12 +57,11 @@ def request_class_template resource min_template_lock = lock - 1 min_class = class_resource end - class_resource.find_direct_superclasses.each{ |uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) if(!@classResources[uri].template.nil?) # do not search in paths you previously found if @classResources[uri].base - if(!min_class.nil? && min_template_lock == lock) #min_class could contain a previously found class with equal distance + if(!min_class.nil? &&( min_template_lock == lock || (min_template_lock == -1 && lock == 0))) #min_class could contain a previously found class with equal distance alternatives.push @classResources[uri] unless min_class.eql? @classResources[uri] else min_template_lock = lock @@ -98,7 +97,8 @@ def request_class_template resource # def extract_template class_resource, hash_str class_resource.propagate_template(class_resource.distance) - return (@template_cache[hash_str] = class_resource.get_path_root.template) + return (@template_cache[hash_str] = class_resource.get_path_root.template) unless(class_resource.get_path_root.template.nil?) #toDo: remove the unless-part + the default under it in another pr + return class_resource.template #toDo find_highlevel_inheritance: "@classResources[uri].path = resource" causes get_path_root to go to far or propagate_template does not work correctly? end ## @@ -107,17 +107,18 @@ def extract_template class_resource, hash_str # +resource+ is the original input of request_class_template. # def find_highlevel_inheritance current_best, class_list, resource #check at the end of the search for direct inheritance on highest level - class_list.each{|resource| + all_solutions = class_list.dup.push(current_best) + all_solutions.each{|resource| resource.find_direct_superclasses.each{|uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) @classResources[uri].path = resource } if resource.base } # this is valnuable to cyclic inheritance - while(class_list.include?(current_best.path)) - slice = class_list.index(current_best) + while(all_solutions.include?(current_best.path)) + slice = all_solutions.index(current_best) # parent alternatives are no real alternatives - class_list.slice!(slice) unless slice.nil? + all_solutions.slice!(slice) unless slice.nil? current_best = current_best.path end return consistence_templates(current_best, class_list, resource) unless class_list.empty? diff --git a/test/cases/classHierarchy/_config.yml b/test/cases/classHierarchy/_config.yml index bfdf280d..58bb3041 100644 --- a/test/cases/classHierarchy/_config.yml +++ b/test/cases/classHierarchy/_config.yml @@ -4,9 +4,12 @@ plugins: - jekyll-rdf jekyll_rdf: path: "_data/knowledge-base.ttl" - restriction: "SELECT ?resourceUri WHERE {?resourceUri ?o}" + restriction: "SELECT ?resourceUri WHERE {?resourceUri }" class_template_mappings: "http://animals.org/classification/landBorn": "landBorn" "http://animals.org/classification/layingEggs": "layingEggs" "http://animals.org/classification/foodFromWater": "foodFromWater" "http://animals.org/classification/breathingAir": "breathingAir" + "http://animals.org/classification/PseudoClass31": "PseudoClass03" + "http://animals.org/classification/PseudoClass32": "PseudoClass30" + "http://animals.org/classification/TestClass" : "PseudoClass03" diff --git a/test/cases/classHierarchy/_data/knowledge-base.ttl b/test/cases/classHierarchy/_data/knowledge-base.ttl index 2693f802..5ba53139 100644 --- a/test/cases/classHierarchy/_data/knowledge-base.ttl +++ b/test/cases/classHierarchy/_data/knowledge-base.ttl @@ -1,6 +1,7 @@ @prefix rdfs: . @prefix an: . @prefix ani: . +@prefix jrdf: . an:landBorn rdfs:subClassOf an:animal . an:birds rdfs:subClassOf an:animal . @@ -30,3 +31,32 @@ ani:Fish a an:waterHunting . ani:Fish a an:waterFiltering . ani:Whale a an:breathingAir . ani:Whale a an:foodFromWater . + +ani:ape a jrdf:render . +ani:Lizard a jrdf:render . +ani:Penguins a jrdf:render . +ani:Fish a jrdf:render . +ani:Whale a jrdf:render . + +an:PseudoClass11 rdfs:subClassOf an:PseudoClass21 . +an:PseudoClass21 rdfs:subClassOf an:PseudoClass31 . +an:PseudoClass12 rdfs:subClassOf an:PseudoClass22 . +an:PseudoClass22 rdfs:subClassOf an:PseudoClass32 . +an:PseudoMergeClass rdfs:subClassOf an:PseudoClass11 . +an:PseudoMergeClass rdfs:subClassOf an:PseudoClass12 . +an:PseudoClass32 rdfs:subClassOf an:PseudoClass31 . +an:PseudoDirectClass rdfs:subClassOf an:PseudoClass31 . +an:PseudoDirectClass rdfs:subClassOf an:PseudoClass32 . + +ani:PseudoInstance1 a an:PseudoClass11 . +ani:PseudoInstance2 a an:PseudoClass12 . +ani:PseudoTestInstance a an:PseudoMergeClass . +ani:PseudoTestDirectInstance a an:PseudoDirectClass . + +an:priorSplit rdfs:subClassOf an:Split1 . +an:priorSplit rdfs:subClassOf an:Split2 . +an:Split1 rdfs:subClassOf an:afterSplit . +an:Split2 rdfs:subClassOf an:afterSplit . +an:afterSplit rdfs:subClassOf an:TestClass . + +ani:PseudoInstance3 a an:priorSplit . diff --git a/test/cases/classHierarchy/_layouts/PseudoClass03.html b/test/cases/classHierarchy/_layouts/PseudoClass03.html new file mode 100644 index 00000000..2b6e5e83 --- /dev/null +++ b/test/cases/classHierarchy/_layouts/PseudoClass03.html @@ -0,0 +1,14 @@ +--- +--- + + + + + + + +
{{page.rdf}}
+ PseudoClass03 +
+ + diff --git a/test/cases/classHierarchy/_layouts/PseudoClass30.html b/test/cases/classHierarchy/_layouts/PseudoClass30.html new file mode 100644 index 00000000..945964ce --- /dev/null +++ b/test/cases/classHierarchy/_layouts/PseudoClass30.html @@ -0,0 +1,14 @@ +--- +--- + + + + + + + +
{{page.rdf}}
+ PseudoClass30 +
+ + diff --git a/test/cases/classHierarchy/test_class_hierarchy.rb b/test/cases/classHierarchy/test_class_hierarchy.rb index c08840b6..9d1eb395 100644 --- a/test/cases/classHierarchy/test_class_hierarchy.rb +++ b/test/cases/classHierarchy/test_class_hierarchy.rb @@ -53,6 +53,16 @@ class TestClassHierarchy < Test::Unit::TestCase assert Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*Penguins.*/)}, "This warning should have been thrown >>>Warning: multiple possible templates for resources http://animals.org/instance/Penguins Possible Templates: foodFromWater, layingEggs<<<" assert !Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*Fish.*/)}, "This warning should not have been thrown >>>Warning: multiple possible templates for resources http://animals.org/instance/Fish Possible Templates: ***<<<" + + config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) + mapper = Jekyll::RdfTemplateMapper.new(config["jekyll_rdf"]['instance_template_mappings'], config["jekyll_rdf"]['class_template_mappings'], config["jekyll_rdf"]['default_template']) + + assert_equal "PseudoClass30", mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoTestDirectInstance"))) + mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoInstance1"))) + mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoInstance2"))) + test = mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoTestInstance"))) + assert (("PseudoClass30".eql? test) || ("PseudoClass03".eql? test)), "The mapper should have returned PseudoClass03 or PseudoClass30, but returned: #{test}" + assert_equal "PseudoClass03", mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoInstance3"))) end end end diff --git a/test/cases/debugTools/Gemfile b/test/cases/debugTools/Gemfile new file mode 100644 index 00000000..895226d4 --- /dev/null +++ b/test/cases/debugTools/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', '>= 3.0.0.a' #, :path => '../../../' +end diff --git a/test/cases/debugTools/_config.yml b/test/cases/debugTools/_config.yml new file mode 100644 index 00000000..a53d96bf --- /dev/null +++ b/test/cases/debugTools/_config.yml @@ -0,0 +1,14 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: "default" + class_template_mappings: + "http://xmlns.com/foaf/0.1/Person": "person" + instance_template_mappings: + "http://example.org/instance/resource": "exampleInstance" diff --git a/test/cases/debugTools/_data/Prefixes.pref b/test/cases/debugTools/_data/Prefixes.pref new file mode 100644 index 00000000..f59c9317 --- /dev/null +++ b/test/cases/debugTools/_data/Prefixes.pref @@ -0,0 +1,5 @@ +PREFIX rdf: +PREFIX rdfs: +PREFIX xsd: +PREFIX foaf: +PREFIX eg: diff --git a/test/cases/debugTools/_data/knowledge-base.ttl b/test/cases/debugTools/_data/knowledge-base.ttl new file mode 100644 index 00000000..9eede4ae --- /dev/null +++ b/test/cases/debugTools/_data/knowledge-base.ttl @@ -0,0 +1,10 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix foaf: . +@prefix eg: . + +eg:resource eg:predicate eg:object . +eg:person a foaf:Person . +eg:person foaf:age "28"^^xsd:int . +eg:person foaf:name "Jeanne Doe" . diff --git a/test/cases/debugTools/_layouts/default.html b/test/cases/debugTools/_layouts/default.html new file mode 100644 index 00000000..96137a3e --- /dev/null +++ b/test/cases/debugTools/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf

+ {{content}} +
+ + diff --git a/test/cases/debugTools/_layouts/exampleInstance.html b/test/cases/debugTools/_layouts/exampleInstance.html new file mode 100644 index 00000000..655a2ea8 --- /dev/null +++ b/test/cases/debugTools/_layouts/exampleInstance.html @@ -0,0 +1,8 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
This page is mapped to:
+ {{page.rdf}} +
diff --git a/test/cases/debugTools/_layouts/person.html b/test/cases/debugTools/_layouts/person.html new file mode 100644 index 00000000..30e3bf3b --- /dev/null +++ b/test/cases/debugTools/_layouts/person.html @@ -0,0 +1,15 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
+ name: +
+ {{page.rdf | rdf_property: "foaf:name"}} +
+
+ age: +
+ {{page.rdf | rdf_property: "foaf:age"}} +
diff --git a/test/cases/debugTools/debug.html b/test/cases/debugTools/debug.html new file mode 100644 index 00000000..d79aef9b --- /dev/null +++ b/test/cases/debugTools/debug.html @@ -0,0 +1,18 @@ +--- +--- + + + Debug Messages + + + + +
+ {%- assign message = "Info message" | rdf_debug_message: "info" -%} + {%- assign message = "Warn message" | rdf_debug_message: "warn" -%} + {%- assign message = "Error message" | rdf_debug_message: "error" -%} + {%- assign message = "Debug message" | rdf_debug_message: "debug" -%} + {%- assign message = "message" | rdf_debug_message: "none" -%} +
+ + diff --git a/test/cases/debugTools/test_debug.rb b/test/cases/debugTools/test_debug.rb new file mode 100644 index 00000000..e39097be --- /dev/null +++ b/test/cases/debugTools/test_debug.rb @@ -0,0 +1,25 @@ +class TestPages < Test::Unit::TestCase + include RdfTestUtility + context "Jekyll logger" do + setup do + Jekyll.logger.log_level = :debug + old_err_out = $stderr + old_std_out = $stdout + dummy_out = StringIO.new + $stderr = dummy_out + $stdout = dummy_out + setup_jekyll File.dirname(__FILE__) + $stderr = old_err_out + $stdout = old_std_out + Jekyll.logger.log_level = :error + end + + should "contain messages" do + assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Info message.*/)}), "Jekyll.logger should contain message: >>>Info message<<<" + assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Warn message.*/)}), "Jekyll.logger should contain message: >>>Warn message<<<" + assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Error message.*/)}), "Jekyll.logger should contain message: >>>Error message<<<" + assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Debug message.*/)}), "Jekyll.logger should contain message: >>>Debug message<<<" + assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*NoLevel: message.*/)}), "Jekyll.logger should contain message: >>>NoLevel: message<<<" + end + end +end diff --git a/test/cases/generalTest/_data/knowledge-base.ttl b/test/cases/generalTest/_data/knowledge-base.ttl index b7c12286..e2b114cc 100644 --- a/test/cases/generalTest/_data/knowledge-base.ttl +++ b/test/cases/generalTest/_data/knowledge-base.ttl @@ -4,6 +4,8 @@ @prefix foaf: . eg:resource eg:predicate eg:object . +eg:subject eg:resource "label"@en . +eg:subject eg:predicate eg:resource . eg:person a foaf:Person . eg:person foaf:age "28"^^xsd:int . eg:person foaf:name "Jeanne Doe" . diff --git a/test/cases/generalTest/_layouts/exampleInstance.html b/test/cases/generalTest/_layouts/exampleInstance.html index 655a2ea8..f3f93c0b 100644 --- a/test/cases/generalTest/_layouts/exampleInstance.html +++ b/test/cases/generalTest/_layouts/exampleInstance.html @@ -1,8 +1,21 @@ --- -layout: default rdf_prefix_path: _data/Prefixes.pref --- -
-
This page is mapped to:
- {{page.rdf}} -
+ + + + +
+
This page is mapped to:

+ {{ page.rdf }}
+
Statements

+ {%- for statement in page.rdf.statements -%} + {{ statement.subject }}--{{ statement.predicate }}--{{ statement.object }}
+ {%- endfor -%} + {%- assign lit = "eg:subject" | rdf_property: "eg:resource" -%} + {{ lit }}
+ {%- assign liter = lit.literal -%} + {{ liter }}
+
+ + diff --git a/test/cases/generalTest/test_general.rb b/test/cases/generalTest/test_general.rb index 371f5e87..86c341d8 100644 --- a/test/cases/generalTest/test_general.rb +++ b/test/cases/generalTest/test_general.rb @@ -49,5 +49,15 @@ class TestGeneral < Test::Unit::TestCase assert "
Prefix rdfs:Container
".eql?(content[4]), "Headline should be
Prefix rdf:type
\nIt was: #{content[4]}" assert "http://www.w3.org/2000/01/rdf-schema#Container".eql?(content[5]), "This line should be >>>http://www.w3.org/2000/01/rdf-schema#Container<<< \nIt was :#{content[5]}" end + + should "render statements" do + file = File.read(File.join(@source, "_site/resource.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert (content.include? "http://example.org/instance/resource--http://example.org/instance/predicate--http://example.org/instance/object"), "statement http://example.org/instance/resource--http://example.org/instance/predicate--http://example.org/instance/object was not rendered" + assert (content.include? "http://example.org/instance/subject--http://example.org/instance/resource--label"), "statement http://example.org/instance/subject--http://example.org/instance/resource--label was not rendered" + assert (content.include? "http://example.org/instance/subject--http://example.org/instance/predicate--http://example.org/instance/resource"), "statement http://example.org/instance/subject--http://example.org/instance/predicate--http://example.org/instance/resource was not rendered" + end end end diff --git a/test/cases/includeAll/Gemfile b/test/cases/includeAll/Gemfile new file mode 100644 index 00000000..2cbd50ec --- /dev/null +++ b/test/cases/includeAll/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end + diff --git a/test/cases/includeAll/_config.yml b/test/cases/includeAll/_config.yml new file mode 100644 index 00000000..e9d1c2d8 --- /dev/null +++ b/test/cases/includeAll/_config.yml @@ -0,0 +1,10 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +plugins: +- jekyll-rdf +jekyll_rdf: + baseiri: "http://example.org/instance" + path: "_data/knowledge-base.ttl" + include_blank: true + default_template: "default" diff --git a/test/cases/includeAll/_data/Prefixes.pref b/test/cases/includeAll/_data/Prefixes.pref new file mode 100644 index 00000000..cd1928d9 --- /dev/null +++ b/test/cases/includeAll/_data/Prefixes.pref @@ -0,0 +1,2 @@ +PREFIX eg: + diff --git a/test/cases/includeAll/_data/knowledge-base.ttl b/test/cases/includeAll/_data/knowledge-base.ttl new file mode 100644 index 00000000..f6914f59 --- /dev/null +++ b/test/cases/includeAll/_data/knowledge-base.ttl @@ -0,0 +1,3 @@ +@prefix eg: . + +_:resource eg:predicate eg:object . diff --git a/test/cases/includeAll/_layouts/default.html b/test/cases/includeAll/_layouts/default.html new file mode 100644 index 00000000..96137a3e --- /dev/null +++ b/test/cases/includeAll/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf

+ {{content}} +
+ + diff --git a/test/cases/includeAll/_layouts/exampleInstance.html b/test/cases/includeAll/_layouts/exampleInstance.html new file mode 100644 index 00000000..655a2ea8 --- /dev/null +++ b/test/cases/includeAll/_layouts/exampleInstance.html @@ -0,0 +1,8 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
This page is mapped to:
+ {{page.rdf}} +
diff --git a/test/cases/includeAll/_layouts/person.html b/test/cases/includeAll/_layouts/person.html new file mode 100644 index 00000000..30e3bf3b --- /dev/null +++ b/test/cases/includeAll/_layouts/person.html @@ -0,0 +1,15 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
+ name: +
+ {{page.rdf | rdf_property: "foaf:name"}} +
+
+ age: +
+ {{page.rdf | rdf_property: "foaf:age"}} +
diff --git a/test/cases/includeAll/test_all.rb b/test/cases/includeAll/test_all.rb new file mode 100644 index 00000000..10931967 --- /dev/null +++ b/test/cases/includeAll/test_all.rb @@ -0,0 +1,15 @@ +class TestGeneral < Test::Unit::TestCase + include RSpec::Matchers + include RdfTestUtility + context "Jekyll-Rdf" do + setup do + setup_jekyll File.dirname(__FILE__) + end + + should "render all resources, including blanknodes" do + assert File.exist?(File.join(@source, "_site/predicate.html")), "Jekyll-Rdf did not render _site/predicate.html" + assert File.exist?(File.join(@source, "_site/object.html")), "Jekyll-Rdf did not render _site/object.html" + assert File.exist?(File.join(@source, "_site/rdfsites/blanknode/blanknode_resource/index.html")), "Jekyll-Rdf did not render _site/rdfsites/blanknode/blanknode_resource/index.html" + end + end +end diff --git a/test/cases/prefixError/Gemfile b/test/cases/prefixError/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/prefixError/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/prefixError/_config.yml b/test/cases/prefixError/_config.yml new file mode 100644 index 00000000..f0ce5e39 --- /dev/null +++ b/test/cases/prefixError/_config.yml @@ -0,0 +1,10 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: prefixError + diff --git a/test/cases/prefixError/_data/knowledge-base.ttl b/test/cases/prefixError/_data/knowledge-base.ttl new file mode 100644 index 00000000..56932c1f --- /dev/null +++ b/test/cases/prefixError/_data/knowledge-base.ttl @@ -0,0 +1 @@ + . diff --git a/test/cases/prefixError/_layouts/prefixError.html b/test/cases/prefixError/_layouts/prefixError.html new file mode 100644 index 00000000..6042609d --- /dev/null +++ b/test/cases/prefixError/_layouts/prefixError.html @@ -0,0 +1,13 @@ +--- +rdf_prefix_path: _data/does_not_exist.pref +--- + + + TODO supply a title + + + + +
TODO write content
+ + diff --git a/test/cases/prefixError/test_prefix_error.rb b/test/cases/prefixError/test_prefix_error.rb new file mode 100644 index 00000000..7960cc82 --- /dev/null +++ b/test/cases/prefixError/test_prefix_error.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class TestPrefixes < Test::Unit::TestCase + context "load_prefixes form RdfPageHelper" do + include RdfTestUtility + should "stop Jekyll if an specified prefix file is not found" do + test = false + TestHelper.setErrOutput + begin + setup_jekyll File.dirname(__FILE__) + rescue Errno::ENOENT + test = true + end + TestHelper.resetErrOutput + assert test, "Jekyll should have been stopped with Errno::ENOENT" + end + end +end diff --git a/test/cases/prefixes/PrefixDemo2.html b/test/cases/prefixes/PrefixDemo2.html new file mode 100644 index 00000000..7c3df022 --- /dev/null +++ b/test/cases/prefixes/PrefixDemo2.html @@ -0,0 +1,22 @@ +--- +layout: ontology +--- + + + + + +
+ {%- assign res = "eg:_" | rdf_get -%} + eg: {{res}}
+ {%- assign res = "rdf:_" | rdf_get -%} + rdf: {{res}}
+ {%- assign res = "rdfs:_" | rdf_get -%} + rdfs: {{res}}
+ {%- assign res = "xsd:_" | rdf_get -%} + xsd: {{res}}
+ {%- assign res = "foaf:_" | rdf_get -%} + foaf: {{res}} +
+ + diff --git a/test/cases/prefixes/_config.yml b/test/cases/prefixes/_config.yml index 9b0d44e6..d454efb6 100644 --- a/test/cases/prefixes/_config.yml +++ b/test/cases/prefixes/_config.yml @@ -6,4 +6,5 @@ plugins: jekyll_rdf: path: "_data/knowledge-base.ttl" restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" - + default_template: ontology + \ No newline at end of file diff --git a/test/cases/prefixes/_data/knowledge-base.ttl b/test/cases/prefixes/_data/knowledge-base.ttl index 8b137891..8d8addc5 100644 --- a/test/cases/prefixes/_data/knowledge-base.ttl +++ b/test/cases/prefixes/_data/knowledge-base.ttl @@ -1 +1 @@ - + . diff --git a/test/cases/prefixes/_layouts/default.html b/test/cases/prefixes/_layouts/default.html new file mode 100644 index 00000000..f1e03467 --- /dev/null +++ b/test/cases/prefixes/_layouts/default.html @@ -0,0 +1,5 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- +{{content}} + diff --git a/test/cases/prefixes/_layouts/ontology.html b/test/cases/prefixes/_layouts/ontology.html new file mode 100644 index 00000000..c30e60ca --- /dev/null +++ b/test/cases/prefixes/_layouts/ontology.html @@ -0,0 +1,5 @@ +--- +layout: default +--- +{{content}} + diff --git a/test/cases/prefixes/demo.md b/test/cases/prefixes/demo.md new file mode 100644 index 00000000..5797179c --- /dev/null +++ b/test/cases/prefixes/demo.md @@ -0,0 +1,3 @@ +--- +layout: ontology +--- diff --git a/test/cases/prefixes/index.html b/test/cases/prefixes/index.html new file mode 100644 index 00000000..2c074035 --- /dev/null +++ b/test/cases/prefixes/index.html @@ -0,0 +1,13 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- + + + TODO supply a title + + + + +
TODO write content
+ + diff --git a/test/cases/prefixes/test_prefixes.rb b/test/cases/prefixes/test_prefixes.rb index ba394b17..15a26714 100644 --- a/test/cases/prefixes/test_prefixes.rb +++ b/test/cases/prefixes/test_prefixes.rb @@ -3,9 +3,11 @@ class TestPrefixes < Test::Unit::TestCase context "load_prefixes form RdfPageHelper" do include RdfTestUtility - should "should map prefixes from the file given through rdf_prefix_path in target templates frontmatter" do + setup do setup_jekyll File.dirname(__FILE__) + end + should "should map prefixes from the file given through rdf_prefix_path in target templates frontmatter" do content = [] file = File.read(File.join(@source, "_site/PrefixDemo.html")) content = file[/\(.|\s)*\<\/div\>/][22..-7].strip.split("
").map do |entry| @@ -18,5 +20,19 @@ class TestPrefixes < Test::Unit::TestCase assert_equal "xsd: http://www.w3.org/2001/XMLSchema#_", content[3] assert_equal "foaf: http://xmlns.com/foaf/0.1/_", content[4] end + + should "should map prefixes from the file given through rdf_prefix_path in frontmatters of the entire layout hierarchy" do + content = [] + file = File.read(File.join(@source, "_site/PrefixDemo2.html")) + content = file[/\(.|\s)*\<\/div\>/][22..-7].strip.split("
").map do |entry| + entry.strip + end + + assert_equal "eg: http://example.org/instance/_", content[0] + assert_equal "rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#_", content[1] + assert_equal "rdfs: http://www.w3.org/2000/01/rdf-schema#_", content[2] + assert_equal "xsd: http://www.w3.org/2001/XMLSchema#_", content[3] + assert_equal "foaf: http://xmlns.com/foaf/0.1/_", content[4] + end end end diff --git a/test/cases/prefixesInPosts/_posts/2019-02-13-Blogpost.md b/test/cases/prefixesInPosts/_posts/2019-02-13-Blogpost.md new file mode 100644 index 00000000..0f97cdd3 --- /dev/null +++ b/test/cases/prefixesInPosts/_posts/2019-02-13-Blogpost.md @@ -0,0 +1,6 @@ +--- +layout: post +rdf_prefix_path: _data/Prefixes.pref +--- + +This is a Blogpost diff --git a/test/cases/remoteFaultyConfig/Gemfile b/test/cases/remoteFaultyConfig/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/remoteFaultyConfig/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/remoteFaultyConfig/_config.yml b/test/cases/remoteFaultyConfig/_config.yml new file mode 100644 index 00000000..9a541b3e --- /dev/null +++ b/test/cases/remoteFaultyConfig/_config.yml @@ -0,0 +1,9 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + baseiri: "http://example.org/instance" + diff --git a/test/cases/remoteFaultyConfig/test_faulty_config.rb b/test/cases/remoteFaultyConfig/test_faulty_config.rb new file mode 100644 index 00000000..c34847fe --- /dev/null +++ b/test/cases/remoteFaultyConfig/test_faulty_config.rb @@ -0,0 +1,40 @@ +require 'test_helper' + +class TestFaultyConfig < Test::Unit::TestCase + context "Jekyll-Rdf" do + include RdfTestUtility + should "step out of the rendering process if no source-file was provided" do + @source = File.dirname(__FILE__) + yaml = YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")}) + yaml["jekyll_rdf"] = yaml["jekyll_rdf"].delete_if {|key, value| + key.eql? "remote" + } + config = Jekyll.configuration(yaml) + site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + TestHelper.setErrOutput + site.process + TestHelper.resetErrOutput + assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*No sparql endpoint defined. Jumping out of jekyll-rdf processing.*/)}), "" + end + + should "throw an ArgumentError if the key remote is specified without a remote endpoint" do + @source = File.dirname(__FILE__) + yaml = YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")}) + yaml["jekyll_rdf"] = yaml["jekyll_rdf"].merge({"remote" => {}}) + config = Jekyll.configuration(yaml) + site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + TestHelper.setErrOutput + test = false + begin + site.process + rescue ArgumentError + test = true + end + assert test, "an ArgumentError should have been thrown, since {remote => {}} is specified" + TestHelper.resetErrOutput + end + end +end + diff --git a/test/cases/types/_data/knowledge-base.ttl b/test/cases/types/_data/knowledge-base.ttl index fa502ba4..58b1ed27 100644 --- a/test/cases/types/_data/knowledge-base.ttl +++ b/test/cases/types/_data/knowledge-base.ttl @@ -1,5 +1,10 @@ @prefix eg: . +@prefix xsd: . eg:types eg:value1 "28.07.2018"^^eg:replace . eg:types eg:value2 "detrever"^^eg:revert . eg:types eg:value3 "this was all lower case"^^eg:uppercase . +eg:types eg:value4 "1"^^xsd:boolean . +eg:types eg:value5 "1.0"^^xsd:decimal . +eg:types eg:value6 "12"^^xsd:integer . +eg:types eg:value7 "1.0E5"^^xsd:double . diff --git a/test/cases/types/_layouts/types.html b/test/cases/types/_layouts/types.html index cc6f9bc9..dd51450e 100644 --- a/test/cases/types/_layouts/types.html +++ b/test/cases/types/_layouts/types.html @@ -12,12 +12,24 @@ {%- assign replace = page.rdf | rdf_property: "" -%} {%- assign revert = page.rdf | rdf_property: "" -%} {%- assign upperCase = page.rdf | rdf_property: "" -%} + {%- assign bool = page.rdf | rdf_property: "" -%} + {%- assign decimal = page.rdf | rdf_property: "" -%} + {%- assign integer = page.rdf | rdf_property: "" -%} + {%- assign double = page.rdf | rdf_property: "" -%}
Replace

{{replace}}
Revert

{{revert}}
Upper Case

- {{upperCase}} + {{upperCase}}
+
Boolean

+ {{bool}}
+
Decimal

+ {{decimal}}
+
Integer

+ {{integer}}
+
Double

+ {{double}}
diff --git a/test/cases/types/test_types.rb b/test/cases/types/test_types.rb index b46b7ec4..1de5bfab 100644 --- a/test/cases/types/test_types.rb +++ b/test/cases/types/test_types.rb @@ -84,6 +84,15 @@ def self.=== other assert_equal "28--07--2018", content[1] assert_equal "reverted", content[3] assert_equal "THIS WAS ALL LOWER CASE", content[5] + assert_equal "false", content[7] + assert_equal "1.0", content[9] + assert_equal "12", content[11] + assert_equal "100000", content[13] + + assert_equal "http://www.w3.org/2001/XMLSchema#boolean", Jekyll::JekyllRdf::Types::XsdBoolean.to_s + assert_equal "http://www.w3.org/2001/XMLSchema#decimal", Jekyll::JekyllRdf::Types::XsdDecimal.to_s + assert_equal "http://www.w3.org/2001/XMLSchema#integer", Jekyll::JekyllRdf::Types::XsdInteger.to_s + assert_equal "http://www.w3.org/2001/XMLSchema#double", Jekyll::JekyllRdf::Types::XsdDouble.to_s end end end