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
2095c4a3
Commit
2095c4a3
authored
Apr 30, 2012
by
Sylvester Keil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added separate defaults and utilities
parent
80e27522
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
118 deletions
+116
-118
lib/jekyll/scholar.rb
lib/jekyll/scholar.rb
+2
-28
lib/jekyll/scholar/defaults.rb
lib/jekyll/scholar/defaults.rb
+26
-0
lib/jekyll/scholar/generators/details.rb
lib/jekyll/scholar/generators/details.rb
+7
-26
lib/jekyll/scholar/tags/bibliography.rb
lib/jekyll/scholar/tags/bibliography.rb
+10
-40
lib/jekyll/scholar/tags/cite.rb
lib/jekyll/scholar/tags/cite.rb
+6
-16
lib/jekyll/scholar/utilities.rb
lib/jekyll/scholar/utilities.rb
+65
-8
No files found.
lib/jekyll/scholar.rb
View file @
2095c4a3
...
...
@@ -5,36 +5,10 @@ require 'bibtex'
require
'citeproc'
require
'jekyll/scholar/version'
require
'jekyll/scholar/defaults'
require
'jekyll/scholar/utilities'
require
'jekyll/scholar/converters/bibtex'
require
'jekyll/scholar/tags/bibliography'
require
'jekyll/scholar/tags/cite'
require
'jekyll/scholar/generators/details'
module
Jekyll
class
Scholar
@defaults
=
Hash
[
*
%w{
style apa
locale en
sort_by none
order ascending
source ./_bibliography
bibliography references.bib
details_dir ./bibliography
details_layout bibtex.html
query @*
}
].
freeze
class
<<
self
attr_reader
:defaults
end
end
end
lib/jekyll/scholar/defaults.rb
0 → 100644
View file @
2095c4a3
module
Jekyll
class
Scholar
@defaults
=
Hash
[
*
%w{
style apa
locale en
sort_by none
order ascending
source ./_bibliography
bibliography references.bib
details_dir bibliography
details_layout bibtex.html
details_link Details
query @*
}
].
freeze
class
<<
self
attr_reader
:defaults
end
end
end
\ No newline at end of file
lib/jekyll/scholar/generators/details.rb
View file @
2095c4a3
...
...
@@ -2,15 +2,14 @@ module Jekyll
class
Scholar
class
Details
<
Page
attr_reader
:config
include
Scholar
::
Utilities
def
initialize
(
site
,
base
,
dir
,
entry
)
@site
,
@base
,
@dir
=
site
,
base
,
dir
@config
=
Scholar
.
defaults
.
merge
(
site
.
config
[
'scholar'
]
||
{})
@name
=
filenam
e_for
(
entry
)
@name
=
details_fil
e_for
(
entry
)
process
(
@name
)
read_yaml
(
File
.
join
(
base
,
'_layouts'
),
config
[
'details_layout'
])
...
...
@@ -20,14 +19,6 @@ module Jekyll
private
def
filename_for
(
entry
)
n
=
entry
.
key
.
dup
n
.
gsub!
(
/[:\s]+/
,
'_'
)
[
n
,
'html'
].
join
(
'.'
)
end
def
liquidify
(
entry
)
data
[
'entry'
]
=
{}
...
...
@@ -42,16 +33,17 @@ module Jekyll
end
class
DetailsGenerator
<
Generator
include
Scholar
::
Utilities
safe
true
attr_reader
:config
def
generate
(
site
)
@
config
=
Scholar
.
defaults
.
merge
(
site
.
config
[
'scholar'
]
||
{})
@
site
,
@config
=
site
,
Scholar
.
defaults
.
merge
(
site
.
config
[
'scholar'
]
||
{})
if
site
.
layouts
.
key?
(
File
.
basename
(
config
[
'details_layout'
],
'.html'
))
bibliography
[
config
[
'query'
]]
.
each
do
|
entry
|
details
=
Details
.
new
(
site
,
site
.
source
,
config
[
'details_dir'
]
,
entry
)
if
generate_details?
entries
.
each
do
|
entry
|
details
=
Details
.
new
(
site
,
site
.
source
,
details_path
,
entry
)
details
.
render
(
site
.
layouts
,
site
.
site_payload
)
details
.
write
(
site
.
dest
)
...
...
@@ -61,17 +53,6 @@ module Jekyll
end
end
private
def
bibliography
@bibliography
||=
BibTeX
.
open
(
bibliography_path
,
:filter
=>
:latex
)
end
def
bibliography_path
p
=
File
.
join
(
config
[
'source'
],
config
[
'bibliography'
])
p
<<
'.bib'
unless
File
.
exists?
(
p
)
p
end
end
...
...
lib/jekyll/scholar/tags/bibliography.rb
View file @
2095c4a3
...
...
@@ -2,65 +2,35 @@ module Jekyll
class
Scholar
class
BibliographyTag
<
Liquid
::
Tag
attr_reader
:file
,
:config
include
Scholar
::
Utilities
def
initialize
(
tag_name
,
arguments
,
tokens
)
super
@config
=
Scholar
.
defaults
.
dup
@file
=
arguments
.
strip
@
bibtex_
file
=
arguments
.
strip
end
def
render
(
context
)
config
.
merge!
(
context
.
registers
[
:site
].
config
[
'scholar'
]
||
{})
@site
=
context
.
registers
[
:site
]
config
.
merge!
(
site
.
config
[
'scholar'
]
||
{})
references
=
entries
.
map
do
|
e
|
r
=
CiteProc
.
process
e
.
to_citeproc
,
:style
=>
config
[
'style'
],
r
eference
=
CiteProc
.
process
e
.
to_citeproc
,
:style
=>
config
[
'style'
],
:locale
=>
config
[
'locale'
],
:format
=>
'html'
r
=
"<span id='
#{
e
.
key
}
'>
#{
r
}
</span>"
if
e
.
field?
(
:url
)
r
<<
"<a href='
#{
e
.
url
}
'>URL</a>"
end
reference
=
"<span id='
#{
e
.
key
}
'>
#{
reference
}
</span>"
if
e
.
field?
(
:doi
)
r
<<
"<a href='
#{
e
.
doi
}
'>DOI</a>"
if
generate_details?
r
eference
<<
"<a href='
#{
details_link_for
(
e
)
}
'>
#{
config
[
'details_link'
]
}
</a>"
end
"<li>
#{
r
}
</li>"
"<li>
#{
r
eference
}
</li>"
end
"<ol>
\n
#{
references
.
join
(
"
\n
"
)
}
\n
</ol>"
end
private
def
bibliography
@bibliography
||=
BibTeX
.
open
(
extend_path
(
file
),
:filter
=>
:latex
)
end
def
entries
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
def
extend_path
(
name
)
if
name
.
nil?
||
name
.
empty?
name
=
config
[
'bibliography'
]
end
p
=
File
.
join
(
config
[
'source'
],
name
)
p
<<
'.bib'
unless
File
.
exists?
(
p
)
p
end
end
end
...
...
lib/jekyll/scholar/tags/cite.rb
View file @
2095c4a3
...
...
@@ -2,6 +2,7 @@ module Jekyll
class
Scholar
class
CiteTag
<
Liquid
::
Tag
include
Scholar
::
Utilities
attr_reader
:key
,
:pages
,
:config
...
...
@@ -15,29 +16,18 @@ module Jekyll
def
render
(
context
)
config
.
merge!
(
context
.
registers
[
:site
].
config
[
'scholar'
]
||
{})
e
=
bibliography
[
key
]
e
ntry
=
bibliography
[
key
]
if
e
c
=
CiteProc
.
process
e
.
to_citeproc
,
:style
=>
config
[
'style'
],
if
e
ntry
c
=
CiteProc
.
process
e
ntry
.
to_citeproc
,
:style
=>
config
[
'style'
],
:locale
=>
config
[
'locale'
],
:format
=>
'html'
,
:mode
=>
:citation
"<a href='#
#{
e
.
key
}
'>
#{
c
}
</a>"
"<a href='#
#{
e
ntry
.
key
}
'>
#{
c
}
</a>"
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
...
...
lib/jekyll/scholar/utilities.rb
View file @
2095c4a3
module
Jekyll
class
Scholar
# Utility methods used by several Scholar plugins. The methods in this
# module may depend on the presence of #config, #bibtex_file, and
# #site readers
module
Utilities
attr_reader
:bibtex_file
,
:config
,
:site
def
bibtex_options
@bibtex_options
||=
{
:filter
=>
:latex
}
end
def
bibtex_path
@bibtex_path
||=
extend_path
(
bibtex_file
)
end
def
bibliography
@bibliography
||=
BibTeX
.
open
(
bibtex_path
,
bibtex_options
)
end
def
entries
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
def
extend_path
(
name
)
if
name
.
nil?
||
name
.
empty?
name
=
config
[
'bibliography'
]
end
p
=
File
.
join
(
config
[
'source'
],
name
)
p
<<
'.bib'
unless
File
.
exists?
(
p
)
p
end
def
generate_details?
site
.
layouts
.
key?
(
File
.
basename
(
config
[
'details_layout'
],
'.html'
))
end
def
details_file_for
(
entry
)
name
=
entry
.
key
.
to_s
.
dup
name
.
gsub!
(
/[:\s]+/
,
'_'
)
[
name
,
'html'
].
join
(
'.'
)
end
def
details_link_for
(
entry
)
[
site
.
source
,
details_path
,
details_file_for
(
entry
)].
join
(
'/'
)
end
def
details_path
config
[
'details_dir'
]
end
end
...
...
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