Last active
February 12, 2017 15:01
-
-
Save nukos/f19ab09efd18b0a035ec to your computer and use it in GitHub Desktop.
Jekyll Plugin: Liquid tag FontAwesome icon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fa_prefix: #default: fa | |
fa_exclude: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
class RenderFontAwesomeTag < Liquid::Tag | |
def initialize(tag_name, text, tokens) | |
super | |
@classes = text.split(' ') | |
end | |
def render(context) | |
# local vars | |
site = context.registers[:site] | |
exclude_classes = ['pull-left'] | |
prefix = 'fa' | |
fa_classes = [] | |
# merge exclude_classes | |
if site.config['fa_exclude'] | |
exclude_classes = exclude_classes + site.config['fa_exclude'] | |
exclude_classes = exclude_classes.uniq | |
end | |
# set prefix | |
if site.config['fa_prefix'] | |
prefix = site.config['fa_prefix'] | |
end | |
# set classes | |
@classes.each do | name | | |
# add prefix class | |
unless exclude_classes.include?( name ) | |
fa_class_name = prefix + '-' + name | |
else | |
fa_class_name = name | |
end | |
fa_classes.push( fa_class_name ) | |
end | |
"<i class='#{prefix} #{fa_classes.join(' ')}'></i>" | |
end | |
end | |
end | |
Liquid::Template.register_tag('fa', Jekyll::RenderFontAwesomeTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you create a documentary about how to install and how these liquid tags look like? 👍