Sha256: 08a769a3e9494e0026f6214a55de6a71fe607a529c130de36ded89da9c4ecd1b

Contents?: true

Size: 743 Bytes

Versions: 2

Compression:

Stored size: 743 Bytes

Contents

# Gist Liquid Tag
#
# Example:
#    {% gist 1234567 %}
#    {% gist 1234567 file.rb %}

module Monad
  class GistTag < Liquid::Tag
    def render(context)
      if tag_contents = @markup.strip.match(/\A(\d+) ?(\S*)\Z/)
        gist_id, filename = tag_contents[1].strip, tag_contents[2].strip
        gist_script_tag(gist_id, filename)
      else
        "Error parsing gist id"
      end
    end

    private

    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

Liquid::Template.register_tag('gist', Monad::GistTag)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
monad-0.0.2 lib/monad/tags/gist.rb
monad-0.0.1 lib/monad/tags/gist.rb