Commit 80e27522 authored by Sylvester Keil's avatar Sylvester Keil

added filter/query settings

#1
parent ee753709
......@@ -34,4 +34,4 @@ Feature: BibTeX
When I run jekyll
Then the _site directory should exist
And the "_site/bibliography/ruby.html" file should exist
And I should see "<i>The Ruby Programming Language</i>" in "_site/bibliography/ruby.html"
And I should see "The Ruby Programming Language" in "_site/bibliography/ruby.html"
Feature: BibTeX
As a scholar who likes to blog
I want to apply filters to my BibTeX bibliography
In order to have control over the references that go up on my website
@tags @filters
Scenario: Filter by Year
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| query | "@*[year=2009]" |
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}
}
@book{pickaxe,
title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
author = {Thomas, Dave and Fowler, Chad and Hunt, Andy},
year = {2009},
edition = 3,
publisher = {Pragmatic Bookshelf}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Programming Ruby" in "_site/scholar.html"
And I should not see "The Ruby Programming Language" in "_site/scholar.html"
......@@ -54,9 +54,15 @@ Then /^the (.*) directory should exist$/ do |dir|
end
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
puts File.open(file).readlines.join
assert_match Regexp.new(text), File.open(file).readlines.join
end
Then /^I should not see "(.*)" in "(.*)"$/ do |text, file|
assert !File.open(file).readlines.join.match(Regexp.new(text))
end
Then /^the "(.*)" file should exist$/ do |file|
assert File.file?(file)
end
......
......@@ -5,6 +5,7 @@ require 'bibtex'
require 'citeproc'
require 'jekyll/scholar/version'
require 'jekyll/scholar/utilities'
require 'jekyll/scholar/converters/bibtex'
require 'jekyll/scholar/tags/bibliography'
require 'jekyll/scholar/tags/cite'
......@@ -27,6 +28,8 @@ module Jekyll
details_dir ./bibliography
details_layout bibtex.html
query @*
}].freeze
class << self
......
......@@ -2,8 +2,9 @@ module Jekyll
class Scholar
class BibTeXConverter < Converter
safe true
priority :highest
attr_reader :config
@pattern = (/bib(tex)?$/i).freeze
@extension = '.html'.freeze
......@@ -12,10 +13,10 @@ module Jekyll
attr_reader :pattern, :extension
end
def initialize (config = {})
def initialize(config = {})
super
@config['scholar'] = Scholar.defaults.merge(@config['scholar'] || {})
@markdown = MarkdownConverter.new config
@markdown = MarkdownConverter.new(config)
end
def matches(extension)
......@@ -26,15 +27,16 @@ module Jekyll
BibTeXConverter.extension
end
def convert (content)
content = BibTeX.parse(content, :strict => true, :include => [:meta_content], :filter => [:latex]).map do |b|
def convert(content)
content = BibTeX.parse(content, :strict => true, :include => [:meta_content], :filter => [:latex]).map do |b|
if b.respond_to?(:to_citeproc)
CiteProc.process b.to_citeproc, :style => @config['style'],
:locale => @config['locale'], :format => 'html'
CiteProc.process b.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html'
else
b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
end
end
@markdown.convert(content.join("\n"))
end
......
......@@ -50,7 +50,7 @@ module Jekyll
@config = Scholar.defaults.merge(site.config['scholar'] || {})
if site.layouts.key?(File.basename(config['details_layout'], '.html'))
bibliography.each do |entry|
bibliography[config['query']].each do |entry|
details = Details.new(site, site.source, config['details_dir'], entry)
details.render(site.layouts, site.site_payload)
details.write(site.dest)
......
......@@ -31,7 +31,7 @@ module Jekyll
"<li>#{r}</li>"
end
"<ol>\n#{references.join("\n")}\n</ol>"
end
......@@ -42,13 +42,13 @@ module Jekyll
end
def entries
b = bibliography['@*']
b = bibliography[config['query']]
unless config['sort_by'] == 'none'
b.sort_by! { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i
end
b
end
......
module Jekyll
class Scholar
module Utilities
end
end
end
\ No newline at end of file
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