Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
J
jekyll-scholar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
caesr-pub
jekyll-scholar
Commits
a5cf0849
Commit
a5cf0849
authored
Apr 22, 2012
by
Sylvester Keil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added bibliography and cite tags
#1
parent
11b1a3ed
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
285 additions
and
61 deletions
+285
-61
features/bibtex.feature
features/bibtex.feature
+38
-4
features/citation.feature
features/citation.feature
+57
-0
features/sorting.feature
features/sorting.feature
+30
-30
features/step_definitions/jekyll_steps.rb
features/step_definitions/jekyll_steps.rb
+0
-10
features/step_definitions/scholar_steps.rb
features/step_definitions/scholar_steps.rb
+24
-1
lib/jekyll/scholar.rb
lib/jekyll/scholar.rb
+25
-0
lib/jekyll/scholar/converters/bibtex.rb
lib/jekyll/scholar/converters/bibtex.rb
+14
-15
lib/jekyll/scholar/tags/bibliography.rb
lib/jekyll/scholar/tags/bibliography.rb
+51
-0
lib/jekyll/scholar/tags/cite.rb
lib/jekyll/scholar/tags/cite.rb
+45
-0
lib/jekyll/scholar/version.rb
lib/jekyll/scholar/version.rb
+1
-1
No files found.
features/bibtex.feature
View file @
a5cf0849
...
...
@@ -3,8 +3,11 @@ Feature: BibTeX
I want to publish my BibTeX bibliography on my blog
In order to share my awesome references with my peers
@converters
Scenario
:
Simple Bibliography
Given
I have a configuration file with
"citation_style"
set to
"apa"
Given I have a scholar configuration with
:
|
key
|
value
|
|
style
|
apa
|
And I have a page "references.bib"
:
"""
---
...
...
@@ -21,8 +24,11 @@ Feature: BibTeX
And
the
"_site/references.html"
file should exist
And
I should see
"<i>The Ruby Programming Language</i>"
in
"_site/references.html"
@converters
Scenario
:
Markdown Formatted Bibliography
Given
I have a configuration file with
"citation_style"
set to
"apa"
Given I have a scholar configuration with
:
|
key
|
value
|
|
style
|
apa
|
And I have a page "references.bib"
:
"""
---
...
...
@@ -42,7 +48,9 @@ Feature: BibTeX
@latex
Scenario
:
Simple Bibliography with LaTeX directives
Given
I have a configuration file with
"citation_style"
set to
"apa"
Given I have a scholar configuration with
:
|
key
|
value
|
|
style
|
apa
|
And I have a page "references.bib"
:
"""
---
...
...
@@ -55,3 +63,29 @@ Feature: BibTeX
Then
the _site directory should exist
And
the
"_site/references.html"
file should exist
And I should see "Look, an umlaut
:
ü!"
in
"_site/references.html"
@tags
Scenario
:
Simple Bibliography Loaded From Default Directory
Given I have a scholar configuration with
:
|
key
|
value
|
|
source
|
./_bibliography
|
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 page "scholar.html"
:
"""
---
---
{% bibliography references %}
"""
When
I run jekyll
Then
the _site directory should exist
And
the
"_site/scholar.html"
file should exist
And
I should see
"<i>The Ruby Programming Language</i>"
in
"_site/scholar.html"
features/citation.feature
0 → 100644
View file @
a5cf0849
Feature
:
Citations
As a scholar who likes to blog
I want to reference cool papers and books from my bibliography
@tags
Scenario
:
A
Simple Citation
Given I have a scholar configuration with
:
|
key
|
value
|
|
source
|
./_bibliography
|
|
bibliography
|
my_references
|
And
I have a
"_bibliography"
directory
And I have a file "_bibliography/my_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 page "scholar.html"
:
"""
---
---
{% cite ruby %}
"""
When
I run jekyll
Then
the _site directory should exist
And
the
"_site/scholar.html"
file should exist
And
I should see
"Flanagan"
in
"_site/scholar.html"
@tags
Scenario
:
Missing references
Given I have a scholar configuration with
:
|
key
|
value
|
|
source
|
./_bibliography
|
|
bibliography
|
my_references
|
And
I have a
"_bibliography"
directory
And I have a file "_bibliography/my_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 page "scholar.html"
:
"""
---
---
{% cite java %}
"""
When
I run jekyll
Then
the _site directory should exist
And
the
"_site/scholar.html"
file should exist
And
I should see
"missing reference"
in
"_site/scholar.html"
features/sorting.feature
View file @
a5cf0849
...
...
@@ -2,33 +2,33 @@ Feature: Sorting BibTeX Bibliographies
As a scholar who likes to blog
I want to sort my bibliographies according to configurable parameters
Scenario Outline
:
Sort Bibliography
Given
I have a configuration file with
"citation_sort_by"
set to
"<sort-by>"
And
I have a configuration file with
"citation_sort_order"
set to
"<sort-order>"
And I have a page "references.bib"
:
"""
---
---
@book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
@book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2007},
publisher = {O'Reilly Media}
}
"""
When
I run jekyll
Then
"<pattern-1>"
should come before
"<pattern-2>"
in
"_site/references.html"
Scenarios
:
Various Sort Orders
|
sort_order
|
sort-by
|
pattern-1
|
pattern-2
|
|
ascending
|
none
|
2008
|
2007
|
|
descending
|
none
|
2008
|
2007
|
|
ascending
|
year
|
2007
|
2008
|
|
descending
|
year
|
2008
|
2007
|
\ No newline at end of file
# Scenario: Sort Bibliography
# Given I have a configuration file with "citation_sort_by" set to "<sort-by>"
# And I have a configuration file with "citation_sort_order" set to "<sort-order>"
# And I have a page "references.bib":
# """
# ---
# ---
# @book{ruby,
# title = {The Ruby Programming Language},
# author = {Flanagan, David and Matsumoto, Yukihiro},
# year = {2008},
# publisher = {O'Reilly Media}
# }
# @book{ruby,
# title = {The Ruby Programming Language},
# author = {Flanagan, David and Matsumoto, Yukihiro},
# year = {2007},
# publisher = {O'Reilly Media}
# }
# """
# When I run jekyll
# Then "<pattern-1>" should come before "<pattern-2>" in "_site/references.html"
#
# Scenarios: Various Sort Orders
# | sort_order | sort-by | pattern-1 | pattern-2 |
# | ascending | none | 2008 | 2007 |
# | descending | none | 2008 | 2007 |
# | ascending | year | 2007 | 2008 |
# | descending | year | 2008 | 2007 |
#
\ No newline at end of file
features/step_definitions/jekyll_steps.rb
View file @
a5cf0849
...
...
@@ -45,16 +45,6 @@ Given /^I have a configuration file with:$/ do |table|
end
end
Given
/^I have a configuration file with "([^\"]*)" set to:$/
do
|
key
,
table
|
File
.
open
(
'_config.yml'
,
'w'
)
do
|
f
|
f
.
write
(
"
#{
key
}
:
\n
"
)
table
.
hashes
.
each
do
|
row
|
f
.
write
(
"-
#{
row
[
"value"
]
}
\n
"
)
end
f
.
close
end
end
When
/^I run jekyll$/
do
run_jekyll
end
...
...
features/step_definitions/scholar_steps.rb
View file @
a5cf0849
Given
/^I have a page "([^"]*)":$/
do
|
file
,
string
|
Given
/^I have a "([^"]*)" directory/
do
|
dir
|
FileUtils
.
mkdir
(
dir
)
end
Given
/^I have a (?:page|file) "([^"]*)":$/
do
|
file
,
string
|
File
.
open
(
file
,
'w'
)
do
|
f
|
f
.
write
(
string
)
end
end
Given
/^I have a configuration file with "([^\"]*)" set to:$/
do
|
key
,
table
|
File
.
open
(
'_config.yml'
,
'w'
)
do
|
f
|
f
.
write
(
"
#{
key
}
:
\n
"
)
table
.
hashes
.
each
do
|
row
|
f
.
write
(
"
#{
row
[
"key"
]
}
:
#{
row
[
"value"
]
}
\n
"
)
end
end
end
Given
/^I have a scholar configuration with:$/
do
|
table
|
File
.
open
(
'_config.yml'
,
'w'
)
do
|
f
|
f
.
write
(
"scholar:
\n
"
)
table
.
hashes
.
each
do
|
row
|
f
.
write
(
"
#{
row
[
"key"
]
}
:
#{
row
[
"value"
]
}
\n
"
)
end
end
end
Then
/^"(.*)" should come before "(.*)" in "(.*)"$/
do
|
p1
,
p2
,
file
|
data
=
File
.
open
(
file
).
readlines
.
join
(
''
)
...
...
lib/jekyll/scholar.rb
View file @
a5cf0849
require
'jekyll'
require
'bibtex'
require
'citeproc'
require
'jekyll/scholar/version'
require
'jekyll/scholar/converters/bibtex'
require
'jekyll/scholar/tags/bibliography'
require
'jekyll/scholar/tags/cite'
module
Jekyll
class
Scholar
@defaults
=
Hash
[
*
%w{
style apa
locale en
sort_by none
order ascending
source ./_bibliography
bibliography references.bib
}
].
freeze
class
<<
self
attr_reader
:defaults
end
end
end
lib/jekyll/scholar/converters/bibtex.rb
View file @
a5cf0849
require
'bibtex'
require
'citeproc'
module
Jekyll
module
Scholar
class
Scholar
class
BibTeXConverter
<
Converter
safe
true
priority
:highest
DEFAULTS
=
Hash
[
*
%w{
citation_style apa
citation_locale en
citation_sort_by none
}
].
freeze
@pattern
=
(
/bib(tex)?$/i
).
freeze
@extension
=
'.html'
.
freeze
PATTERN
=
(
/bib(tex)?$/i
).
freeze
EXTENSION
=
'.html'
.
freeze
class
<<
self
attr_reader
:pattern
,
:extension
end
def
initialize
(
config
=
{})
super
@config
[
'scholar'
]
=
DEFAULTS
.
merge
(
@config
[
'scholar'
]
||
{})
@config
[
'scholar'
]
=
Scholar
.
defaults
.
merge
(
@config
[
'scholar'
]
||
{})
@markdown
=
MarkdownConverter
.
new
config
end
def
matches
(
extension
);
extension
=~
PATTERN
;
end
def
matches
(
extension
)
extension
=~
BibTeXConverter
.
pattern
end
def
output_ext
(
extension
);
EXTENSION
;
end
def
output_ext
(
extension
)
BibTeXConverter
.
extension
end
def
convert
(
content
)
content
=
BibTeX
.
parse
(
content
,
:include
=>
[
:meta_content
],
:filter
=>
[
:latex
]).
map
do
|
b
|
...
...
lib/jekyll/scholar/tags/bibliography.rb
0 → 100644
View file @
a5cf0849
module
Jekyll
class
Scholar
class
BibliographyTag
<
Liquid
::
Tag
attr_reader
:file
,
:config
def
initialize
(
tag_name
,
arguments
,
tokens
)
super
@config
=
Scholar
.
defaults
.
dup
@file
=
arguments
.
strip
end
def
render
(
context
)
config
.
merge!
(
context
.
registers
[
:site
].
config
[
'scholar'
]
||
{})
entries
.
map
{
|
e
|
CiteProc
.
process
e
.
to_citeproc
,
:style
=>
config
[
'style'
],
:locale
=>
config
[
'locale'
],
:format
=>
'html'
}.
join
(
"
\n
"
)
end
private
def
bibliography
@bibliography
||=
BibTeX
.
open
(
extend_path
(
file
),
:filter
=>
:latex
)
end
def
entries
b
=
bibliography
[
'@*'
]
unless
config
[
'sort_by'
]
==
'none'
b
.
sort_by!
{
|
e
|
e
[
config
[
'sort_by'
]]
}
b
.
reverse!
if
config
[
'order'
]
=~
/^(desc|reverse)/i
end
b
end
def
extend_path
(
name
)
p
=
File
.
join
(
config
[
'source'
],
name
)
p
<<
'.bib'
unless
File
.
exists?
(
p
)
p
end
end
end
end
Liquid
::
Template
.
register_tag
(
'bibliography'
,
Jekyll
::
Scholar
::
BibliographyTag
)
\ No newline at end of file
lib/jekyll/scholar/tags/cite.rb
0 → 100644
View file @
a5cf0849
module
Jekyll
class
Scholar
class
CiteTag
<
Liquid
::
Tag
attr_reader
:key
,
:pages
,
:config
def
initialize
(
tag_name
,
arguments
,
tokens
)
super
@config
=
Scholar
.
defaults
.
dup
@key
=
arguments
.
strip
.
split
(
/\s+/
)[
0
]
end
def
render
(
context
)
config
.
merge!
(
context
.
registers
[
:site
].
config
[
'scholar'
]
||
{})
puts
key
e
=
bibliography
[
key
]
puts
e
if
e
CiteProc
.
process
e
.
to_citeproc
,
:style
=>
config
[
'style'
],
:locale
=>
config
[
'locale'
],
:format
=>
'html'
,
:mode
=>
:citation
else
"(missing reference)"
end
end
private
def
bibliography
@bibliography
||=
BibTeX
.
open
(
extend_path
(
config
[
'bibliography'
]),
:filter
=>
:latex
)
end
def
extend_path
(
name
)
p
=
File
.
join
(
config
[
'source'
],
name
)
p
<<
'.bib'
unless
File
.
exists?
(
p
)
p
end
end
end
end
Liquid
::
Template
.
register_tag
(
'cite'
,
Jekyll
::
Scholar
::
CiteTag
)
\ No newline at end of file
lib/jekyll/scholar/version.rb
View file @
a5cf0849
module
Jekyll
module
Scholar
class
Scholar
VERSION
=
'0.0.1'
.
freeze
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment