Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use liquid template for bibliographies

add support for file repositories
  • Loading branch information...
commit 913ca29ac16079315e40a07e2af45db13978ada0 1 parent 4f61717
@inukshuk authored
View
1  .travis.yml
@@ -1,6 +1,7 @@
language: ruby
bundler_args: --without debug
rvm:
+ - 2.1.0
- 2.0.0
- 1.9.3
notifications:
View
9 Gemfile
@@ -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
View
8 features/bibtex.feature
@@ -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":
"""
View
4 features/details.feature
@@ -1,8 +1,8 @@
-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:
View
4 jekyll-scholar.gemspec
@@ -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
View
3  lib/jekyll/scholar/defaults.rb
@@ -9,6 +9,7 @@ class Scholar
'source' => './_bibliography',
'bibliography' => 'references.bib',
+ 'repository' => nil,
'bibtex_options' => { :strip => false },
'bibtex_filters' => [ :latex ],
@@ -20,7 +21,7 @@ class Scholar
'details_link' => 'Details',
'bibliography_class' => 'bibliography',
- 'bibliography_template' => '%{reference}',
+ 'bibliography_template' => '{{reference}}',
'reference_tagname' => 'span',
'missing_reference' => '(missing reference)',
View
4 lib/jekyll/scholar/generators/details.rb
@@ -38,7 +38,7 @@ def liquidify(entry)
class DetailsGenerator < Generator
include Scholar::Utilities
-
+
safe true
priority :high
@@ -63,4 +63,4 @@ def generate(site)
end
-end
+end
View
2  lib/jekyll/scholar/tags/bibliography.rb
@@ -20,7 +20,7 @@ def render(context)
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|
View
56 lib/jekyll/scholar/utilities.rb
@@ -35,7 +35,7 @@ def optparse(arguments)
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 @@ def entries
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 @@ def reference_tagname
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 @@ def details_file_for(entry)
[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
Please sign in to comment.
Something went wrong with that request. Please try again.