margin_figure.rb
1 ## Liquid tag 'marginfigure' used to add image data that fits 2 ## in the right margin column area of the layout 3 ## Usage {% marginfigure 'margin-id-whatever' 'path/to/image' 'This is the caption' %} 4 # 5 module Jekyll 6 class RenderMarginFigureTag < Liquid::Tag 7 8 require "shellwords" 9 10 def initialize(tag_name, text, tokens) 11 super 12 @text = text.shellsplit 13 end 14 15 def render(context) 16 baseurl = context.registers[:site].config['baseurl'] 17 if @text[1].start_with?('http://', 'https://', '//') 18 "<label for='#{@text[0]}' class='margin-toggle'>⊕</label>"+ 19 "<input type='checkbox' id='#{@text[0]}' class='margin-toggle'/>"+ 20 "<span class='marginnote'><img class='fullwidth' src='#{@text[1]}'/><br>#{@text[2]}</span>" 21 else 22 "<label for='#{@text[0]}' class='margin-toggle'>⊕</label>"+ 23 "<input type='checkbox' id='#{@text[0]}' class='margin-toggle'/>"+ 24 "<span class='marginnote'><img class='fullwidth' src='#{baseurl}/#{@text[1]}'/><br>#{@text[2]}</span>" 25 end 26 end 27 end 28 end 29 30 Liquid::Template.register_tag('marginfigure', Jekyll::RenderMarginFigureTag)