Skip to content

Instantly share code, notes, and snippets.

@andystanton
Forked from melborne/lightbox.rb
Last active September 23, 2015 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andystanton/6629cca760df386a0726 to your computer and use it in GitHub Desktop.
Save andystanton/6629cca760df386a0726 to your computer and use it in GitHub Desktop.
# A Liquid tag for Jekyll sites that allows embedding Lightbox images.
#
# Adapted to work with http://lokeshdhakar.com/projects/lightbox2/
# as well as allowing remote image urls and commas in image titles.
#
# original author: kyoendo
# modified by: andystanton
#
# original Source URL: https://gist.github.com/4035604
# modified Source URL: https://gist.github.com/andystanton/6629cca760df386a0726
#
# Example usage: {% lightbox http://path/to/fullSizeUrl.png; http://path/to/thumbnailUrl.png; Image Title; Image Grouping %}
module Jekyll
class LightboxTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text
end
def render(context)
fullSizeUrl, thumbnailUrl, title, grouping = @text.split(';').map(&:strip)
%{<a href="#{fullSizeUrl}" data-lightbox="#{grouping || title}" data-title="#{title}"><img src="#{thumbnailUrl}" alt="#{title}" /></a>}
end
end
end
Liquid::Template.register_tag('lightbox', Jekyll::LightboxTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment