-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
institute
and institute_short
tags
also for breaking the build when wrong ID given the `person` tag now uses the institute tag for lookup and rendering of the affiliation Signed-off-by: Torbjörn Klatt <[email protected]>
- Loading branch information
1 parent
f87b801
commit ba8555e
Showing
3 changed files
with
75 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Jekyll | ||
module Tags | ||
class RenderInstituteTagError < StandardError | ||
def initialize(msg) | ||
super(msg) | ||
end | ||
end | ||
|
||
class RenderInstituteBaseTag < Liquid::Tag | ||
def initialize(tag_name, markup, tokens) | ||
super | ||
@markup = markup.strip | ||
@institute = nil | ||
@institutes = nil | ||
end | ||
|
||
def get_institute(context) | ||
@institutes = context.registers[:site].data['orgs'] | ||
|
||
@institute_id = Liquid::Template.parse(@markup).render(context) | ||
|
||
if @institutes.has_key?(@institute_id) | ||
@institute = @institutes[@institute_id] | ||
else | ||
raise RenderInstituteTagError.new \ | ||
"InstituteID '#{@institute_id}' not found. Probably a typo? See _data/orgs.yml." | ||
end | ||
end | ||
|
||
def render(context) | ||
"#{construct_institute(context)}" | ||
end | ||
end | ||
|
||
class RenderInstituteTag < RenderInstituteBaseTag | ||
def construct_institute(context) | ||
get_institute(context) | ||
|
||
unless @institute.has_key?('title') | ||
raise RenderInstituteTagError.new "InstituteID '#{@institute_id}' has no 'title' defined." | ||
end | ||
|
||
"<span class=\"institute\">#{@institute['title']}</span>" | ||
end | ||
end | ||
|
||
class RenderInstituteShortTag < RenderInstituteBaseTag | ||
def construct_institute(context) | ||
get_institute(context) | ||
|
||
unless @institute.has_key?('title') | ||
raise RenderInstituteTagError.new "InstituteID '#{@institute_id}' has no 'title' defined." | ||
end | ||
unless @institute.has_key?('abbr') | ||
raise RenderInstituteTagError.new "InstituteID '#{@institute_id}' has no 'abbr' defined." | ||
end | ||
|
||
"<abbr title=\"#{@institute['title']}\" class=\"initialism\">#{@institute['abbr']}</abbr>" | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag('institute', Jekyll::Tags::RenderInstituteTag) | ||
Liquid::Template.register_tag('institute_short', Jekyll::Tags::RenderInstituteShortTag) |
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