Fix #179 make repository keys more flexible

parent fd1c3435
...@@ -98,3 +98,52 @@ Feature: PDF Repository ...@@ -98,3 +98,52 @@ Feature: PDF Repository
And the "_site/papers/ruby.pdf" file should exist 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 "Link: /papers/ruby.pdf" in "_site/scholar.html"
And I should see "Slides: /papers/ruby.ppt" 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 ...@@ -27,8 +27,14 @@ module Jekyll
'source' => './_bibliography', 'source' => './_bibliography',
# Name of default references file # Name of default references file
'bibliography' => 'references.bib', 'bibliography' => 'references.bib',
# The repository folder with your entries' attachemnts, slides, etc.
'repository' => nil, '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_options' => { :strip => false, :parse_months => true },
'bibtex_filters' => [ :superscript, :latex ], 'bibtex_filters' => [ :superscript, :latex ],
'bibtex_skip_fields' => [ :abstract, :month_numeric ], 'bibtex_skip_fields' => [ :abstract, :month_numeric ],
...@@ -70,7 +76,8 @@ module Jekyll ...@@ -70,7 +76,8 @@ module Jekyll
}, },
'type_order' => [], 'type_order' => [],
'month_names' => nil, 'month_names' => nil
}.freeze }.freeze
class << self class << self
......
...@@ -79,7 +79,7 @@ module Jekyll ...@@ -79,7 +79,7 @@ module Jekyll
end end
group_renderer(groups,group_keys,group_order,group_tags) group_renderer(groups,group_keys,group_order,group_tags)
end end
def render_items(items) def render_items(items)
bibliography = items.each_with_index.map { |entry, index| bibliography = items.each_with_index.map { |entry, index|
reference = bibliography_tag(entry, index + 1) reference = bibliography_tag(entry, index + 1)
...@@ -96,7 +96,7 @@ module Jekyll ...@@ -96,7 +96,7 @@ module Jekyll
{ :class => config['bibliography_class'] }.merge(config['bibliography_list_attributes']) { :class => config['bibliography_class'] }.merge(config['bibliography_list_attributes'])
end end
end end
end end
......
...@@ -239,6 +239,7 @@ module Jekyll ...@@ -239,6 +239,7 @@ module Jekyll
grouper(ungrouped, group_keys, group_order) grouper(ungrouped, group_keys, group_order)
end end
def group_keys def group_keys
return @group_keys unless @group_keys.nil? return @group_keys unless @group_keys.nil?
...@@ -351,14 +352,15 @@ module Jekyll ...@@ -351,14 +352,15 @@ module Jekyll
repo = Hash.new { |h,k| h[k] = {} } repo = Hash.new { |h,k| h[k] = {} }
return repo unless repository? 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 # 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| Dir[File.join(site.source, repository_path, '**/*')].each do |path|
extname = File.extname(path) parts = path.split(repository_file_delimiter, 2)
repo[File.basename(path, extname)][extname[1..-1]] = Pathname(path).relative_path_from(Pathname(base)) repo[File.basename(parts[0])][parts[1]] =
Pathname(path).relative_path_from(Pathname(base))
end end
repo repo
...@@ -368,6 +370,10 @@ module Jekyll ...@@ -368,6 +370,10 @@ module Jekyll
config['repository'] config['repository']
end end
def repository_file_delimiter
config['repository_file_delimiter']
end
def replace_strings? def replace_strings?
config['replace_strings'] config['replace_strings']
end end
...@@ -400,7 +406,7 @@ module Jekyll ...@@ -400,7 +406,7 @@ module Jekyll
def scholar_source def scholar_source
source = config['source'] source = config['source']
# Improve by using Pathname from stdlib? # Improve by using Pathname from stdlib?
return source if source.start_with?('/') && File.exists?(source) return source if source.start_with?('/') && File.exists?(source)
...@@ -455,7 +461,7 @@ module Jekyll ...@@ -455,7 +461,7 @@ module Jekyll
def bibliography_tag(entry, index) def bibliography_tag(entry, index)
return missing_reference unless entry return missing_reference unless entry
tmp = liquid_template.render( tmp = liquid_template.render(
reference_data(entry,index) reference_data(entry,index)
.merge(site.site_payload) .merge(site.site_payload)
...@@ -471,7 +477,7 @@ module Jekyll ...@@ -471,7 +477,7 @@ module Jekyll
# process the generated reference with Liquid, to get the same behaviour as # process the generated reference with Liquid, to get the same behaviour as
# when it is used on a page # when it is used on a page
Liquid::Template.parse(tmp).render( Liquid::Template.parse(tmp).render(
site.site_payload, site.site_payload,
{ {
:registers => { :site => site }, :registers => { :site => site },
:filters => [Jekyll::Filters] :filters => [Jekyll::Filters]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment