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

added filter/query settings

#1
parent ee753709
...@@ -34,4 +34,4 @@ Feature: BibTeX ...@@ -34,4 +34,4 @@ Feature: BibTeX
When I run jekyll When I run jekyll
Then the _site directory should exist Then the _site directory should exist
And the "_site/bibliography/ruby.html" file 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| ...@@ -54,9 +54,15 @@ Then /^the (.*) directory should exist$/ do |dir|
end end
Then /^I should see "(.*)" in "(.*)"$/ do |text, file| Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
puts File.open(file).readlines.join
assert_match Regexp.new(text), File.open(file).readlines.join assert_match Regexp.new(text), File.open(file).readlines.join
end 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| Then /^the "(.*)" file should exist$/ do |file|
assert File.file?(file) assert File.file?(file)
end end
......
...@@ -5,6 +5,7 @@ require 'bibtex' ...@@ -5,6 +5,7 @@ require 'bibtex'
require 'citeproc' require 'citeproc'
require 'jekyll/scholar/version' require 'jekyll/scholar/version'
require 'jekyll/scholar/utilities'
require 'jekyll/scholar/converters/bibtex' require 'jekyll/scholar/converters/bibtex'
require 'jekyll/scholar/tags/bibliography' require 'jekyll/scholar/tags/bibliography'
require 'jekyll/scholar/tags/cite' require 'jekyll/scholar/tags/cite'
...@@ -27,6 +28,8 @@ module Jekyll ...@@ -27,6 +28,8 @@ module Jekyll
details_dir ./bibliography details_dir ./bibliography
details_layout bibtex.html details_layout bibtex.html
query @*
}].freeze }].freeze
class << self class << self
......
...@@ -2,8 +2,9 @@ module Jekyll ...@@ -2,8 +2,9 @@ module Jekyll
class Scholar class Scholar
class BibTeXConverter < Converter class BibTeXConverter < Converter
safe true safe true
priority :highest priority :highest
attr_reader :config
@pattern = (/bib(tex)?$/i).freeze @pattern = (/bib(tex)?$/i).freeze
@extension = '.html'.freeze @extension = '.html'.freeze
...@@ -12,10 +13,10 @@ module Jekyll ...@@ -12,10 +13,10 @@ module Jekyll
attr_reader :pattern, :extension attr_reader :pattern, :extension
end end
def initialize (config = {}) def initialize(config = {})
super super
@config['scholar'] = Scholar.defaults.merge(@config['scholar'] || {}) @config['scholar'] = Scholar.defaults.merge(@config['scholar'] || {})
@markdown = MarkdownConverter.new config @markdown = MarkdownConverter.new(config)
end end
def matches(extension) def matches(extension)
...@@ -26,15 +27,16 @@ module Jekyll ...@@ -26,15 +27,16 @@ module Jekyll
BibTeXConverter.extension BibTeXConverter.extension
end end
def convert (content) def convert(content)
content = BibTeX.parse(content, :strict => true, :include => [:meta_content], :filter => [:latex]).map do |b| content = BibTeX.parse(content, :strict => true, :include => [:meta_content], :filter => [:latex]).map do |b|
if b.respond_to?(:to_citeproc) if b.respond_to?(:to_citeproc)
CiteProc.process b.to_citeproc, :style => @config['style'], CiteProc.process b.to_citeproc, :style => config['style'],
:locale => @config['locale'], :format => 'html' :locale => config['locale'], :format => 'html'
else else
b.is_a?(BibTeX::MetaContent) ? b.to_s : '' b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
end end
end end
@markdown.convert(content.join("\n")) @markdown.convert(content.join("\n"))
end end
......
...@@ -50,7 +50,7 @@ module Jekyll ...@@ -50,7 +50,7 @@ module Jekyll
@config = Scholar.defaults.merge(site.config['scholar'] || {}) @config = Scholar.defaults.merge(site.config['scholar'] || {})
if site.layouts.key?(File.basename(config['details_layout'], '.html')) 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 = Details.new(site, site.source, config['details_dir'], entry)
details.render(site.layouts, site.site_payload) details.render(site.layouts, site.site_payload)
details.write(site.dest) details.write(site.dest)
......
...@@ -31,7 +31,7 @@ module Jekyll ...@@ -31,7 +31,7 @@ module Jekyll
"<li>#{r}</li>" "<li>#{r}</li>"
end end
"<ol>\n#{references.join("\n")}\n</ol>" "<ol>\n#{references.join("\n")}\n</ol>"
end end
...@@ -42,13 +42,13 @@ module Jekyll ...@@ -42,13 +42,13 @@ module Jekyll
end end
def entries def entries
b = bibliography['@*'] b = bibliography[config['query']]
unless config['sort_by'] == 'none' unless config['sort_by'] == 'none'
b.sort_by! { |e| e[config['sort_by']].to_s } b.sort_by! { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i b.reverse! if config['order'] =~ /^(desc|reverse)/i
end end
b b
end 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