f4550644 by Dan Gopstein Committed by Sylvester Keil

Allow style paths relative to Jekyll's source directory (#180)

* Use site source path to qualify style location

* Fix tests by checking for existence of local style

* Add test that fails in master and succeeds in this branch
1 parent 8bab5410
......@@ -369,3 +369,49 @@ Feature: BibTeX
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should not see "{%[\w*]raw[\w*]%}" in "_site/scholar.html"
@config @bibliography @style
Scenario: A custom style with Jekyll source directory set
Given I have a configuration file with:
| key | value |
| source | src |
And I have a scholar configuration with:
| key | value |
| source | _bibliography |
| style | _styles/custom.csl |
And I have a "src" directory
And I have a "src/_bibliography" directory
And I have a "src/_styles" directory
And I have a file "src/_styles/custom.csl":
"""
<style>
<citation>
<layout>
<text variable="title"/>
</layout>
</citation>
<bibliography>
<layout>
<text variable="title"/>
</layout>
</bibliography>
</style>
"""
And I have a file "src/_bibliography/references.bib":
"""
@book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
"""
And I have a page "src/scholar.html":
"""
---
---
{% bibliography --style _styles/custom.csl %}
"""
When I run jekyll
Then the _site directory should exist
And I should see "The Ruby Programming Language" in "_site/scholar.html"
\ No newline at end of file
......
......@@ -598,12 +598,12 @@ module Jekyll
item.label = label unless label.nil?
item
}, STYLES[style].citation
}, style_cache(style).citation
end
def render_bibliography(entry, index = nil)
renderer.render citation_item_for(entry, index),
STYLES[style].bibliography
style_cache(style).bibliography
end
def citation_item_for(entry, citation_number = nil)
......@@ -693,6 +693,25 @@ module Jekyll
config.merge!(site.config['scholar'] || {})
self
end
# Try to resolve local style paths
# relative to Jekyll's source directory
def style_cache(style_name)
style =
if site && site.source
site_relative_style = File.join(site.source, style_name)
if Pathname.new(style_name).relative? && File.exist?(site_relative_style)
site_relative_style
else
style_name
end
else
style_name
end
STYLES[style]
end
end
end
......