class Archangel::Liquid::Tags::GistTag
Gist custom tag for Liquid
Example
{% gist '0d6f8a168a225fda62e8d2ddfe173271' %} {% gist '0d6f8a168a225fda62e8d2ddfe173271' file:'hello.rb' %}
Attributes
attributes[R]
key[R]
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Asset for Liquid
@param tag_name [String] the Liquid
tag name @param markup [String] the passed options @param options [Object] options
Calls superclass method
# File lib/archangel/liquid/tags/gist_tag.rb, line 23 def initialize(tag_name, markup, options) super match = ASSET_ATTRIBUTES_SYNTAX.match(markup) if match.blank? raise ::Liquid::SyntaxError, Archangel.t("errors.syntax.gist") end @key = ::Liquid::Variable.new(match[:asset], options).name @attributes = {} match[:attributes].scan(KEY_VALUE_ATTRIBUTES_SYNTAX) do |key, value| @attributes[key.to_sym] = ::Liquid::Expression.parse(value) end end
Public Instance Methods
render(_context)
click to toggle source
Render the Gist
@param _context [Object] the Liquid
context @return [String] the rendered Gist
# File lib/archangel/liquid/tags/gist_tag.rb, line 46 def render(_context) return if key.blank? src = gist_source(key, attributes.fetch(:file, nil)) javascript_include_tag(src) end
Protected Instance Methods
gist_source(id, file)
click to toggle source
# File lib/archangel/liquid/tags/gist_tag.rb, line 58 def gist_source(id, file) file_string = file.blank? ? nil : "?file=#{file}" "https://gist.github.com/#{id}.js#{file_string}" end