bibliography.rb 1.2 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, @query = arguments.strip.split(/\s*filter:\s*/)
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
        content_tag :ol, references.join("\n"), :class => config['bibliography_class']
32
      end
33
    end
34

35
    private
36

37
38
39
40
41
42
43
    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)