Class: Alula::Sublimevideo

Inherits:
VideoTag
  • Object
show all
Defined in:
lib/alula/plugins/sublimevideo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.install(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/alula/plugins/sublimevideo.rb', line 14

def self.install(options)
  # Require valid sublime token present in configuration
  return false unless options.token
  
  # Register addons
  Alula::Plugin.addon :head, ->(context) {
    "<script src=\"http://cdn.sublimevideo.net/js/#{options.token}.js\" async></script>" if context.item.content[/\<video/]
  }
  
  # Register for image tags
  Alula::Tag.register :video, self
end

.pathObject



6
7
8
# File 'lib/alula/plugins/sublimevideo.rb', line 6

def self.path
  File.join(File.dirname(__FILE__), %w{.. .. .. plugins sublimevideo})
end

.versionObject



10
11
12
# File 'lib/alula/plugins/sublimevideo.rb', line 10

def self.version
  Alula::Plugins::VERSION::STRING
end

Instance Method Details

#contentObject



27
28
29
30
31
32
# File 'lib/alula/plugins/sublimevideo.rb', line 27

def content
  # FeedBuilder support, skip sublime extensions for feeds
  return super if self.context.item..renderer.class.to_s == "Alula::FeedBuilder"

  sublime_videotag(@source)
end

#sublime_videotag(source) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/alula/plugins/sublimevideo.rb', line 34

def sublime_videotag(source)
  poster = source.gsub(/#{File.extname(source)}$/, '.png')
  info = info(poster, :thumbnail)
  poster_hires = hires_url(poster, :thumbnail)
  poster = attachment_url(poster, :thumbnail)
  
  tag =  "<a"
  tag += " class=\"sublime zoomable video #{@options["classes"].join(" ")}\""
  tag += " href=\"#{sources.first[:url]}\""
  tag += " style=\"width: #{info.width}px; height: #{info.height}px;\""
  tag += ">"
  tag += " <img"
  tag += "  alt=\"#{@options["alternative"]}\""
  tag += "  width=\"#{info.width}\" height=\"#{info.height}\""
  if context.site.config.attachments.image.lazyload
    tag += " src=\"#{asset_url("grey.gif")}\""
    tag += " data-original=\"#{poster}\""
  else
    tag += " src=\"#{poster}\""
  end
  tag += " data-hires=\"#{poster_hires}\"" if context.site.config.attachments.image.hires and poster_hires
  
  tag += "  />"
  tag += "  <span class=\"zoom_icon\"></span>"
  tag += "</a>"
  
  info = info(sources.first[:name], :video)
  tag += "<video"
  tag += " controls"
  tag += " class=\"sublime lightbox\""
  tag += " style=\"display: none;\""
  tag += " width=\"#{info.width}\""
  tag += " height=\"#{info.height}\""
  tag += " poster=\"#{poster}\""
  tag += " preload=\"none\""
  tag += " data-uid=\"#{source}\""
  tag += " data-name=\"#{source}\""
  tag += ">"
  
  sources.each do |source|
    tag += "  <source src=\"#{source[:url]}\" #{source[:hires] ? "data-quality=\"hd\"" : ""} />"
  end
  
  tag += "</video>"
  
end