Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match pages according to their page.url #194

Merged
merged 4 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jekyll/helper/rdf_generator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def create_page(site, resource, mapper)
if(page.complete)
changes = false
site.pages.map!{|old_page|
if (File.join(old_page.dir, old_page.name) == File.join(page.dir, page.name))
if (old_page.url == page.url)
changes||=true
page.assimilate_page(old_page)
page
Expand Down
5 changes: 5 additions & 0 deletions lib/jekyll/helper/rdf_page_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def re_init_as_rdf(resource, mapper)
resource.page = self
resource.site = @site
@site.data['resources'] << resource
@url = resource.page_url
#page_url reflects the url given by the uri of that site
#Jekyll on the other hand renders .html in each url belonging to an html (also converted ones like .md)
@url << ".html" unless (@url.length == 0) || (@url[-1].eql? "/")
@url = "/" + @url unless (@url.length > 0)&&(@url[0].eql? "/") #by default jekyll renders with a leading /
end

def self.prepare_resource resource, mapper
Expand Down
5 changes: 5 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/Bart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Barts Skating page"
---

I really like skating
4 changes: 4 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/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
13 changes: 13 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
baseurl: "/instance"
url: "http://example.org/"
# Build settings

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"

3 changes: 3 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_data/Prefixes.pref
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX eg: <http://example.org/instance/>
7 changes: 7 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix eg: <http://example.org/instance/> .

eg:Bart a foaf:Person .
eg:Bart foaf:age "15"^^xsd:int .
eg:Bart foaf:name "Bart" .
21 changes: 21 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_layouts/bart_layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
layout: default_bart
---

<div class="person">
<h6>
name:
</h6>
{{page.rdf | rdf_property: "foaf:name"}}
<br/>
<h6>
age:
</h6>
{{page.rdf | rdf_property: "foaf:age"}}
</div>

<div>
begin bart content
{{ content }}
end bart content
</div>
16 changes: 16 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---
<!DOCTYPE html>
<html>
<head>
<title>Default: {{ page.title }}</title>
</head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4>
begin default content
{{content}}
end default content
</div>
</body>
</html>
16 changes: 16 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_layouts/default_bart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---
<!DOCTYPE html>
<html>
<head>
<title>{{ page.title }}</title>
</head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4>
begin default_bart content
{{content}}
end default_bart content
</div>
</body>
</html>
21 changes: 21 additions & 0 deletions test/cases/MergeFeatureLayoutRoute/_layouts/person.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
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>

<div>
begin person content
{{content}}
end person content
</div>
6 changes: 6 additions & 0 deletions test/cases/MergeFeaturePageRoute/Bart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "Barts Skating page"
layout: bart_layout
---

I really like skating
4 changes: 4 additions & 0 deletions test/cases/MergeFeaturePageRoute/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/MergeFeaturePageRoute/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
baseurl: "/instance"
url: "http://example.org/"
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"

5 changes: 5 additions & 0 deletions test/cases/MergeFeaturePageRoute/_data/Prefixes.pref
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX eg: <http://example.org/instance/>
7 changes: 7 additions & 0 deletions test/cases/MergeFeaturePageRoute/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix eg: <http://example.org/instance/> .

eg:Bart a foaf:Person .
eg:Bart foaf:age "15"^^xsd:int .
eg:Bart foaf:name "Bart" .
21 changes: 21 additions & 0 deletions test/cases/MergeFeaturePageRoute/_layouts/bart_layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
layout: default_bart
---

<div class="person">
<h6>
name:
</h6>
{{page.rdf | rdf_property: "foaf:name"}}
<br/>
<h6>
age:
</h6>
{{page.rdf | rdf_property: "foaf:age"}}
</div>

<div>
begin bart content
{{ content }}
end bart content
</div>
16 changes: 16 additions & 0 deletions test/cases/MergeFeaturePageRoute/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---
<!DOCTYPE html>
<html>
<head>
<title>Default: {{ page.title }}</title>
</head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4>
begin default content
{{content}}
end default content
</div>
</body>
</html>
16 changes: 16 additions & 0 deletions test/cases/MergeFeaturePageRoute/_layouts/default_bart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---
<!DOCTYPE html>
<html>
<head>
<title>{{ page.title }}</title>
</head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4>
begin default_bart content
{{content}}
end default_bart content
</div>
</body>
</html>
21 changes: 21 additions & 0 deletions test/cases/MergeFeaturePageRoute/_layouts/person.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
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>

<div>
begin person content
{{content}}
end person content
</div>
82 changes: 25 additions & 57 deletions test/test_rdf_main_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,31 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
end
end

context "create_page from rdf_main_generator" do
setup do
@resources_to_templates = {
"http://www.ifi.uio.no/INF3580/simpsons/Homer" => "homer",
"http://placeholder.host.plh/placeholder#Placeholder" => "Placeholder",
"this://should/merge/merge" => "merge",
"this://should/also/merge/merge" => "merge",
"this://should/not/merge/merge" => "nMerge",
"this://should/be/copied/merge/merge" => "nil"
}
@classes_to_templates = {
"http://xmlns.com/foaf/0.1/Person" => "person",
"http://pcai042.informatik.uni-leipzig.de/~dtp16#SpecialPerson" => "SpecialPerson",
"http://pcai042.informatik.uni-leipzig.de/~dtp16#AnotherSpecialPerson" => "AnotherSpecialPerson"
}
@default_template = "default"
res_helper.global_site = true
@resource1 = res_helper.basic_resource("http://www.ifi.uio.no/INF3580/simpsons/Homer")
@resource2 = res_helper.basic_resource("http://www.ifi.uio.no/INF3580/simpsons/Maggie")
@resource3 = res_helper.basic_resource("http://resource3")
res_helper.global_site = false
@mapper = Jekyll::RdfTemplateMapper.new(@resources_to_templates, @classes_to_templates, @default_template, sparql)
@config = Jekyll.configuration(TestHelper::TEST_OPTIONS)
@site = Jekyll::Site.new(@config)
@site.data['resources'] = []
@site.layouts["homer"] = Jekyll::Layout.new(@site, @site.source, "homer.html")
@site.layouts["person"] = Jekyll::Layout.new(@site, @site.source, "person.html")
@site.layouts["default"] = Jekyll::Layout.new(@site, @site.source, "default.html")
@site.layouts["merge"] = Jekyll::Layout.new(@site, File.join(@site.source, "_layouts"), "merge.html")
@site.layouts["merge"].content = "outer part of a merged page \n {{ content }}"
@site.layouts["nMerge"] = Jekyll::Layout.new(@site, File.join(@site.source, "_layouts"), "nMerge.html")
@site.layouts["nMerge"].content = "an unmerged page \n {{ content }}"
@site.layouts["nil"] = Jekyll::Layout.new(@site, File.join(@site.source, "_layouts"), "nil.html")
@site.layouts["nil"].content = "this is nil content"
@site.pages = []
end

should "assimilate already existing pages if they share the same path" do
@site.pages << Jekyll::Page.new(@site, @site.source, "rdfsites/this/should", "merge.html")
@site.pages.last.content = "this is the first normal part"
@site.pages << Jekyll::Page.new(@site, @site.source, "rdfsites/this/should/also", "merge.html")
@site.pages.last.content = "this is the second normal part"
@site.pages << Jekyll::Page.new(@site, @site.source, "rdfsites/this/should/wont", "merge.html")
@site.pages.last.content = "this is the third normal part"
@site.pages << Jekyll::Page.new(@site, @site.source, "rdfsites/this/should/be/copied", "merge.html")
@site.pages.last.content = "this should be the only line in this file"
@site.pages.last.data['layout'] = ""
create_page(@site, Jekyll::JekyllRdf::Drops::RdfResource.new("this://should/merge/merge"), @mapper)
create_page(@site, Jekyll::JekyllRdf::Drops::RdfResource.new("this://should/also/merge/merge"), @mapper)
create_page(@site, Jekyll::JekyllRdf::Drops::RdfResource.new("this://should/not/merge/merge"), @mapper)
create_page(@site, Jekyll::JekyllRdf::Drops::RdfResource.new("this://should/be/copied/merge/merge"), @mapper)
assert (@site.pages.length.eql? 5), "The page count should be 4 it was #{@site.pages.length}"
assert (!!(@site.pages[0].content =~ /outer part of a merged page \n this is the first normal part/)), "content should be:>>>>>\nouter part of a merged page \n this is the first normal part\nbut was:>>>>>\n#{@site.pages[0].content}"
assert (!!(@site.pages[1].content =~ /outer part of a merged page \n this is the second normal part/)), "content should be:>>>>>\nouter part of a merged page \n this is the second normal part\nbut was:>>>>>\n#{@site.pages[1].content}"
assert (!!(@site.pages[2].content =~ /this is the third normal part/)), "content should be:>>>>>\nthis is the third normal part\nbut was:>>>>>\n#{@site.pages[2].content}"
assert (!!(@site.pages[4].content =~ /an unmerged page/)), "content should be:>>>>>\nan unmerged page\nbut was:>>>>>\n#{@site.pages[4].content}"
assert (!!(@site.pages[3].content =~ /this should be the only line in this file/)), "This page should only contain >>>this should be the only line in this file<<<\ncontained: #{@site.pages[3].content}"
context "the Merge Feature of jekyll-rdf" do
should "create a page that takes the layout defined in the page" do
@source = File.join(File.dirname(__FILE__), "cases/MergeFeaturePageRoute")
config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")}))
site = Jekyll::Site.new(config)
site.process

s = File.read(File.join(@source,"_site/Bart.html"))
assert (s.include? '<title>Barts Skating page</title>'), "does not contain the right title"
assert (s.include? 'begin bart content'), "does not contain the right template"
assert (s.include? 'I really like skating'), "does not contain the core page"
assert (!(s.include? 'begin person content')), "does contain the wrong template"
end

should "create a page that uses the layout of the resource if the page does not have a layout" do
@source = File.join(File.dirname(__FILE__), "cases/MergeFeatureLayoutRoute")
config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")}))
site = Jekyll::Site.new(config)
site.process

s = File.read(File.join(@source,"_site/Bart.html"))
assert (s.include? '<title>Default: Barts Skating page</title>'), "does not contain the right title"
assert (!(s.include? 'begin bart content')), "does contain the wrong template"
assert (s.include? 'I really like skating'), "does not contain the core page"
assert (s.include? 'begin person content'), "does not contain the right template"
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/test_rdf_template_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
graph = RDF::Graph.load(File.join(TestHelper::TEST_OPTIONS['source'], TestHelper::TEST_OPTIONS['jekyll_rdf']['path']))
sparql = SPARQL::Client.new(graph)
res_helper = ResourceHelper.new(sparql)
Jekyll::JekyllRdf::Helper::RdfHelper::sparql = sparql
context "the class extraction" do
should "extract classes from the given source" do
answer = search_for_classes(sparql)
Expand Down Expand Up @@ -85,6 +86,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
"http://pcai042.informatik.uni-leipzig.de/~dtp16#AnotherSpecialPerson" => "AnotherSpecialPerson"
}
default_template = "default"
Jekyll::JekyllRdf::Helper::RdfHelper::sparql = sparql
@mapper = Jekyll::RdfTemplateMapper.new(resources_to_templates, classes_to_templates, default_template, sparql)
end

Expand Down