bibliography.rb 1.02 KB
Newer Older
1 2 3 4
module Jekyll
  class Scholar

    class BibliographyTag < Liquid::Tag
5
      include Scholar::Utilities
6 7 8
  
      def initialize(tag_name, arguments, tokens)
        super
Sylvester Keil's avatar
Sylvester Keil committed
9

10
        @config = Scholar.defaults.dup
11
        @bibtex_file = arguments.strip
12 13 14
      end

      def render(context)
15 16
        @site = context.registers[:site]
        config.merge!(site.config['scholar'] || {})
17

Sylvester Keil's avatar
Sylvester Keil committed
18
        references = entries.map do |e|
19
          reference = CiteProc.process e.to_citeproc, :style => config['style'],
20
            :locale => config['locale'], :format => 'html'
Sylvester Keil's avatar
Sylvester Keil committed
21
                    
22
          reference = "<span id='#{e.key}'>#{reference}</span>"
Sylvester Keil's avatar
Sylvester Keil committed
23
          
24 25
          if generate_details?
            reference << "<a href='#{details_link_for(e)}'>#{config['details_link']}</a>"            
Sylvester Keil's avatar
Sylvester Keil committed
26
          end
27 28
                    
          "<li>#{reference}</li>"
Sylvester Keil's avatar
Sylvester Keil committed
29
        end
Sylvester Keil's avatar
Sylvester Keil committed
30

Sylvester Keil's avatar
Sylvester Keil committed
31
        "<ol>\n#{references.join("\n")}\n</ol>"
32 33 34 35 36 37 38 39
      end
      
    end
    
  end
end

Liquid::Template.register_tag('bibliography', Jekyll::Scholar::BibliographyTag)