Last active
June 14, 2022 05:02
-
-
Save SteveBenner/9029034 to your computer and use it in GitHub Desktop.
Slim partial - HTML5 video tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ Generate an HTML5 video tag with embedded Flash fallback | |
/ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video HTML5 video tag spec | |
/ | |
/ @local [Hash] video Attribute hash for the `video` tag | |
/ @option video [Integer] :width (320) Width of the video tag in pixels | |
/ @option video [Integer] :height (240) Height of the video tag in pixels | |
/ | |
/ @local [Hash] src Mapping of source file types to URLs for source files | |
/ @option src [String] :mp4 URL of an MP4 source file for the video | |
/ @option src [String] :webm URL of a WebM source file for the video | |
/ @option src [String] :ogg URL of an Ogg source file for the video | |
/ | |
/ @local [Hash] flash Data for a Flash object | |
/ @option flash [String] :src URL of a flash video to supply as a fallback | |
/ @option flash [String] :swf URL of a flash video to supply as a fallback | |
/ @option flash [Hash] :vars Additional data for the Flash object, formatted as URL params | |
/ | |
/ Slims 'splat' attribute parsing lets us neatly convert a Hash into HTML attributes | |
/ | |
video*{ width: 320, height: 240, class: 'video-player' }.update(video) | |
- src.each do |format, file| | |
source type="video/#{format}" src=file | |
- if defined?(flash) | |
object*{ width: video[:width] || 320, height: video[:height] || 240, | |
type: 'application/x-shockwave-flash', data: flash[:swf] } | |
param name="movie" value=flash[:swf] | |
- if flash[:vars] | |
param name="flashvars" value=(flash[:vars].collect { |k, v| "#{k}=#{v}" }.join('&')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
video: | |
width: 480 | |
height: auto | |
poster: path-to-thumbnail.jpg | |
controls: true | |
src: | |
mp4: path-to-video.mp4 | |
webm: path-to-video.webm | |
ogg: path-to-video.ogv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<video class="video-player" controls="" height="auto" poster="../img/mdc-promo-vid-thumb.jpg" width="480"> | |
<source src="video/mdc-promo-vid.mp4" type="video/mp4" /> | |
<source src="video/mdc-promo-vid.webm" type="video/webm" /> | |
<source src="video/mdc-promo-vid.ogv" type="video/ogg" /> | |
</video> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an example of how to include this partial in a framework such as Middleman (the one I use):