bibliography.rb 1.18 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
12

        optparse(arguments)
13
14
15
      end

      def render(context)
Sylvester Keil's avatar
Sylvester Keil committed
16
        set_context_to context
17

18
19
        references = entries

20
        if cited_only?
21
22
23
24
25
26
          references = cited_references.map do |key|
            references.detect { |e| e.key == key }
          end          
        end

        references.map! do |entry|
Sylvester Keil's avatar
Sylvester Keil committed
27
          reference = bibliography_tag entry
28

29
          if generate_details?
30
31
            reference << link_to(details_link_for(entry),
              config['details_link'], :class => config['details_link_class'])
Sylvester Keil's avatar
Sylvester Keil committed
32
          end
33

Sylvester Keil's avatar
Sylvester Keil committed
34
          content_tag :li, reference
Sylvester Keil's avatar
Sylvester Keil committed
35
        end
Sylvester Keil's avatar
Sylvester Keil committed
36

37
        content_tag :ol, references.join("\n"), :class => config['bibliography_class']
38
      end
39
    end
40

41
    private
42

43
44
45
46
47
48
49
    def citeproc
      @citeproc ||= CiteProc::Processor.new do |p|
        p.style = config['style']
        p.format = 'html'
        p.locale = config['locale']
      end
    end
50
51
52
53
  end
end

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