From b8d2887e52666238ee860282baafcabfe48ba5d8 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Thu, 17 Apr 2014 17:02:41 +0200 Subject: [PATCH] Initial checkin. Signed-off-by: Thomas Hochstein --- LICENSE | 19 +++++++++++++++++++ README.md | 36 ++++++++++++++++++++++++++++++++++++ lib/filters/abbreviations.rb | 23 +++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 lib/filters/abbreviations.rb diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cea1042 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfb1431 --- /dev/null +++ b/README.md @@ -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 `` tags. + +After reading a YAML document from `/content/_data/abbreviations.yam`, +all occurences of each $abbrev are replaced by a +`$fulltext` 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 diff --git a/lib/filters/abbreviations.rb b/lib/filters/abbreviations.rb new file mode 100644 index 0000000..8596577 --- /dev/null +++ b/lib/filters/abbreviations.rb @@ -0,0 +1,23 @@ +# abbreviations.rb +# a nanoc filter +# licensed as nanoc itself +# +# add 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' + a[:abbrev]+ '\\2') + end + return output + end + end +end