Class: JekyllVideo::Video

Inherits:
JekyllSupport::JekyllTag
  • Object
show all
Defined in:
lib/video.rb

Overview

This class implements the Jekyll video functionality

Constant Summary collapse

PLUGIN_NAME =
'video'.freeze
VERSION =
JekyllVideo::VERSION

Instance Method Summary collapse

Instance Method Details

#render_implvoid

This method returns an undefined value.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/video.rb', line 28

def render_impl
  classes   = @helper.parameter_specified?('classes') || 'shadow rounded'
  src       = @helper.parameter_specified?('src')     || @argument_string
  style     = @helper.parameter_specified?('style')   || ''
  width     = @helper.parameter_specified?('width')   || '100%'

  remote_video = src.start_with?('http')
  local_video_exists = !remote_video && File.exist?(src)
  raise VideoError, "Video file at #{src} referenced by  #{@page['path']} does not exist." unless remote_video || local_video_exists

  <<~END_OUTPUT
    <video class="jekyll_video #{classes}" controls width="#{width}" style="#{style}">
      <source src="#{src}">

      Your browser does not support HTML video.
      Here is a <a href="#{src}">link to the video</a>.
    </video>
  END_OUTPUT
rescue VideoError => e # jekyll_plugin_support handles StandardError
  e.shorten_backtrace
  msg = format_error_message e.message
  @logger.error { "#{e.class} raised #{msg}" }
  binding.pry if @pry_on_video_error # rubocop:disable Lint/Debugger
  raise e if @die_on_video_error

  "<div class='jekyll_video_error'>#{e.class} raised in #{@tag_name} tag\n#{msg}</div>"
end