Sha256: b482b5e0ad4d7939814d3a3dbc5ad4b152ea7c09fef13ae3a5dd8dd32a30ca6f
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
module Alula module Plugins class Lightbox < Liquid::Tag def self.install(options) @@options = options # Register custom tag Liquid::Template.register_tag('lightbox', Alula::Plugins::Lightbox) # Return path to assets File.expand_path(File.join(File.dirname(__FILE__), *%w{.. .. .. plugins lightbox})) end def initialize(tag_name, markup, tokens) /(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?<title>\s+.+)?/ =~ markup /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ title @name = src @title = title || "" @alt = alt || "" end def render(context) asset_path = context.registers[:site].config["asset_path"] manifest = context.registers[:site].config["manifest"] original = File.join(asset_path, manifest.assets[File.join("_originals", @name)]) thumbnail = File.join(asset_path, manifest.assets[File.join("_thumbnails", @name)]) # Fetch image size img = Magick::Image.read(File.join("public", thumbnail)).first width = img.columns height = img.rows tag = "<a class=\"fancybox\" rel=\"#{context.environments.first["page"]["id"]}\" href=\"#{original}\">" tag += "<img src=\"#{thumbnail}\" alt=\"#{@alt}\" title=\"#{@title}\" width=\"#{width}\" height=\"#{height}\">" tag += "</a>" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
alula-plugins-0.1.1a | lib/alula/plugins/lightbox.rb |
alula-plugins-0.1.0 | lib/alula/plugins/lightbox.rb |