extras_utilities.rb 2.48 KB
Newer Older
1 2 3
module Jekyll
  module ScholarExtras

rmrf's avatar
rmrf committed
4 5 6 7
    # Return the extra configurations for parsing.
    def extra_parse_fields
      return @config_extras['parse_extra_fields']
    end
8

rmrf's avatar
rmrf committed
9 10 11 12 13 14 15 16
    # Generate the index using csl-index.
    def render_index(item, ref)
      si = '[' + @prefix_defaults[item.type].to_s + @type_counts[item.type].to_s + ']'
      @type_counts[item.type] = @type_counts[item.type].to_i - 1
      
      idx_html = content_tag "div class=\"csl-index\"", si
      return idx_html + ref
    end
17

rmrf's avatar
rmrf committed
18 19 20 21 22 23 24 25 26
    # Generate the publication type images.
    def render_ref_img(item)
      css_points = Hash[{
                          :article => "csl-point-journal-icon",
                          :inproceedings => "csl-point-conference-icon",
                          :incollection=> "csl-point-bookchapter-icon",
                          :techreport => "csl-point-techreport-icon",
                          :book => "csl-point-book-icon"
                        }]
27

rmrf's avatar
rmrf committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
      s = css_points[item.type]
      return s
    end

    # Look at the defaults for prefixes.
    # TODO: Should move this to defaults.
    def initialize_prefix_defaults() 
      @prefix_defaults = Hash[{
                                :article => "J",
                                :inproceedings => "C",
                                :incollection=> "BC",
                                :techreport => "TR",
                                :book => "B"
                              }]
    end
43

rmrf's avatar
rmrf committed
44
    # Generate a link if an ACM PDF link exists.
45 46 47 48 49
    def render_acmpdf_link(entry)
      pdflink =""
      if entry.field?(:acmpdflink)
        pdflink = "<div class=\"pure-button csl-pdf\"><a href=\"" + entry.acmpdflink.to_s + "\">PDF</a></div>"
      end
rmrf's avatar
rmrf committed
50
      
51 52
      return pdflink
    end
rmrf's avatar
rmrf committed
53

rmrf's avatar
rmrf committed
54
    # Generate a SLIDES link. 
rmrf's avatar
rmrf committed
55 56 57 58 59 60
    def repository_slides_link_for(entry, base = base_url)
      links = repository[entry.key + "_slides"]
      url = links['pdf'] || links['pptx']
      return unless url

      File.join(base, url)
rmrf's avatar
rmrf committed
61
    end
62

63 64 65 66 67 68
    # Generate a BibTeX link. 
    def bibtex_link_for(entry, base = base_url)
      url=entry.key + ".bib"
      return base + url 
    end
    
rmrf's avatar
rmrf committed
69 70
    def split_reference(reference)
      puts "## " + reference.to_s
71
#      puts "\n"
rmrf's avatar
rmrf committed
72
      if !reference.nil? 
73 74 75 76 77 78 79
        xml = Nokogiri::HTML(reference.to_s)
        puts "====B======"
 #       puts xml.css("div.csl-index")
        xml.css("div.csl-block.csl-title").each do |node|
          puts "==> " + node.text
        end
        puts "====E====="
rmrf's avatar
rmrf committed
80
      end
81
    end
rmrf's avatar
rmrf committed
82

83 84 85
  end 

end