Class: Archangel::Liquid::Tags::GistTag
- Inherits:
-
ApplicationTag
- Object
- Liquid::Tag
- ApplicationTag
- Archangel::Liquid::Tags::GistTag
- Includes:
- ActionView::Helpers::AssetTagHelper
- Defined in:
- lib/archangel/liquid/tags/gist_tag.rb
Overview
Gist custom tag for Liquid
Example
{% gist '0d6f8a168a225fda62e8d2ddfe173271' %}
{% gist '0d6f8a168a225fda62e8d2ddfe173271' 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
-
#initialize(tag_name, markup, options) ⇒ GistTag
constructor
Asset for Liquid.
-
#render(_context) ⇒ String
Render the Gist.
Constructor Details
#initialize(tag_name, markup, options) ⇒ GistTag
Asset for Liquid
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, ) 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], ).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
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 |