Skip to content

Commit

Permalink
streamline filename generation
Browse files Browse the repository at this point in the history
the methods page_url, render_path, filename and filedir will now yield correct
results, no matter in what order they are used.
  • Loading branch information
Simaris committed Apr 12, 2018
1 parent bf535df commit 0137c87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/jekyll/drops/rdf_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ def statements_as_object
#
def filename
return @filename unless @filename.nil?
generate_file_name(URI::split(Jekyll::JekyllRdf::Helper::RdfHelper::site.config["url"])[2], Jekyll::JekyllRdf::Helper::RdfHelper::site.config["baseurl"])
generate_file_name()
@filename
end

def filedir
return @filedir unless @filedir.nil?
generate_file_name(URI::split(Jekyll::JekyllRdf::Helper::RdfHelper::site.config["url"])[2], Jekyll::JekyllRdf::Helper::RdfHelper::site.config["baseurl"])
generate_file_name()
@filedir
end

Expand All @@ -141,7 +141,7 @@ def direct_classes
#
def page_url
return @page_url unless @page_url.nil?
generate_file_name(@site.config["url"], @site.config["baseurl"])
generate_file_name()
@page_url
end

Expand All @@ -150,7 +150,7 @@ def page_url
#
def render_path
return @render_path unless @page_url.nil?
generate_file_name(@site.config["url"], @site.config["baseurl"])
generate_file_name()
@render_path
end

Expand Down Expand Up @@ -250,10 +250,10 @@ def identify_name_from_path(path)
# Generate a filename corresponding to the RDF resource represented by the receiver. The mapping between RDF resources and filenames should be bijective. If the url of the rdf is the same as of the hosting site it will be omitted.
# * +domain_name+
#
def generate_file_name(domain_name, baseurl)
def generate_file_name()
fragment_holder = nil
domain_name = domain_name.to_s
baseurl = baseurl.to_s
domain_name = URI::split(Jekyll::JekyllRdf::Helper::RdfHelper::site.config["url"])[2].to_s
baseurl = Jekyll::JekyllRdf::Helper::RdfHelper::site.config["baseurl"].to_s
(("/".eql? baseurl[-1]) || (baseurl.empty? && ("/".eql? domain_name[-1]))) ? rdfsites="rdfsites/": rdfsites="/rdfsites/"
if(term.to_s[0..1].eql? "_:")
file_name = "#{rdfsites}blanknode/#{term.to_s.gsub('_:','blanknode_')}/" # ':' can not be used on windows
Expand Down
7 changes: 5 additions & 2 deletions test/test_rdf_page_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
setup do
@config = Jekyll.configuration({'url' => "http://ex.org", 'baseurl' => "" })
@site = Jekyll::Site.new(@config)
Jekyll::JekyllRdf::Helper::RdfHelper::site = @site
end

should "correctly render simple urls" do
Expand Down Expand Up @@ -160,6 +161,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
setup do
@config = Jekyll.configuration({'url' => "http://ex.org", 'baseurl' => "/" })
@site = Jekyll::Site.new(@config)
Jekyll::JekyllRdf::Helper::RdfHelper::site = @site
end

should "correctly render simple urls" do
Expand Down Expand Up @@ -187,6 +189,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
setup do
@config = Jekyll.configuration({'url' => "http://ex.org", 'baseurl' => "/blog" })
@site = Jekyll::Site.new(@config)
Jekyll::JekyllRdf::Helper::RdfHelper::site = @site
end

should "correctly render simple urls" do
Expand Down Expand Up @@ -218,6 +221,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
setup do
@config = Jekyll.configuration({'url' => "http://ex.org", 'baseurl' => "/blog/" })
@site = Jekyll::Site.new(@config)
Jekyll::JekyllRdf::Helper::RdfHelper::site = @site
end

should "correctly render simple urls" do
Expand Down Expand Up @@ -273,8 +277,7 @@ class TestRdfTemplateMapper < Test::Unit::TestCase
assert_equal "/rdfsites/http/ex.org/blog/bla/", resource.filedir
resource = Jekyll::JekyllRdf::Drops::RdfResource.new("http://ex.org/blog/bla/a")
@site.config['url'] = "http://ex.org"
@site.config['baseurl'] = ""
Jekyll.logger.error "\nbaseurl: #{@site.config['baseurl']}\n baseurl: #{Jekyll::JekyllRdf::Helper::RdfHelper::site.config['baseurl']}"
@site.config['baseurl'] = "t"
assert_equal "a.html", resource.filename
assert_equal "/rdfsites/http/ex.org/blog/bla/", resource.filedir
resource = Jekyll::JekyllRdf::Drops::RdfResource.new("http://ex.org/blog/bla/a")
Expand Down

0 comments on commit 0137c87

Please sign in to comment.