Skip to content

Instantly share code, notes, and snippets.

@nukos
Created January 29, 2015 16:59
Show Gist options
  • Save nukos/c1f292cd9a37853c0490 to your computer and use it in GitHub Desktop.
Save nukos/c1f292cd9a37853c0490 to your computer and use it in GitHub Desktop.
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