bibliography.rb 1.21 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)
Sylvester Keil's avatar
Sylvester Keil committed
15
        set_context_to context
16

Sylvester Keil's avatar
Sylvester Keil committed
17
18
        references = entries.map do |entry|
          reference = CiteProc.process entry.to_citeproc, :style => config['style'],
19
            :locale => config['locale'], :format => 'html'
20
        
Sylvester Keil's avatar
Sylvester Keil committed
21
          reference = content_tag :span, reference, :id => entry.key
22
        
23
          if generate_details?
24
25
            reference << link_to(details_link_for(entry),
              config['details_link'], :class => config['details_link_class'])
Sylvester Keil's avatar
Sylvester Keil committed
26
          end
27
        
Sylvester Keil's avatar
Sylvester Keil committed
28
          content_tag :li, reference
Sylvester Keil's avatar
Sylvester Keil committed
29
        end
Sylvester Keil's avatar
Sylvester Keil committed
30

31
32
        content_tag :ol, references.join("\n"), :class => config['bibliography_class']
      end      
33
34
    end
    
35
36
37
38
39
40
41
42
43
    private
    
    def citeproc
      @citeproc ||= CiteProc::Processor.new do |p|
        p.style = config['style']
        p.format = 'html'
        p.locale = config['locale']
      end
    end
44
45
46
47
  end
end

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