Sha256: da50f3578539436f53ac5bf69159dbcfba2bbc601aee775d6445836db7a80024

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

class PublifyApp
  class Textfilter
    class Youtube < TextFilterPlugin::MacroPre
      plugin_display_name "Youtube"
      plugin_description "Embed Youtube videos"

      DEFAULT_OPTIONS = { width: 560,
                          height: 315 }.freeze

      def self.help_text
        %{
You can use `<publify:youtube v="eXamPL" />` to embed Youtube videos.

Options:

* **v**. Required, the video_id.
* **width**.  560 by default.
* **height**.  Height. 315 by default.
* **start**.  Sets the start time
}
      end

      def self.macrofilter(attrib)
        video_id = attrib["v"]
        return '' unless video_id # Video ID is required

        width = attrib.fetch("width", DEFAULT_OPTIONS[:width])
        height = attrib.fetch("height", DEFAULT_OPTIONS[:height])
        start = attrib["start"]

        src = "https://www.youtube.com/embed/#{video_id}"
        src += "?start=#{start}" if start

        "<iframe width=\"#{width}\" height=\"#{height}\" src=\"#{src}\" frameborder=\"0\"" \
        ' allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope;' \
        ' picture-in-picture; web-share"' \
        ' referrerpolicy="strict-origin-when-cross-origin" allowfullscreen>' \
        '</iframe>'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
publify_textfilter_youtube-10.0.1 lib/publify_app/textfilter_youtube.rb
publify_textfilter_youtube-10.0.0 lib/publify_app/textfilter_youtube.rb