Commit 3152df77 authored by Sylvester Keil's avatar Sylvester Keil

improving on details page generator

#1
parent a1cace40
...@@ -2,3 +2,7 @@ source :rubygems ...@@ -2,3 +2,7 @@ source :rubygems
gemspec gemspec
gem 'unicode_utils' gem 'unicode_utils'
group 'development' do
gem 'debugger'
end
Feature: BibTeX
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:
| key | value |
| source | ./_bibliography |
| details_layout | details.html |
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 "_layouts" directory
And I have a file "_layouts/details.html":
"""
---
---
<html>
<head></head>
<body>
{{ page.entry.title }}
</body>
</html>
"""
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"
...@@ -3,8 +3,9 @@ require 'test/unit' ...@@ -3,8 +3,9 @@ require 'test/unit'
require 'jekyll/scholar' require 'jekyll/scholar'
# require 'ruby-debug'
# Debugger.start require 'debugger'
World do World do
include Test::Unit::Assertions include Test::Unit::Assertions
......
...@@ -25,7 +25,7 @@ module Jekyll ...@@ -25,7 +25,7 @@ module Jekyll
bibliography references.bib bibliography references.bib
details_dir ./bibliography details_dir ./bibliography
detauls_layout bibtex.html details_layout bibtex.html
}].freeze }].freeze
......
...@@ -7,14 +7,14 @@ module Jekyll ...@@ -7,14 +7,14 @@ module Jekyll
def initialize(site, base, dir, entry) def initialize(site, base, dir, entry)
@site, @base, @dir = site, base, dir @site, @base, @dir = site, base, dir
@config = Scholar.defaults.merge(site.config['scholar'] || {}) @config = Scholar.defaults.merge(site.config['scholar'] || {})
@name = [entry.key, 'html'].join('.') @name = [entry.key, 'html'].join('.')
process(@name) process(@name)
read_yaml(File.join(base, '_layouts'), config['details_layout']) read_yaml(File.join(base, '_layouts'), config['details_layout'])
data['entry'] = entry data['entry'] = entry
end end
end end
...@@ -25,12 +25,11 @@ module Jekyll ...@@ -25,12 +25,11 @@ module Jekyll
attr_reader :config attr_reader :config
def generate(site) def generate(site)
if site.config['scholar'] && site.layouts.key?(site.config['scholar']['details_layout']) @config = Scholar.defaults.merge(site.config['scholar'] || {})
@config = Scholar.defaults.merge(site.config['scholar'] || {}) if site.layouts.key?(File.basename(config['details_layout'], '.html'))
bibliography.each do |entry|
bibliography['@*'].each do |entry| details = Details.new(site, site.source, config['details_dir'], entry)
details = Detauls.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)
...@@ -39,19 +38,15 @@ module Jekyll ...@@ -39,19 +38,15 @@ module Jekyll
end end
end end
private private
def bibliography def bibliography
@bibliography ||= BibTeX.open(extend_path(file), :filter => :latex) @bibliography ||= BibTeX.open(bibliography_path, :filter => :latex)
end end
def extend_path(name) def bibliography_path
if name.nil? || name.empty? p = File.join(config['source'], config['bibliography'])
name = config['bibliography']
end
p = File.join(config['source'], name)
p << '.bib' unless File.exists?(p) p << '.bib' unless File.exists?(p)
p p
end 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