8bab5410 by Sylvester Keil

Fix #179 make repository keys more flexible

1 parent fd1c3435
......@@ -98,3 +98,52 @@ Feature: PDF Repository
And the "_site/papers/ruby.pdf" file should exist
And I should see "Link: /papers/ruby.pdf" in "_site/scholar.html"
And I should see "Slides: /papers/ruby.ppt" in "_site/scholar.html"
@repository
Scenario: A bibliography with a single entry and a repository with slides pdf
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| repository | papers |
| bibliography_template | bibliography |
| file_delimit | '.' |
And I have a "_bibliography" directory
And I have a file "_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 "papers" directory
And I have a file "papers/ruby.pdf":
"""
The PDF
"""
And I have a file "papers/ruby.slides.pdf":
"""
The Slides PDF
"""
And I have a "_layouts" directory
And I have a file "_layouts/bibliography.html":
"""
---
---
{{ reference }} Link: {{ link }} Slides: {{ links['slides.pdf'] }}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/papers/ruby.pdf" file should exist
And the "_site/papers/ruby.slides.pdf" file should exist
And I should see "The Ruby Programming Language" in "_site/scholar.html"
And I should see "Link: /papers/ruby.pdf" in "_site/scholar.html"
And I should see "Slides: /papers/ruby.slides.pdf" in "_site/scholar.html"
......
......@@ -27,8 +27,14 @@ module Jekyll
'source' => './_bibliography',
# Name of default references file
'bibliography' => 'references.bib',
# The repository folder with your entries' attachemnts, slides, etc.
'repository' => nil,
# Delimiter for files in repositories;
# this character may not be part of your entry keys!
'repository_file_delimiter' => '.',
'bibtex_options' => { :strip => false, :parse_months => true },
'bibtex_filters' => [ :superscript, :latex ],
'bibtex_skip_fields' => [ :abstract, :month_numeric ],
......@@ -70,7 +76,8 @@ module Jekyll
},
'type_order' => [],
'month_names' => nil,
'month_names' => nil
}.freeze
class << self
......
......@@ -79,7 +79,7 @@ module Jekyll
end
group_renderer(groups,group_keys,group_order,group_tags)
end
def render_items(items)
bibliography = items.each_with_index.map { |entry, index|
reference = bibliography_tag(entry, index + 1)
......@@ -96,7 +96,7 @@ module Jekyll
{ :class => config['bibliography_class'] }.merge(config['bibliography_list_attributes'])
end
end
end
......
......@@ -239,6 +239,7 @@ module Jekyll
grouper(ungrouped, group_keys, group_order)
end
def group_keys
return @group_keys unless @group_keys.nil?
......@@ -351,14 +352,15 @@ module Jekyll
repo = Hash.new { |h,k| h[k] = {} }
return repo unless repository?
# ensure that the base directory format is literally
# ensure that the base directory format is literally
# the same as the entries that are in the directory
base = Dir[site.source][0]
base = Dir[site.source][0]
Dir[File.join(site.source, repository_path, '**/*')].each do |path|
extname = File.extname(path)
repo[File.basename(path, extname)][extname[1..-1]] = Pathname(path).relative_path_from(Pathname(base))
parts = path.split(repository_file_delimiter, 2)
repo[File.basename(parts[0])][parts[1]] =
Pathname(path).relative_path_from(Pathname(base))
end
repo
......@@ -368,6 +370,10 @@ module Jekyll
config['repository']
end
def repository_file_delimiter
config['repository_file_delimiter']
end
def replace_strings?
config['replace_strings']
end
......@@ -400,7 +406,7 @@ module Jekyll
def scholar_source
source = config['source']
# Improve by using Pathname from stdlib?
return source if source.start_with?('/') && File.exists?(source)
......@@ -455,7 +461,7 @@ module Jekyll
def bibliography_tag(entry, index)
return missing_reference unless entry
tmp = liquid_template.render(
reference_data(entry,index)
.merge(site.site_payload)
......@@ -471,7 +477,7 @@ module Jekyll
# process the generated reference with Liquid, to get the same behaviour as
# when it is used on a page
Liquid::Template.parse(tmp).render(
site.site_payload,
site.site_payload,
{
:registers => { :site => site },
:filters => [Jekyll::Filters]
......