Class: Archangel::Liquid::Tags::GistTag

Inherits:
ApplicationTag show all
Includes:
ActionView::Helpers::AssetTagHelper
Defined in:
lib/archangel/liquid/tags/gist_tag.rb

Overview

Gist custom tag for Liquid

Example

{% gist '9bbaf7332bff1042c2d83fc88683b9df' %}
{% gist '9bbaf7332bff1042c2d83fc88683b9df' file:'hello.rb' %}

Constant Summary

Constants inherited from ApplicationTag

ApplicationTag::ASSET_ATTRIBUTES_SYNTAX, ApplicationTag::ASSET_SYNTAX, ApplicationTag::KEY_VALUE_ATTRIBUTES_SYNTAX, ApplicationTag::SLUG_ATTRIBUTES_SYNTAX, ApplicationTag::SLUG_SYNTAX, ApplicationTag::URL_ATTRIBUTES_SYNTAX

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ GistTag

Asset for Liquid

Parameters:

  • tag_name (String)

    the Liquid tag name

  • markup (String)

    the passed options

  • options (Object)

    options


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

Instance Method Details

#render(_context) ⇒ String

Render the Gist

Parameters:

  • _context (Object)

    the Liquid context

Returns:

  • (String)

    the rendered Gist


46
47
48
49
50
51
52
# 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