cite.rb 842 Bytes
Newer Older
1 2 3 4
module Jekyll
  class Scholar

    class CiteTag < Liquid::Tag
5 6
      include Scholar::Utilities
      
7 8 9 10 11 12 13 14 15 16 17 18
      attr_reader :key, :pages, :config
    
      def initialize(tag_name, arguments, tokens)
        super
        
        @config = Scholar.defaults.dup
        @key = arguments.strip.split(/\s+/)[0]
      end

      def render(context)
        config.merge!(context.registers[:site].config['scholar'] || {})

19
        entry = bibliography[key]
Sylvester Keil's avatar
Sylvester Keil committed
20

21 22
        if entry
          c = CiteProc.process entry.to_citeproc, :style => config['style'],
23
            :locale => config['locale'], :format => 'html', :mode => :citation
Sylvester Keil's avatar
Sylvester Keil committed
24
          
25
          "<a href='##{entry.key}'>#{c}</a>"
26 27 28 29 30 31 32 33 34 35 36
        else
          "(missing reference)"
        end
      end
      
    end
    
  end
end

Liquid::Template.register_tag('cite', Jekyll::Scholar::CiteTag)