Commit 913ca29a authored by Sylvester Keil's avatar Sylvester Keil

use liquid template for bibliographies

add support for file repositories
parent 4f617173
language: ruby
bundler_args: --without debug
rvm:
- 2.1.0
- 2.0.0
- 1.9.3
notifications:
......
......@@ -12,9 +12,12 @@ group 'development' do
gem 'redcarpet', '~> 2.2.2'
gem 'launchy', '~> 2.1.2'
gem 'unicode_utils'
gem 'unicode_utils'
end
group 'debug' do
gem 'debugger'
group :debug do
gem 'ruby-debug', :require => false, :platform => :jruby
gem 'debugger', '~>1.6', :require => false, :platform => :mri
gem 'rubinius-compiler', '~>2.0', :require => false, :platform => :rbx
gem 'rubinius-debugger', '~>2.0', :require => false, :platform => :rbx
end
......@@ -35,7 +35,7 @@ Feature: BibTeX
---
References
==========
@book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
......@@ -93,9 +93,9 @@ Feature: BibTeX
@tags @bibliography @config
Scenario: Simple Bibliography With Custom Template
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| bibliography_template | <abbr>%{index} [%{key}]</abbr>%{reference} |
| key | value |
| source | ./_bibliography |
| bibliography_template | <abbr>{{index}} [{{key}}]</abbr>{{reference}} |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
......
Feature: BibTeX
Feature: Details
As a scholar who likes to blog
I want to publish my BibTeX bibliography on my blog
And I want Jekyll to generate detail pages for all the entries in my bibliography
@generators
Scenario: A bibliography with a single entry
Given I have a scholar configuration with:
......
......@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
formats your BibTeX bibliographies for the web using CSL citation styles
and generally gives your blog posts citation super-powers.'
}.gsub(/\s+/, ' ')
s.date = Time.now
s.required_rubygems_version = '>= 1.3.6'
......@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = []
s.require_path = 'lib'
end
# vim: syntax=ruby
......@@ -9,6 +9,7 @@ module Jekyll
'source' => './_bibliography',
'bibliography' => 'references.bib',
'repository' => nil,
'bibtex_options' => { :strip => false },
'bibtex_filters' => [ :latex ],
......@@ -20,7 +21,7 @@ module Jekyll
'details_link' => 'Details',
'bibliography_class' => 'bibliography',
'bibliography_template' => '%{reference}',
'bibliography_template' => '{{reference}}',
'reference_tagname' => 'span',
'missing_reference' => '(missing reference)',
......
......@@ -38,7 +38,7 @@ module Jekyll
class DetailsGenerator < Generator
include Scholar::Utilities
safe true
priority :high
......@@ -63,4 +63,4 @@ module Jekyll
end
end
\ No newline at end of file
end
......@@ -20,7 +20,7 @@ module Jekyll
if cited_only?
references = cited_references.uniq.map do |key|
references.detect { |e| e.key == key }
end
end
end
bibliography = references.each_with_index.map { |entry, index|
......
......@@ -35,7 +35,7 @@ module Jekyll
opts.on('-s', '--style STYLE') do |style|
@style = style
end
end
end
argv = arguments.split(/(\B-[cfqpts]|\B--(?:cited|file|query|prefix|text|style|))/)
......@@ -75,6 +75,26 @@ module Jekyll
b
end
def repository?
!config['repository'].nil? && !config['repository'].empty?
end
def repository
@repository ||= load_repository
end
def load_repository
return {} unless repository?
Hash[Dir[File.join(repository_path, '**/*.{pdf,ps}')].map { |path|
[File.basename(path).sub(/\.(pdf|ps)$/, ''), path]
}]
end
def repository_path
config['repository']
end
def replace_strings?
config['replace_strings']
end
......@@ -120,18 +140,31 @@ module Jekyll
end
def bibliography_template
config['bibliography_template'] || '%{reference}'
return @bibliography_template if @bibliography_template
tmp = config['bibliography_template'] || '{{reference}}'
case
when tmp.nil?
tmp = '{{reference}}'
when site.layouts.key?(tmp)
tmp = site.layouts[tmp].content
end
@bibliography_template = Liquid::Template.parse(tmp)
end
def bibliography_tag(entry, index)
return missing_reference unless entry
bibliography_template % {
:reference => reference_tag(entry),
:key => entry.key,
:type => entry.type,
:index => index
}
bibliography_template.render({
'entry' => entry,
'reference' => reference_tag(entry),
'key' => entry.key,
'type' => entry.type,
'link' => repository_link_for(entry),
'index' => index
})
end
def generate_details?
......@@ -146,6 +179,13 @@ module Jekyll
[name, 'html'].join('.')
end
def repository_link_for(entry, base = base_url)
url = repository[entry.key]
return unless url
File.join(base, url)
end
def details_link_for(entry, base = base_url)
File.join(base, details_path, details_file_for(entry))
end
......
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