Skip to content

Commit

Permalink
Merge pull request #177 from Simaris/168/make_RdfPage_and_JekyllPage_…
Browse files Browse the repository at this point in the history
…same

Combine original Jekyll pages and Jekyll-RDF pages
  • Loading branch information
white-gecko authored Jul 17, 2018
2 parents e20874d + 2532a8f commit 285efc4
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 125 deletions.
1 change: 0 additions & 1 deletion lib/jekyll-rdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@

Liquid::Template.register_filter(Jekyll::JekyllRdf::Filter)
require 'jekyll/rdf_main_generator'
require 'jekyll/rdf_page_data'
require 'jekyll/rdf_template_mapper'
2 changes: 1 addition & 1 deletion lib/jekyll/drops/rdf_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RdfResource < RdfTerm
attr_accessor :site

##
# The Jekyll::RdfPageData of this Jekyll::JekyllRdf::Drops::RdfResource
# The Jekyll::Page of this Jekyll::JekyllRdf::Drops::RdfResource
#
attr_accessor :page

Expand Down
25 changes: 20 additions & 5 deletions lib/jekyll/helper/rdf_generator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ module Helper
module RdfGeneratorHelper
private
def prepare_pages (site, mapper)
Jekyll::Page.prepend Jekyll::JekyllRdf::Helper::RdfPageHelper
@pageResources.each{|uri, entry|
resource = entry.delete('./')
resource.subResources = entry
create_page(site, resource, mapper, @global_config)
create_page(site, resource, mapper)
}

@blanknodes.each{|resource|
create_page(site, resource, mapper, @global_config)
create_page(site, resource, mapper)
}
end

Expand Down Expand Up @@ -120,10 +121,24 @@ def extract_resources(selection, include_blank, sparql)
end.uniq
end

def create_page(site, resource, mapper, global_config)
page = RdfPageData.new(site, site.source, resource, mapper, global_config)
def create_page(site, resource, mapper)
Jekyll::JekyllRdf::Helper::RdfPageHelper.prepare_resource resource, mapper
page = Jekyll::Page.new(site, site.source, resource.filedir, resource.filename)
page.re_init_as_rdf(resource, mapper)
if(page.complete)
site.pages << page
changes = false
site.pages.map!{|old_page|
if (File.join(old_page.dir, old_page.name) == File.join(page.dir, page.name))
changes||=true
page.assimilate_page(old_page)
page
else
old_page
end
}
unless changes
site.pages << page
end
resource.add_necessities(site, page)
resource.subResources.each {|key, value|
value.add_necessities(site, page)
Expand Down
66 changes: 58 additions & 8 deletions lib/jekyll/helper/rdf_page_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@ module Jekyll
module JekyllRdf
module Helper
module RdfPageHelper
attr_reader :complete

def assimilate_page page
self.data.merge!(page.data)
setData()
if page.data['layout'].nil?
self.content.gsub!(/{{\s*content\s*}}/, page.content)
else
self.content = page.content
end
self
end

def re_init_as_rdf(resource, mapper)
@resource = resource
if(@base.nil?)
Jekyll.logger.warn "Resource #{resource} not rendered: no base url found."
@complete = false #TODO: set a return here and adapt the test for displaying a warning for rendering a page without template
else
@complete = true
end
map_template(resource, mapper)
return unless @complete
load_data(@site)
self.data['permalink'] = File.join(@dir, @name) #overwrite permalinks to stop them from interfering with JekyllRdfs rendersystem
return unless @complete
load_prefixes_yaml()
resource.page = self
resource.site = @site
@site.data['resources'] << resource
end

def self.prepare_resource resource, mapper
@@template = mapper.map(resource)
@@template.gsub!(".html", "") unless @@template.nil? #gsub only for downward compatibility // remove gsub + unless on next version update
end

def read_yaml(base, name, opts = {})
@path = @site.layouts[Jekyll::JekyllRdf::Helper::RdfPageHelper.template(true)].path unless Jekyll::JekyllRdf::Helper::RdfPageHelper.template.nil?
super(base, name, opts)
end

def self.template read_out = false
template = @@template
@@template = nil if read_out
template
end

private
include Jekyll::JekyllRdf::Helper::RdfPrefixHelper
##
Expand All @@ -10,7 +58,8 @@ module RdfPageHelper
# * +resource+ - the resource that will be mapped to a template
# * +mapper+ - the mapper that provides the resource mappings
def map_template(resource, mapper)
@template = mapper.map(resource).gsub(".html", "") unless mapper.map(resource).nil? #gsub only for downward compatibility // remove gsub + unless on next version update
@template = mapper.map(resource)
@template.gsub!(".html", "") unless @template.nil? #gsub only for downward compatibility // remove gsub + unless on next version update
if(@template.nil?)
Jekyll.logger.warn("Resource #{resource} not rendered: No fitting template or default template found.")
@complete = false
Expand All @@ -30,11 +79,7 @@ def load_data(site)
@complete = false
return
end
@path = @site.layouts[@template].path
self.read_yaml(@site.layouts[@template].instance_variable_get(:@base_dir), @site.layouts[@template].name)
self.data['title'] = @resource.iri
self.data['rdf'] = @resource
self.data['template'] = @template
setData()
if(!@resource.subResources.nil?)
self.data['sub_rdf'] = @resource.subResources.values
self.data['sub_rdf'].each { |res|
Expand All @@ -44,16 +89,21 @@ def load_data(site)
end
end

def setData
self.data['rdf'] = @resource
self.data['template'] = @template
end

##
# loads the prefix data passed in the layout yaml-frontmatter into page.data["rdf_prefixes"] and page.data["rdf_prefix_map"]
def load_prefixes_yaml
if !self.data["rdf_prefix_path"].nil?
unless self.data["rdf_prefix_path"].nil?
load_prefixes(File.join(@site.layouts[@template].instance_variable_get(:@base_dir), self.data["rdf_prefix_path"].strip), self.data)
end
end

end

end
end
end

2 changes: 1 addition & 1 deletion lib/jekyll/helper/rdf_prefix_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module RdfPrefixHelper
def load_prefixes(path, prefHolder)
Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes(path, prefHolder)
rescue Errno::ENOENT => ex
Jekyll.logger.error("--> context resource: #{@resource} template: #{@template}") if self.class <= Jekyll::RdfPageData
Jekyll.logger.error("--> context resource: #{@resource} template: #{@template}") unless self.data["rdf"].nil?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/hooks/rdf_page_pointer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


Jekyll::Hooks.register :pages, :pre_render do |page, payload|
if(page.class <= Jekyll::RdfPageData)
unless(page.data['rdf'].nil?)
payload["content"] = ""
end
if(page.data["rdf_prefixes"].nil? && !page.data["rdf_prefix_path"].nil?)
Expand Down
66 changes: 0 additions & 66 deletions lib/jekyll/rdf_page_data.rb

This file was deleted.

2 changes: 1 addition & 1 deletion test/ResourceHelper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def fake_page.eql? other_page
end

def fake_page.class
return Jekyll::RdfPageData
return Jekyll::Page
end

def fake_page.is_a? t_class
Expand Down
3 changes: 2 additions & 1 deletion test/source/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ jekyll_rdf:
"http://example.org/B" : "test_rdf_get"
"http://example.org/B#some" : "test_rdf_get"
"http://example.org/C" : "test_rdf_get"
"http://www.ifi.uio.no/INF3580/pages" : "sites_covered"
"http://www.ifi.uio.no/INF3580/pages" : "sites_covered"
"http://www.ifi.uio.no/INF3580/ex/hybrid/" : "conflictWrap"
14 changes: 14 additions & 0 deletions test/source/_layouts/conflictWrap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
---
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>This page is a conflict wrapper for the following page:</h1>
{{content}}
</body>
</html>
4 changes: 4 additions & 0 deletions test/source/_layouts/merge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---
outer part of a merged page
{{ content }}
4 changes: 4 additions & 0 deletions test/source/_layouts/nMerge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---
an unmerged page
{{ content }}
3 changes: 3 additions & 0 deletions test/source/_layouts/nil.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---
this is nil content
3 changes: 3 additions & 0 deletions test/source/ex/hybrid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---
<h3>Our Hybrid page</h3>
3 changes: 3 additions & 0 deletions test/source/ex/hybrid/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---
<h3>Our Hybrid page</h3>
1 change: 1 addition & 0 deletions test/source/rdf-data/simpsons.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ plha:gem plh:predicate plh:object.
<http://example.org/date> <http://example.org/dateTimeSec> "2018-06-12T12:42:55+02:00"^^xsd:dateTime .

base:pages a base:page .
<http://www.ifi.uio.no/INF3580/ex/hybrid/> rdfs:label "Some label".
Loading

0 comments on commit 285efc4

Please sign in to comment.