Class: Archangel::Liquid::Tags::NoembedTag
- Inherits:
-
ApplicationTag
- Object
- Liquid::Tag
- ApplicationTag
- Archangel::Liquid::Tags::NoembedTag
- Defined in:
- lib/archangel/liquid/tags/noembed_tag.rb
Overview
Noembed custom tag for Liquid
For more information about Noembed, see noembed.com/
Example
{% noembed "https://www.youtube.com/watch?v=-X2atEH7nCg" %}
{% noembed "https://vimeo.com/70707344" %}
{% noembed "https://vimeo.com/70707344" remote: true %}
{% noembed "https://vimeo.com/70707344" maxwidth:600 %}
{% noembed "https://vimeo.com/70707344" maxheight:400 %}
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) ⇒ NoembedTag
constructor
Noembed for Liquid.
-
#render(_context) ⇒ String
Render the Widget.
Constructor Details
#initialize(tag_name, markup, options) ⇒ NoembedTag
Noembed for Liquid
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/archangel/liquid/tags/noembed_tag.rb', line 29 def initialize(tag_name, markup, ) super match = URL_ATTRIBUTES_SYNTAX.match(markup) if match.blank? raise ::Liquid::SyntaxError, Archangel.t("errors.syntax.noembed") end @url = ::Liquid::Variable.new(match[:url], ).name @attributes = { remote: false } 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 Widget
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/archangel/liquid/tags/noembed_tag.rb', line 52 def render(_context) return if url.blank? = "noembed-#{Digest::MD5.hexdigest(url)}" content = if %w[1 true yes y].include?(attributes[:remote].to_s) build_js_request() else build_ruby_request end content_tag(:div, raw(content), id: , class: "noembed") end |