Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit bdd53a4

Browse files
committed
Add new filehash.rb linguist.rb and math.rb plugins
1 parent 9f54ce2 commit bdd53a4

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Custom plugins for the Jekyll static site generator.
22

3+
## filehash.rb
4+
5+
filehash.rb generates a SHA1 hex digest for a given file.
6+
7+
It has no dependencies.
8+
39
## h1kramdown.rb
410

511
h1kramdown.rb patches `Kramdown::Converter::Html.convert_header` so that it inserts an empty `a` element as the first child of h[1..6] elements, with href pointing to the id of the h[1..6] element. It can be styled with the selector `h[1..6] > a:first-child:empty`.
@@ -14,6 +20,21 @@ handleize.rb is a liquid filter that forms a valid handle/slug from an input str
1420

1521
It has no dependencies.
1622

23+
## linguist.rb
24+
25+
linguist.rb contains the tag `linguist_colors` that outputs css rules corresponding to languages that [linguist](https://github.com/github/linguist) (used by GitHub) detects.
26+
27+
It depends on linguist: `$ [sudo] gem install github-linguist`.
28+
29+
It accepts a property to assign the colour to and a css selector that replaces the `{language}` token with a slug derived from the language name.
30+
31+
## math.rb
32+
33+
math.rb provides liquid filters to access the following [`Math` module](http://www.ruby-doc.org/core-1.9.3/Math.html) methods: [acos](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-acos) [acosh](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-acosh) [asin](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-asin) [asinh](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-asinh) [atan](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-atan) [atan2](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-atan2) [atanh](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-atanh) [cbrt](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-cbrt) [cos](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-cos) [cosh](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-cosh) [erf](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-erf) [erfc](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-erfc) [exp](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-exp) [frexp](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-frexp) [gamma](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-gamma) [hypot](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-hypot) [ldexp](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-ldexp) [lgamma](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-lgamma) [log](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-log) [log10](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-log10) [log2](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-log2) [sin](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-sin) [sinh](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-sinh) [sqrt](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-sqrt) [tan](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-tan) [tanh](http://www.ruby-doc.org/core-1.9.3/Math.html#method-c-tanh).
34+
It also provides filters to access the following [`Numeric` module](http://ruby-doc.org/core-1.9.3/Numeric.html) methods: [abs](http://ruby-doc.org/core-1.9.3/Numeric.html#method-i-abs) [abs2](http://ruby-doc.org/core-1.9.3/Numeric.html#method-i-abs2) [divmod](http://ruby-doc.org/core-1.9.3/Numeric.html#method-i-divmod) [remainder](http://ruby-doc.org/core-1.9.3/Numeric.html#method-i-remainder).
35+
36+
It has no dependencies.
37+
1738
## mathml.rb
1839

1940
mathml.rb converts TeX into MathML. It provides a liquid tag `math` (and closing tag `endmath`), TeX within the tag will be converted into MathML. If kramdown is installed it will also replace `Kramdown::Converter::Html.convert_math` so that MathML can be generated using kramdown builtins. To clarify you can always use `{% math %}...{% endmath %}` but when using the kramdown parser you can also use `$$...$$`.

filehash.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "digest/sha1"
2+
3+
module Jekyll::FileHash
4+
def file_hash input
5+
Digest::SHA1.hexdigest IO.read input
6+
end
7+
end
8+
9+
Liquid::Template.register_filter Jekyll::FileHash

linguist.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "linguist"
2+
3+
class Jekyll::Tags::LinguistColors < Liquid::Tag
4+
def initialize tag_name, markup, tokens
5+
@attributes = {
6+
:selector => ".language-{language}",
7+
:property => "background"
8+
}
9+
10+
markup.scan(Liquid::TagAttributes) { |key, value| @attributes[key.to_sym] = value }
11+
12+
super
13+
end
14+
15+
def render context
16+
Linguist::Language.all.select{ |language| language.color }.map do |language|
17+
slug = language.name.gsub(/\s+/, "-").gsub(/([#+])/, "\\\\\\\\\\1").downcase
18+
19+
"#{@attributes[:selector].gsub "{language}", slug} { #{@attributes[:property]}: #{language.color} }"
20+
end * "\n"
21+
end
22+
end
23+
24+
Liquid::Template.register_tag "linguist_colors", Jekyll::Tags::LinguistColors

math.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Jekyll::MathFilter
2+
%w[acos acosh asin asinh atan atan2 atanh cbrt cos cosh erf erfc
3+
exp frexp gamma hypot ldexp lgamma log log10 log2 sin sinh
4+
sqrt tan tanh].each do |name|
5+
define_method name.to_sym do |*args|
6+
Math.send name, *args
7+
end
8+
end
9+
10+
%w[abs abs2 divmod remainder].each do |name|
11+
define_method name.to_sym do |input, *args|
12+
input.send name, *args
13+
end
14+
end
15+
end
16+
17+
Liquid::Template.register_filter Jekyll::MathFilter

0 commit comments

Comments
 (0)