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

Sylvester Keil's avatar
Sylvester Keil committed
18
19
20
21
22
23
24
25
26
27
28
29
        items = entries

        if cited_only?
          items = if skip_sort?
            cited_references.uniq.map do |key|
              items.detect { |e| e.key == key }
            end
          else
            entries.select do |e|
              cited_references.include? e.key
            end
          end
30
31
32

          # See #90
          cited_keys.clear
Sylvester Keil's avatar
Sylvester Keil committed
33
        end
34

Sylvester Keil's avatar
Sylvester Keil committed
35
        items = items.take(max.to_i) if limit_entries?
Sylvester Keil's avatar
Sylvester Keil committed
36

Sylvester Keil's avatar
Sylvester Keil committed
37
        bibliography = items.each_with_index.map { |entry, index|
38
          reference = bibliography_tag(entry, index + 1)
39

40
          if generate_details?
41
42
            reference << link_to(details_link_for(entry),
              config['details_link'], :class => config['details_link_class'])
Sylvester Keil's avatar
Sylvester Keil committed
43
          end
44

45
          content_tag config['bibliography_item_tag'], reference
46
        }.join("\n")
Sylvester Keil's avatar
Sylvester Keil committed
47

48
        content_tag config['bibliography_list_tag'], bibliography, :class => config['bibliography_class']
49

50
      end
51
    end
52

53
54
55
  end
end

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