bibliography_bytype.rb 1.77 KB
Newer Older
1 2 3 4 5 6 7
module Jekyll
  class Scholar

    class BibliographyHDPByTypeTag < Liquid::Tag
      include Scholar::Utilities
      include ScholarExtras::Utilities
  
rmrf's avatar
rmrf committed
8 9
      attr_reader :type, :header, :arr_args

10 11 12 13
      def initialize(tag_name, arguments, tokens)
        super

        @config = Scholar.defaults.dup
rmrf's avatar
rmrf committed
14 15 16 17
        # Check for number of arguments.
        @arr_args = arguments.strip.split(/\s+/)
        @type= arr_args[0]
        @header = arr_args[1]
18 19 20 21 22 23
      end

      def render(context)
        set_context_to context

         year_section = ''
rmrf's avatar
rmrf committed
24
         opts = ['@' + @type,'@*[public!=no]']
rmrf's avatar
rmrf committed
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
        references = get_entries(opts).map do |entry|
          reference = ''
          ref = ''

          ref = CiteProc.process entry.to_citeproc, :style => config['style'],
            :locale => config['locale'], :format => 'html'
          content_tag :span, ref, :id => entry.key

          reference << ref
          if generate_details?
           reference << "<br />"
           reference << link_to(details_link_for(entry), config['details_link'])
           reference << "."
          end

rmrf's avatar
rmrf committed
41
          if entry.field?(:pdflink1) or entry.field?(:slides)
42 43 44 45 46 47 48 49
            reference << "<b> Downloads: </b>" 
          end 

          if entry.field?(:pdflink1)
            reference << "<a href=\"" + entry[:pdflink1].to_s + "\">PDF</a>"

          end
          
rmrf's avatar
rmrf committed
50 51
          if entry.field?(:slides)
            reference << "<a href=\"" + entry[:slides].to_s + "\">Slides</a>"
52 53 54 55 56

          end

          content_tag :br, reference
        end
rmrf's avatar
rmrf committed
57
         
rmrf's avatar
rmrf committed
58
         section_header = "<h1> #{@header} </h1>"
rmrf's avatar
rmrf committed
59
 
rmrf's avatar
rmrf committed
60
        references.insert(0,section_header)
61 62 63 64 65 66 67 68
        references.join("\n")
      end
    end
    
  end
end

Liquid::Template.register_tag('bibliography_bytype', Jekyll::Scholar::BibliographyHDPByTypeTag)