Commit 38807854 authored by rmrf's avatar rmrf

Starting to up the version to match jekyll-scholar-5.7.x

parent de9c4a1d
require 'jekyll/scholar'
require 'jekyll/scholar/extras/extra_utils'
#require 'jekyll/scholar/extras/extra_utils'
require 'jekyll/scholar/extras/bibliography_hdp'
require 'jekyll/scholar/extras/bibliography_bytype'
require 'jekyll/scholar/extras/details_hdp'
#require 'jekyll/scholar/extras/details_hdp'
#require 'jekyll/scholar/tags/cite_details_dep'
module Jekyll
class Scholar
class BibliographyHDPByTypeTag < Liquid::Tag
class BibliographyTagByType < Liquid::Tag
include Scholar::Utilities
include ScholarExtras::Utilities
attr_reader :type, :header, :arr_args
def initialize(tag_name, arguments, tokens)
super
@config = Scholar.defaults.dup
# Check for number of arguments.
#@arr_args = arguments.strip.split(/\s+/)
@type, @header= arguments.strip.split(/\s*,\s*/, 2)
#@type= arr_args[0]
#@header = arr_args[1]
optparse(arguments)
end
def initialize_type_labels()
@type_labels = Hash[{
"@article" => "Journal Articles",
"@inproceedings" => "Conference and Workshop Papers",
"@incollection" => "Book Chapters",
"@techreport" => "Technical Reports",
"@book" => "Books"
}]
end
def initialize_prefix_defaults()
@prefix_defaults = Hash[{
:article => "J",
:inproceedings => "C",
:incollection=> "BC",
:techreport => "TR",
:book => "B"
}]
end
def set_type_counts(tc)
@type_counts = tc
end
def render_index(item, ref)
si = '[' + @prefix_defaults[item.type].to_s + @type_counts.to_s + ']'
@type_counts = @type_counts - 1
idx_html = content_tag "div class=\"csl-index\"", si
return idx_html + ref
end
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"
}]
s = css_points[item.type]
return s
end
def render_header(y)
ys = content_tag "h2 class=\"csl-year-header\"", y
ys = content_tag "div class=\"csl-year-icon\"", ys
end
def render(context)
set_context_to context
year_section = ''
opts = ['@' + @type,'@*[public!=no]']
# Only select items that are public.
items = entries.select { |e| e.public == 'yes' }
references = get_entries(opts).map do |entry|
reference = ''
ref = ''
initialize_prefix_defaults()
initialize_type_labels()
set_type_counts(items.size())
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 << "."
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
end
if entry.field?(:pdflink1) or entry.field?(:slides)
reference << "<b> Downloads: </b>"
end
items = items[offset..max] if limit_entries?
if entry.field?(:pdflink1)
reference << "<a href=\"" + entry[:pdflink1].to_s + "\">PDF</a>"
bibliography = render_header(@type_labels[query])
bibliography << items.each_with_index.map { |entry, index|
reference = render_index(entry, bibliography_tag(entry, nil))
if generate_details?
reference << link_to(details_link_for(entry),
config['details_link'], :class => config['details_link_class'])
end
if entry.field?(:slides)
reference << "<a href=\"" + entry[:slides].to_s + "\">Slides</a>"
if entry.field?(:award)
# TODO: Awkward -- Find position to insert it. Before the last </div>
ts = content_tag "div class=\"csl-award\"", entry.award.to_s
refPos = reference.rindex('</div>')
if refPos.nil?
puts "NILL"
else
reference.insert(reference.rindex('</div>'), ts.to_s)
end
end
content_tag :br, reference
end
section_header = "<h1> #{@header} </h1>"
references.insert(0,section_header)
references.join("\n")
content_tag config['bibliography_item_tag'], reference
content_tag "li class=\"" + render_ref_img(entry) + "\"", reference
}.join("\n")
content_tag config['bibliography_list_tag'], bibliography, :class => config['bibliography_class']
end
end
end
end
Liquid::Template.register_tag('bibliography_bytype', Jekyll::Scholar::BibliographyHDPByTypeTag)
Liquid::Template.register_tag('bibliography_bytype', Jekyll::Scholar::BibliographyTagByType)
module Jekyll
class Scholar
class BibliographyTagYear < Liquid::Tag
include Scholar::Utilities
def initialize(tag_name, arguments, tokens)
super
@config = Scholar.defaults.dup
optparse(arguments)
end
def initialize_type_counts()
@type_counts = Hash[{
:article => 0,
:inproceedings => 0,
:incollection=> 0,
:techreport => 0,
:book => 0
}]
@type_counts.keys.each { |t|
bib = bibliography.query('@*') { |b|
(b.public == 'yes' and b.type == t)
}
@type_counts[t] = bib.size
}
end
def initialize_type_order()
@type_order = Hash[{
:article => 0,
:book => 0,
:incollection=> 0,
:inproceedings => 0,
:techreport => 0
}]
end
def initialize_prefix_defaults()
@prefix_defaults = Hash[{
:article => "J",
:inproceedings => "C",
:incollection=> "BC",
:techreport => "TR",
:book => "B"
}]
end
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"
}]
s = css_points[item.type]
return s
end
def get_entries_by_type(year, type)
b = bibliography.query('@*') { |item|
(item.year == year and item.type == type)
}
end
def render_year(y)
ys = content_tag "h2 class=\"csl-year-header\"", y
ys = content_tag "div class=\"csl-year-icon\"", ys
# content_tag "h2", y
end
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
def entries_year(year)
b = bibliography.query('@*') {
|a| (a.year == year and a.public == 'yes')
}
end
def initialize_unique_years()
# Get an array of years and then uniquify them.
items = entries
arr = Array.new
items.each { |i| arr.push(i.year.to_s) }
@arr_unique = arr.uniq
end
def render(context)
set_context_to context
# Initialize the number of each type of interest.
initialize_type_counts()
initialize_type_order()
initialize_prefix_defaults()
initialize_unique_years()
# Iterate over unique years, and produce the bib.
bibliography =""
@arr_unique.each { |y|
bibliography << render_year(y)
@type_order.keys.each { |o|
items = entries_year(y).select { |e| e.type == o }
bibliography << items.each_with_index.map { |entry, index|
if entry.type == o then
reference = render_index(entry, bibliography_tag(entry, nil))
if entry.field?(:award)
# TODO: Awkward -- Find position to insert it. Before the last </div>
ts = content_tag "div class=\"csl-award\"", entry.award.to_s
puts ts
puts ts.to_s
refPos = reference.rindex('</div>')
if refPos.nil?
puts "NILL"
else
puts "INSERT\n"
puts ts
reference.insert( reference.rindex('</div>'), ts.to_s )
end
end
# Content tag is dependent on type of article.
content_tag "li class=\"" + render_ref_img(entry) + "\"", reference
end
}.join("\n")
}.join("\n")
}.join("")
return content_tag config['bibliography_list_tag'], bibliography, :class => config['bibliography_class']
end
end
end
end
Liquid::Template.register_tag('bibliography_year', Jekyll::Scholar::BibliographyTagYear)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment