Sha256: 16c307c3e544911fc7bcc43c50912ea2b6d9bab69287734fe6900d045df842d2

Contents?: true

Size: 649 Bytes

Versions: 4

Compression:

Stored size: 649 Bytes

Contents

module Vapid
  module Directives
    # Video directive
    class Video < Vapid::Directive
      # Allow OEmbed from the following providers
      PROVIDERS = %w(
        Youtube
        Vimeo
      ).freeze

      OEmbed::Providers.register(*PROVIDERS.map { |p| OEmbed::Providers.const_get(p) })

      renders :html do |input|
        unless input.blank?
          begin
            OEmbed::Providers.get(input).html
          rescue OEmbed::NotFound
            content_tag(:a, input, href: input)
          end
        end
      end

      form preview: true do |name, value|
        text_field_tag name, value: value
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/directives/video.rb
vapid-0.1.2 lib/vapid/directives/video.rb
vapid-0.1.1 lib/vapid/directives/video.rb
vapid-0.1.0 lib/vapid/directives/video.rb