Created
August 27, 2012 09:54
-
-
Save HKLF4/3487038 to your computer and use it in GitHub Desktop.
Octopress HTML5 Audio 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
# Title: | |
# Octopress HTML5 Audio Tag | |
# http://antoncherkasov.me/projects/octopress-plugins | |
# Author: | |
# Anton Cherkasov | |
# http://antoncherkasov.me | |
# [email protected] | |
# Syntax: | |
# {% audio url/to/mp3 %} | |
# {% audio url/to/mp3 url/to/ogg %} | |
# Example: | |
# {% audio http://example.org/music.mp3 http://example.org/music.ogg %} | |
# Output: | |
# <audio controls><source src="http://example.org/music.mp3"><source src="http://example.org/music.org"></audio> | |
module Jekyll | |
class AudioTag < Liquid::Tag | |
@audio = nil | |
def initialize(tag_name, markup, tokens) | |
@files = markup | |
super | |
end | |
def render(context) | |
output = super | |
audio = "<audio controls>" | |
@files.each_line(' ') do |file| | |
audio += "<source src='#{file[0...-1]}'>" | |
end | |
audio += "</audio>" | |
end | |
end | |
end | |
Liquid::Template.register_tag('audio', Jekyll::AudioTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment