From a17cccb88980476dffc7315ae64c572564005665 Mon Sep 17 00:00:00 2001 From: Jesper Hess Nielsen Date: Mon, 2 Jan 2017 11:32:14 +0100 Subject: [PATCH] Add FontAwesome stylesheet and tag plugin --- _includes/head.html | 1 + _plugins/font_awesome.rb | 71 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 _plugins/font_awesome.rb diff --git a/_includes/head.html b/_includes/head.html index 2087cf3..2fdb75a 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -6,6 +6,7 @@ {% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %} + diff --git a/_plugins/font_awesome.rb b/_plugins/font_awesome.rb new file mode 100644 index 0000000..889b323 --- /dev/null +++ b/_plugins/font_awesome.rb @@ -0,0 +1,71 @@ +## +# The MIT License (MIT) +# +# Copyright (c) 2014 Ryan Morrissey +# +# 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. +# +# +# Font Awesome Icons Liquid Tag +# Documentation can be found at http://fontawesome.io/ +# +# Example: +# {% icon fa-camera-retro %} +# {% icon fa-camera-retro fa-lg %} +# {% icon fa-spinner fa-spin %} +# {% icon fa-shield fa-rotate-90 %} + +module Jekyll + class FontAwesomeTag < Liquid::Tag + + def render(context) + if tag_contents = determine_arguments(@markup.strip) + icon_class, icon_extra = tag_contents[0], tag_contents[1] + icon_tag(icon_class, icon_extra) + else + raise ArgumentError.new <<-eos +Syntax error in tag 'icon' while parsing the following markup: + + #{@markup} + +Valid syntax: + for icons: {% icon fa-camera-retro %} + for icons with size/spin/rotate: {% icon fa-camera-retro fa-lg %} +eos + end + end + + private + + def determine_arguments(input) + matched = input.match(/\A(\S+) ?(\S+)?\Z/) + [matched[1].to_s.strip, matched[2].to_s.strip] if matched && matched.length >= 3 + end + + def icon_tag(icon_class, icon_extra = nil) + if icon_extra.empty? + "" + else + "" + end + end + end +end + +Liquid::Template.register_tag('icon', Jekyll::FontAwesomeTag) \ No newline at end of file