bibliography.rb 1.66 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
20
21
22
23
24
25
26
27
        # Add bibtex files to dependency tree
        if context.registers[:page] and context.registers[:page].has_key? "path"
          bibtex_paths.each do |bibtex_path|
            site.regenerator.add_dependency(
              site.in_source_dir(context.registers[:page]["path"]),
              bibtex_path
            )
          end
        end

Sylvester Keil's avatar
Sylvester Keil committed
28
29
30
31
32
33
34
35
36
37
38
39
        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
40
41
42

          # See #90
          cited_keys.clear
Sylvester Keil's avatar
Sylvester Keil committed
43
        end
44

egon w. stemle's avatar
egon w. stemle committed
45
        items = items[offset..max] if limit_entries?
Sylvester Keil's avatar
Sylvester Keil committed
46

Sylvester Keil's avatar
Sylvester Keil committed
47
        bibliography = items.each_with_index.map { |entry, index|
48
          reference = bibliography_tag(entry, index + 1)
49

50
          if generate_details?
51
52
            reference << link_to(details_link_for(entry),
              config['details_link'], :class => config['details_link_class'])
Sylvester Keil's avatar
Sylvester Keil committed
53
          end
54

55
          content_tag config['bibliography_item_tag'], reference
56
        }.join("\n")
Sylvester Keil's avatar
Sylvester Keil committed
57

58
        content_tag config['bibliography_list_tag'], bibliography, :class => config['bibliography_class']
59

60
      end
61
    end
62

63
64
65
  end
end

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