bibliography.rb 1.04 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

Sylvester Keil's avatar
Sylvester Keil committed
20
21
22
        references.select! do |e|
          cited_references.include? e.key
        end if cited_only?
23

Sylvester Keil's avatar
Sylvester Keil committed
24
25
        references = references.take(max.to_i) if limit_entries?

Sylvester Keil's avatar
Sylvester Keil committed
26
        bibliography = references.each_with_index.map { |entry, index|
27
          reference = bibliography_tag(entry, index + 1)
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
35
        }.join("\n")
Sylvester Keil's avatar
Sylvester Keil committed
36

37
        content_tag :ol, bibliography, :class => config['bibliography_class']
38
      end
39
    end
40

41
42
43
  end
end

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