Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
caesr-pub
jekyll-scholar
Commits
9c258e1c
Commit
9c258e1c
authored
Apr 30, 2012
by
Sylvester Keil
Browse files
improved utility functions
#1
parent
5fa5e079
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
17 deletions
+41
-17
lib/jekyll/scholar/tags/bibliography.rb
lib/jekyll/scholar/tags/bibliography.rb
+10
-11
lib/jekyll/scholar/tags/cite.rb
lib/jekyll/scholar/tags/cite.rb
+4
-4
lib/jekyll/scholar/utilities.rb
lib/jekyll/scholar/utilities.rb
+27
-2
No files found.
lib/jekyll/scholar/tags/bibliography.rb
View file @
9c258e1c
...
...
@@ -12,23 +12,22 @@ module Jekyll
end
def
render
(
context
)
@site
=
context
.
registers
[
:site
]
config
.
merge!
(
site
.
config
[
'scholar'
]
||
{})
set_context_to
context
references
=
entries
.
map
do
|
e
|
reference
=
CiteProc
.
process
e
.
to_citeproc
,
:style
=>
config
[
'style'
],
references
=
entries
.
map
do
|
e
ntry
|
reference
=
CiteProc
.
process
e
ntry
.
to_citeproc
,
:style
=>
config
[
'style'
],
:locale
=>
config
[
'locale'
],
:format
=>
'html'
reference
=
"<span id='
#{
e
.
key
}
'>
#{
reference
}
</span>"
reference
=
content_tag
:span
,
reference
,
:id
=>
entry
.
key
if
generate_details?
reference
<<
"<a href='
#{
details_link_for
(
e
)
}
'>
#{
config
[
'details_link'
]
}
</a>"
reference
<<
link_to
(
details_link_for
(
e
ntry
),
config
[
'details_link'
]
)
end
"<li>
#{
reference
}
</li>"
content_tag
:li
,
reference
end
"<ol>
\n
#{
references
.
join
(
"
\n
"
)
}
\n
</ol>"
content_tag
:ol
,
references
.
join
(
"
\n
"
)
end
end
...
...
lib/jekyll/scholar/tags/cite.rb
View file @
9c258e1c
...
...
@@ -14,15 +14,15 @@ module Jekyll
end
def
render
(
context
)
config
.
merge!
(
context
.
registers
[
:site
].
config
[
'scholar'
]
||
{})
set_context_to
context
entry
=
bibliography
[
key
]
if
entry
c
=
CiteProc
.
process
entry
.
to_citeproc
,
:style
=>
config
[
'style'
],
c
itation
=
CiteProc
.
process
entry
.
to_citeproc
,
:style
=>
config
[
'style'
],
:locale
=>
config
[
'locale'
],
:format
=>
'html'
,
:mode
=>
:citation
"<a href='
#
#{
entry
.
key
}
'>
#{
c
}
</a>"
link_to
"
#
#{
entry
.
key
}
"
,
citation
else
"(missing reference)"
end
...
...
lib/jekyll/scholar/utilities.rb
View file @
9c258e1c
...
...
@@ -53,14 +53,39 @@ module Jekyll
[
name
,
'html'
].
join
(
'.'
)
end
def
details_link_for
(
entry
)
[
site
.
sourc
e
,
details_path
,
details_file_for
(
entry
)].
join
(
'/'
)
def
details_link_for
(
entry
,
base
=
site
.
config
[
'baseurl'
]
||
'/'
)
[
bas
e
,
details_path
,
details_file_for
(
entry
)].
compact
.
join
(
'/'
)
end
def
details_path
config
[
'details_dir'
]
end
def
content_tag
(
name
,
content_or_attributes
,
attributes
=
{})
if
content_or_attributes
.
is_a?
(
Hash
)
content
,
attributes
=
nil
,
content_or_attributes
else
content
=
content_or_attributes
end
attributes
=
attributes
.
map
{
|
k
,
v
|
%Q(
#{
k
}
="
#{
v
}
")
}
if
content
.
nil?
"<
#{
[
name
,
attributes
].
flatten
.
compact
.
join
(
' '
)
}
/>"
else
"<
#{
[
name
,
attributes
].
flatten
.
compact
.
join
(
' '
)
}
>
#{
content
}
</
#{
name
}
>"
end
end
def
link_to
(
href
,
content
,
attributes
=
{})
content_tag
:a
,
content
||
href
,
attributes
.
merge
(
:href
=>
href
)
end
def
set_context_to
(
context
)
@site
=
context
.
registers
[
:site
]
config
.
merge!
(
site
.
config
[
'scholar'
]
||
{})
end
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