Initial checkin.

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2014-04-17 17:02:41 +02:00
commit b8d2887e52
3 changed files with 78 additions and 0 deletions

19
LICENSE Normal file
View file

@ -0,0 +1,19 @@
Copyright (c) 2014 Thomas Hochstein
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.

36
README.md Normal file
View file

@ -0,0 +1,36 @@
# nanoc extensions
*[nanoc](http://nanoc.ws/)* is a popular *static site generator*.
I'll add some little extensions for *nanoc<* here.
## filters
### abbreviations.rb
Simple *nanoc* filter to add `<abbr>` tags.
After reading a YAML document from `/content/_data/abbreviations.yam`,
all occurences of each $abbrev are replaced by a
`<abbr title="$abbrev">$fulltext</abbr>` construct.
The filter currently uses a very naive - and time consuming - regexp approach.
The abbreviations dictionay in `/content/_data/abbreviations.yaml` has to
look like this:
---
abbreviations:
- abbrev: HTML
fulltext: HyperText Markup Language
You'll need a (compile and) routing rule to stop the `abbreviations.yaml`
from being rendered and compiled, i.e. like this:
# ignore everything starting with _
compile %r{/_} do
nil
end
route %r{/_} do
nil
end

View file

@ -0,0 +1,23 @@
# abbreviations.rb
# a nanoc filter
# licensed as nanoc itself
#
# add <bbrev> tags for all known abbreviations by a
# very naive - and time consuming - regexp matchingA
#
# data source: YAML file in /content/_data/abbreviations
#
module Nanoc::Filters
class Abbreviations < Nanoc::Filter
identifier :abbrev
type :text
def run(content, params={})
output = content;
@items['/_data/abbreviations/'][:abbreviations].each do |a|
output = output.gsub(/(\s|[-,.;:"'!?>\(\[]+)#{a[:abbrev]}(\s|[-,.;:"'!?<\)\]]+)/,'\\1<abbr title="' + a[:fulltext] + '">' + a[:abbrev]+ '</abbr>\\2')
end
return output
end
end
end