Skip to content

Commit

Permalink
add institute and institute_short tags
Browse files Browse the repository at this point in the history
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
torbjoernk committed Feb 12, 2016
1 parent f87b801 commit ba8555e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 24 deletions.
65 changes: 65 additions & 0 deletions _plugins/institute_tag.rb
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)
30 changes: 9 additions & 21 deletions _plugins/person_tag.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require_relative './institute_tag'


module Jekyll
module Tags
class RenderPersonTagError < StandardError
Expand All @@ -12,7 +15,6 @@ def initialize(tag_name, markup, tokens)
@person_id = markup.strip
@person = nil
@people
@affiliations = nil
end

def get_person(context)
Expand Down Expand Up @@ -43,22 +45,8 @@ def get_affiliations(context)
raise RenderPersonTagError.new "PersonID '#{@person_id}' has no 'affiliation' defined."
end

affies = context.registers[:site].data['orgs']

if @person['affiliation'].is_a?(String)
person_affies = [@person['affiliation']]
else
person_affies = @person['affiliation']
end

@affiliations = []
for affi in person_affies
unless affies.has_key?(affi)
raise RenderPersonTagError.new \
"AffiliationID '#{affi}' not found. Type? Otherwise add it to _data/orgs.yml."
end

@affiliations << affies[affi]
@person['affiliation'] = [@person['affiliation']]
end
end

Expand All @@ -81,10 +69,10 @@ def construct_name
end

module AffiliationsTrait
def construct_affiliation
def construct_affiliation(context)
affies = []
for affi in @affiliations
affies << "<abbr class=\"person affiliation\" title=\"#{affi['title']}\">#{affi['abbr']}</abbr>"
for affi in @person['affiliation']
affies << Liquid::Template.parse("{% institute_short #{affi} %}").render(context)
end

affies.join(', ')
Expand All @@ -98,7 +86,7 @@ class RenderPersonTag < PersonBaseTag

def render(context)
super(context)
"#{construct_name} (#{construct_affiliation})"
"#{construct_name} (#{construct_affiliation(context)})"
end
end

Expand All @@ -117,7 +105,7 @@ class RenderPersonInverseTag < PersonBaseTag

def render(context)
super(context)
"#{construct_name} (#{construct_affiliation})"
"#{construct_name} (#{construct_affiliation(context)})"
end
end

Expand Down
4 changes: 1 addition & 3 deletions about/people.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ subnavbar: People
</td>
<td class="col-affiliation">
{% for affi in person.affiliation %}
<abbr title="{{ site.data.orgs[affi].title }}" class="initialism">
{{ site.data.orgs[affi].abbr }}
</abbr>
{% institute_short {{ affi }} %}
{% unless forloop.last %}
,
{% endunless %}
Expand Down

0 comments on commit ba8555e

Please sign in to comment.