Sha256: 7a79d19251c29f1621270a77aba875c8f235a9c6f8d3f7d17cd2d35b5f00b613
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
module Jekyll module Gist class GistTag < Liquid::Tag def render(context) if tag_contents = determine_arguments(@markup.strip) gist_id, filename = tag_contents[0], tag_contents[1] gist_script_tag(gist_id, filename) else raise ArgumentError.new <<-eos Syntax error in tag 'gist' while parsing the following markup: #{@markup} Valid syntax: for all gists: {% gist user/1234567 %} eos end end private def determine_arguments(input) matched = if input.include?("/") input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/) else input.match(/\A(\d+) ?(\S*)\Z/) end [matched[1].strip, matched[2].strip] if matched && matched.length >= 3 end def gist_script_tag(gist_id, filename = nil) if filename.empty? "<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>" else "<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>" end end end end end Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jekyll-gist-1.0.0 | lib/jekyll-gist/gist_tag.rb |
jekyll-gist-1.0.0.rc1 | lib/jekyll-gist/gist_tag.rb |