Class: Jekyll::CiteTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::CiteTag
- Defined in:
- lib/jekyll-cite.rb
Instance Method Summary collapse
-
#initialize(tag_name, text, tokens) ⇒ CiteTag
constructor
A new instance of CiteTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ CiteTag
7 8 9 10 |
# File 'lib/jekyll-cite.rb', line 7 def initialize(tag_name, text, tokens) super @ref = text end |
Instance Method Details
#render(context) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll-cite.rb', line 12 def render(context) # Retrieve references from page refs = context.registers[:page]["references"] # Parse references to contain only the IDs refs.map! { |ref| ref[0] } # Build output output = '' # Check if index exists if refs.index(@ref).nil? # If it does not exist, set to question mark with no link output = '<sup>?</sup>' else # If it does exist output = "<sup><a href=\"#ref-#{@ref}\">#{refs.index(@ref) + 1}</a></sup>" end # Return output output end |