-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d14028
commit 31bc029
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'utils' | ||
|
||
module Jekyll | ||
module Figure | ||
|
||
class FigRefTag < Liquid::Tag | ||
include Utils | ||
|
||
def initialize(tag_name, markup, tokens) | ||
@label = markup | ||
super | ||
end | ||
|
||
def render(context) | ||
@context = context | ||
print_reference(@label) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag("figref", Jekyll::Figure::FigRefTag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Jekyll | ||
module Figure | ||
module Utils | ||
|
||
class I18n | ||
@figure_i18n = {'en' => "Figure", | ||
'de' => "Abbildung", | ||
'sv' => "Figur", | ||
'fr' => "Figure"} | ||
def self.figure(lang) | ||
return @figure_i18n[lang] if @figure_i18n.key?(lang) | ||
@figure_i18n['en'] | ||
end | ||
end | ||
|
||
def lang | ||
return @context.registers[:page]["lang"].to_s if @context.registers[:page].key?("lang") | ||
"en".to_s | ||
end | ||
|
||
def figure | ||
return @context.registers[:page]["figure"].to_s if @context.registers[:page].key?("figure") | ||
I18n.figure(lang) | ||
end | ||
|
||
def print_figure_counter(label) | ||
label.gsub!(/\s/, '') | ||
@context.registers[:page]["figure_labels"] ||= {} | ||
|
||
if @context.registers[:page]["figure_labels"].key?(label) | ||
value = @context.registers[:page]["figure_labels"][label] | ||
else | ||
value = @context.registers[:page]["figure_labels"].length + 1 | ||
@context.registers[:page]["figure_labels"][label] = value | ||
end | ||
"<em>" + figure + " " + value.to_s + ":</em> " | ||
end | ||
|
||
def print_reference(label) | ||
label.gsub!(/\s/, '') | ||
"<a href=\"\##{label.to_s}\">" + | ||
@context.registers[:page]["figure_labels"][label.to_s].to_s + | ||
"</a>" | ||
end | ||
end | ||
end | ||
end |