Commit 1e8100cc authored by rmrf's avatar rmrf
Browse files

Push jekyll-scholar-extras 0.1.5 to github

parents
*.gem
*.rbc
.bundle
.config
coverage
InstalledFiles
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
# YARD artifacts
.yardoc
_yardoc
doc/
variables:
VERSION: "0.1.4"
image: ruby:2.2
stages:
- setup-extras
- make-extras
#setup-gems:
# stage: setup-gems
# script:
# - gem install jekyll
# - gem install jekyll-scholar
# - gem install bundler
# - gem list
setup-extras:
stage: setup-extras
script:
- gem list
- cd ~;
- git clone https://git.uwaterloo.ca/caesr-pub/jekyll-scholar-extras.git;
- cd jekyll-scholar-extras;
make-extras:
stage: make-extras
script:
- gem build jekyll-scholar-extras.gemspec ;
- gem install jekyll-scholar-extras-$VERSION.gem;
- cp -r samples/jekyll-template ~/;
- cd ~/jekyll-template
- jekyll build --trace
source 'https://rubygems.org'
gemspec
group :development do
if RUBY_VERSION >= '2.2'
gem 'test-unit'
else
gem 'minitest', '< 5.0'
end
gem 'rake'
gem 'redgreen', '~> 1.2'
# gem 'shoulda', '~> 3.5'
# gem 'cucumber', '1.3.11'
gem 'redcarpet'
# gem 'launchy', '~> 2.3'
gem 'unicode_utils'
# gem 'simplecov', '~>0.9', :require => false
# gem 'rubinius-coverage', :platform => :rbx
# gem 'coveralls', :require => false
end
group :debug do
if RUBY_VERSION > '2.0'
gem 'byebug', '~>3.5', :require => false, :platform => :mri
else
gem 'debugger', '~>1.6', :require => false, :platform => [:mri_19, :mri_20]
end
gem 'rubinius-compiler', '~>2.0', :require => false, :platform => :rbx
gem 'rubinius-debugger', '~>2.0', :require => false, :platform => :rbx
end
License
-------
```jekyll-scholar-extras``` is distributed under the same license as Jekyll.
Copyright (c) 2012-2016 [Hiren Patel](https://caesr.uwaterloo.ca/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
jekyll-scholar-extras
=====================
```jekyll-scholar-extras``` provides customized generators and tags for generating a publication bibliography with individual details pages from a [BibTeX](http://www.bibtex.org) file. This resembles other [BibTeX](http://www.bibtex.org) to HTML converters such as [bibtex2web](http://www.cs.washington.edu/homes/mernst/software/#bibtex2web).
These customizations are extensions to [Jekyll](http://jekyllrb.com/) and [Jekyll-Scholar](https://github.com/inukshuk/jekyll-scholar).
Installation
------------
You must compile ```jekyll-scholar-extras``` from source. If someone is interested in publishing to a gem server, then I would be happy to help enable this.
```bash
$ gem build jekyll-scholar-extras.gemspec;
$ gem install jekyll-scholar-extras-<version-number>.gem
```
Vagrant Method
-------------
It may be simpler to just use a vagrant setup to get jekyll-scholar-extras working. Make sure the pre-requisites for vagrant are already installed. Once you ssh into the vagrant box, you should have the jekyll-template generated.
```bash
$ cd jekyll-scholar-extras/vagrant
$ vagrant up
$ vagrant provision
$ vagrant ssh
```
Usage
-----
To enable ```jekyll-scholar-extras```, add a file in your plugin directory (e.g., to `_plugins/jekyll-scholar-extras.rb`) with the following:
require 'jekyll/scholar/extras'
# Features
These extras provide some additional features over the vanilla Jekyll-Scholar. These are described below:
## Disable generation of BibTeX entries marked to not be public.
One can include `public` field for any BibTeX entry. If the `public` field is set to `{yes}` then the corresponding entry will be generated. If the `public` field is set to `{no}` then it will not.
# Create a PDF and SLIDES download link based on the BibTeX key associated with each entry.
[jekyll-scholar](https://github.com/inukshuk/jekyll-scholar) already supports repositories. However, one may want to upload presentations associated with an article as well, and have them automatically generated. To do this, simply include a presentation file whose name is the `key` suffixed with `_slides`. For example, a BibTeX entry with key `abc_xyz` would have two files:
* `abc_xyz.pdf`: The PDF paper download.
* `abc_xyz_slides.pdf`: The PDF of the presentation.
User-defined customizations of these are still in progress.
# Example
An example setup that uses the customized bibliography and details page generators and tags.
* [Sample 1](https://caesr.uwaterloo.ca//publications/index.html)
License
-------
```jekyll-scholar-extras``` is distributed under the same license as Jekyll.
Copyright (c) 2012-2018 [CAESR](https://caesr.uwaterloo.ca/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'jekyll/scholar/version'
#require 'cucumber/rake/task'
#Cucumber::Rake::Task.new(:features)
task :default => [:features]
#require 'coveralls/rake/task'
#Coveralls::RakeTask.new
#task :test_with_coveralls => [:features, 'coveralls:push']
require 'jekyll/scholar/version'
# Mirror to github without history
task :github do |t|
system "git checkout --orphan upit"
system "git commit -m 'Push jekyll-scholar-extras #{Jekyll::ScholarExtras::VERSION} to github' "
system "git remote add origin git@github.com:rseac/jekyll-scholar-extras.git"
system "echo 'push to remote without history'"
system "git push -u origin upit"
system "git remote remove origin"
system "git checkout master"
system "git branch -D upit"
end
# Bring oldest commit to latest
Feature: Public or Not
A BibTeX bibliography may contain publications that are not supposed to be public as of yet.
This could be due to several reasons such as it being under submission.
In order to allow this, I have a specific field that can be inserted in the
BibTeX to describe whether a particular entry should be generated using
jekyll-scholar or not.
Scenario: Wanting to *not* make a publication public.
Suppose that one wants to hide the generation of the BibTeX entry for a
particular publication entry. Simply add the following `public` field to the entry.
"""
@book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media},
public = {no}
}
"""
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
require 'jekyll/scholar/version'
Gem::Specification.new do |s|
s.name = 'jekyll-scholar-extras'
s.version = Jekyll::ScholarExtras::VERSION.dup
s.platform = Gem::Platform::RUBY
s.authors = ['rmrf']
s.email = 'nospam at uwaterloo dot ca'
s.homepage = ''
s.licenses = ['MIT']
s.summary = 'Extras for Jekyll extensions for the academic blogger jekyll-scholar.'
s.description = %q{
Extras for jekyll-scholar. Customized bibliography and details generators.
}.gsub(/\s+/, ' ')
s.date = Time.now
s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = s.name
s.add_runtime_dependency('jekyll', '~> 3.0')
s.add_runtime_dependency('jekyll-scholar', '~> 5.10')
s.add_runtime_dependency('citeproc-ruby', '~> 1.0')
s.add_runtime_dependency('bibtex-ruby', '~> 4.0', '>=4.0.13')
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {samples,test,spec,features}/*`.split("\n")
s.executables = []
s.require_path = 'lib'
end
# vim: syntax=ruby
module Jekyll
class ScholarExtras
@extra_defaults = {
'slides' => '_slides',
'parse_extra_fields' => {
'award' => "award"
}
}.freeze
class << self
attr_reader :extra_defaults
end
end
end
require 'jekyll/scholar'
require 'jekyll/scholar/extra_defaults'
require 'jekyll/scholar/extras_utilities'
require 'jekyll/scholar/extras/bibliography_year'
require 'jekyll/scholar/extras/bibliography_bytype'
module Jekyll
class Scholar
class BibliographyTagByType < Liquid::Tag
include Scholar::Utilities
include ScholarExtras::Utilities
def initialize(tag_name, arguments, tokens)
super
@config = Scholar.defaults.dup
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 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_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
# Only select items that are public.
items = entries.select { |e| e.public == 'yes' }
initialize_prefix_defaults()
initialize_type_labels()
set_type_counts(items.size())
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
items = items[offset..max] if limit_entries?
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?(:award)
# TODO: Awkward -- Find position to insert it. Before the last </div>
ts = content_tag "div class=\"csl-award\"", entry.award.to_s
reference_position = reference.rindex('</div>')
if reference_position.nil?
puts "NILL"
else
reference.insert(reference.rindex('</div>'), ts.to_s)
end
end
# Check if there are ACM PDF links
# Really awkward way of insertion
reference.insert(reference.rindex('</div>').to_i,render_acmpdf_link(entry))
# Render links if repository specified
if repository? && !entry.field?(:acmpdflink)
if not repository_link_for(entry).nil?
pdflink = "<div class=\"pure-button csl-pdf\"><a href=\"" + repository_link_for(entry) + "\">PDF</a></div>"
reference.insert(reference.rindex('</div>'), pdflink.to_s )
end
# Check for SLIDES PDF.
if not repository_link_for(entry).nil?
link = repository_slides_link_for(entry)
if link.to_s.include?("_slides")
pdflink = "<div class=\"pure-button csl-slides\"><a href=\"" + repository_slides_link_for(entry) + "\">SLIDES</a></div>"
reference.insert(reference.rindex('</div>'), pdflink.to_s )
end
end
end
# Is there a link for code
if entry.field?(:code)
code_url = "<div class=\"pure-button csl-code\"><a href=\"" + entry.code.to_s + "\">CODE</a></div>"
reference.insert(reference.rindex('</div>').to_i, code_url.to_s )
end
# Generate the bibtex button
tex_bib = "<div class=\"pure-button csl-bibtex\"><a href=\"" + bibtex_link_for(entry).to_s + "\">BIBTEX</a></div>"
reference.insert(reference.rindex('</div>').to_i, tex_bib.to_s )
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::BibliographyTagByType)
module Jekyll
class Scholar
class BibliographyTagYear < Liquid::Tag
include Scholar::Utilities
include ScholarExtras::Utilities
def initialize(tag_name, arguments, tokens)
super
@config = Scholar.defaults.dup
@config_extras = ScholarExtras.extra_defaults.dup
#puts @config_extras
#puts @config_extras['parse_extra_fields']
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' && 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 get_entries_by_type(year, type)
b = bibliography.query('@*') { |item|
(item.year == year && 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
end
def entries_year(year)
b = bibliography.query('@*') {
|a| (a.year == year && 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?(extra_parse_fields['award'])
# TODO: Awkward -- Find position to insert it. Before the last </div>
ts = content_tag "div class=\"csl-award\"", entry.award.to_s
reference_position = reference.rindex('</div>')
if reference_position.nil?
else
reference.insert( reference.rindex('</div>'), ts.to_s )
end
end
# There are multiple ways to have PDFs associated.
# Priority is suggested as below.
# 1. ACM links to PDF through authorizer
# 2. Repository links
# 3. Just web links to somewhere else.
#
# Check if there are ACM PDF links
position = reference.rindex('</div>')
reference.insert(position.to_i,render_acmpdf_link(entry))
# Render links if repository specified but not acmpdflink
if repository? && !entry.field?(:acmpdflink)
if not repository_link_for(entry).nil?
# puts "link is not null"
# puts repository_link_for(entry)
pdflink = "<div class=\"pure-button csl-pdf\"><a href=\"" + repository_link_for(entry) + "\">PDF</a></div>"
reference.insert(reference.rindex('</div>'), pdflink.to_s )
end
# Check for SLIDES PDF.
if not repository_link_for(entry).nil?
link = repository_slides_link_for(entry)
# puts link.to_s
if link.to_s.include?(@config_extras['slides'])
pdflink = "<div class=\"pure-button csl-slides\"><a href=\"" + repository_slides_link_for(entry) + "\">SLIDES</a></div>"
reference.insert(reference.rindex('</div>'), pdflink.to_s )
end
end
# Is there a link for code
if entry.field?(:code)
code_url = "<div class=\"pure-button csl-code\"><a href=\"" + entry.code.to_s + "\">CODE</a></div>"
reference.insert(reference.rindex('</div>').to_i, code_url.to_s )
end
end
# Generate the bibtex button for all pubs
tex_bib = "<div class=\"pure-button csl-bibtex\"><a href=\"" + bibtex_link_for(entry).to_s + "\">BIBTEX</a></div>"
reference.insert(reference.rindex('</div>').to_i, tex_bib.to_s )
# Content tag is dependent on type of article.
content_tag "li class=\"" + render_ref_img(entry) + "\"", reference
end
# split_reference reference
}.join("\n")
}.join("\n")