Skip to content

Commit

Permalink
Merge pull request #270 from Simaris/269/work_on_reset
Browse files Browse the repository at this point in the history
jekyll-rdf still works after Jekyll reset
  • Loading branch information
white-gecko authored Jun 18, 2019
2 parents a38032a + 2b7bab7 commit 2acad87
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/jekyll/hooks/rdf_page_pointer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
# SOFTWARE.
#

Jekyll::Hooks.register :site, :after_reset do |site|
Jekyll::JekyllRdf::Helper::RdfHelper::reinitialize
end

Jekyll::Hooks.register :documents, :post_init do |page|
if(page.data["rdf_prefix_path"].nil?)
page.data["rdf_prefix_set?"] = false
Expand Down
2 changes: 2 additions & 0 deletions test/cases/filter/test_rdf_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def config

should "return the resource eg:resource" do
Jekyll::JekyllRdf::Helper::RdfHelper::site = Jekyll::Site.new(Jekyll.configuration({}))
Jekyll::JekyllRdf::Helper::RdfHelper::page = PseudoPage.new() # setting site resets these values
Jekyll::JekyllRdf::Helper::RdfHelper::prefixes = prefix_path # setting site resets these values
test_resource = rdf_get("eg:resource")
assert_equal "http://example.org/instance/resource", test_resource.iri
assert (test_resource.site.eql? Jekyll::JekyllRdf::Helper::RdfHelper::site), "The resource should contain the same site as Jekyll::JekyllRdf::Helper::RdfHelper"
Expand Down
4 changes: 4 additions & 0 deletions test/cases/resetSite/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
group :jekyll_plugins do
gem 'jekyll-rdf', :path => '../../../'
end
11 changes: 11 additions & 0 deletions test/cases/resetSite/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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-resource"

2 changes: 2 additions & 0 deletions test/cases/resetSite/_data/Prefixes.pref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PREFIX eg: <http://example.org/instance/>

5 changes: 5 additions & 0 deletions test/cases/resetSite/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@prefix eg: <http://example.org/instance/> .

eg:resource1 eg:predicate eg:object .
eg:resource2 eg:predicate eg:object .

6 changes: 6 additions & 0 deletions test/cases/resetSite/_layouts/default-resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
layout: default
---
<h6>This is a resource</h6> <br/>
{{ page.rdf }}

12 changes: 12 additions & 0 deletions test/cases/resetSite/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
---
<!DOCTYPE html>
<html>
<head></head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4> <br/>
{{content}}
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions test/cases/resetSite/_layouts/exampleInstance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: default
rdf_prefix_path: _data/Prefixes.pref
---
<div class="instance">
<h6> This page is mapped to: </h6>
{{page.rdf}}
</div>
15 changes: 15 additions & 0 deletions test/cases/resetSite/_layouts/person.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: default
rdf_prefix_path: _data/Prefixes.pref
---
<div class="person">
<h6>
name:
</h6>
{{page.rdf | rdf_property: "foaf:name"}}
<br/>
<h6>
age:
</h6>
{{page.rdf | rdf_property: "foaf:age"}}
</div>
6 changes: 6 additions & 0 deletions test/cases/resetSite/reset-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
layout: default
---

<h6>This is a page</h6> <br/>
Test-Page
59 changes: 59 additions & 0 deletions test/cases/resetSite/test_reset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'test_helper'

class TestGeneral < Test::Unit::TestCase
include RSpec::Matchers
include RdfTestUtility
context "Jekyll-Rdf after reinitialization" do
setup do
setup_site_jekyll File.dirname(__FILE__)
end

should "render content completly" do
file = File.read(File.join(@source, "_site/reset-page.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert_equal "<h4>This is made with jekyll-rdf</h4>", content[0]
assert_equal "<h6>This is a page</h6>", content[1]
assert_equal "Test-Page", content[2]
file = File.read(File.join(@source, "_site/resource1.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert_equal "<h4>This is made with jekyll-rdf</h4>", content[0]
assert_equal "<h6>This is a resource</h6>", content[1]
assert_equal "http://example.org/instance/resource1", content[2]
file = File.read(File.join(@source, "_site/resource2.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert_equal "<h4>This is made with jekyll-rdf</h4>", content[0]
assert_equal "<h6>This is a resource</h6>", content[1]
assert_equal "http://example.org/instance/resource2", content[2]
# Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize
@site.process
file = File.read(File.join(@source, "_site/reset-page.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert File.exist?(File.join(@source, "_site/resource1.html")), "resource1.html was in the render list but wasn't rendered after reset"
assert_equal "<h4>This is made with jekyll-rdf</h4>", content[0]
assert_equal "<h6>This is a page</h6>", content[1]
assert_equal "Test-Page", content[2]
file = File.read(File.join(@source, "_site/resource1.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert_equal "<h4>This is made with jekyll-rdf</h4>", content[0]
assert_equal "<h6>This is a resource</h6>", content[1]
assert_equal "http://example.org/instance/resource1", content[2]
file = File.read(File.join(@source, "_site/resource2.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert_equal "<h4>This is made with jekyll-rdf</h4>", content[0]
assert_equal "<h6>This is a resource</h6>", content[1]
assert_equal "http://example.org/instance/resource2", content[2]
end
end
end

0 comments on commit 2acad87

Please sign in to comment.