Skip to content

Commit

Permalink
Support for HTML5 <audio>
Browse files Browse the repository at this point in the history
As with <video>,

   [[foo.wav:audio]]

works now, producing an HTML5 <audio> element.
  • Loading branch information
distler committed Mar 3, 2009
1 parent 8ea8b6a commit c7418af
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
17 changes: 15 additions & 2 deletions app/controllers/application_controller.rb
Expand Up @@ -43,27 +43,40 @@ def connect_to_model
end

FILE_TYPES = {
'.aif' => 'audio/x-aiff',
'.aiff'=> 'audio/x-aiff',
'.avi' => 'video/x-msvideo',
'.exe' => 'application/octet-stream',
'.gif' => 'image/gif',
'.jpg' => 'image/jpeg',
'.pdf' => 'application/pdf',
'.png' => 'image/png',
'.oga' => 'audio/ogg',
'.ogg' => 'audio/ogg',
'.ogv' => 'video/ogg',
'.ogv' => 'video/ogg',
'.mov' => 'video/quicktime',
'.mp3' => 'audio/mpeg',
'.mp4' => 'video/mp4',
'.txt' => 'text/plain',
'.tex' => 'text/plain',
'.wav' => 'audio/x-wav',
'.zip' => 'application/zip'
} unless defined? FILE_TYPES

DISPOSITION = {
'application/octet-stream' => 'attachment',
'application/pdf' => 'inline',
'image/gif' => 'inline',
'image/jpeg' => 'inline',
'application/pdf' => 'inline',
'image/png' => 'inline',
'audio/mpeg' => 'inline',
'audio/x-wav' => 'inline',
'audio/x-aiff' => 'inline',
'audio/ogg' => 'inline',
'video/ogg' => 'inline',
'video/mp4' => 'inline',
'video/quicktime' => 'inline',
'video/x-msvideo' => 'inline',
'text/plain' => 'inline',
'application/zip' => 'attachment'
} unless defined? DISPOSITION
Expand Down
2 changes: 1 addition & 1 deletion lib/chunks/wiki.rb
Expand Up @@ -105,7 +105,7 @@ class Link < WikiLink

unless defined? WIKI_LINK
WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(video)|(delete))$', 0)
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(video)|(audio)|(delete))$', 0)
ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0)
WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/sanitizer.rb
Expand Up @@ -9,7 +9,7 @@ module Sanitizer
require 'node'
require 'stringsupport'

acceptable_elements = %w[a abbr acronym address area b big blockquote br
acceptable_elements = %w[a abbr acronym address area audio b big blockquote br
button caption center cite code col colgroup dd del dfn dir div dl dt
em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label
legend li map menu ol optgroup option p pre q s samp select small span
Expand All @@ -31,8 +31,8 @@ module Sanitizer
align alt axis border cellpadding cellspacing char charoff charset
checked cite class clear cols colspan color compact controls coords datetime
dir disabled enctype for frame headers height href hreflang hspace id
ismap label lang longdesc maxlength media method multiple name nohref
noshade nowrap prompt readonly rel rev rows rowspan rules scope
ismap label lang longdesc loop maxlength media method multiple name nohref
noshade nowrap poster prompt readonly rel rev rows rowspan rules scope
selected shape size span src start style summary tabindex target title
type usemap valign value vspace width xml:lang]

Expand Down
18 changes: 10 additions & 8 deletions lib/url_generator.rb
Expand Up @@ -35,8 +35,10 @@ def make_link(name, web, text = nil, options = {})
file_link(mode, name, text, web.address, known_page, description)
when :pic
pic_link(mode, name, text, web.address, known_page)
when :audio
media_link(mode, name, text, web.address, known_page, 'audio')
when :video
video_link(mode, name, text, web.address, known_page)
media_link(mode, name, text, web.address, known_page, 'video')
when :delete
delete_link(mode, name, web.address, known_page)
else
Expand Down Expand Up @@ -143,25 +145,25 @@ def pic_link(mode, name, text, web_address, known_pic)
end
end

def video_link(mode, name, text, web_address, known_vid)
def media_link(mode, name, text, web_address, known_media, media_type)
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name
case mode
when :export
if known_vid
%{<video src="#{CGI.escape(name)}" controls="controls">#{text}</video>}
if known_media
%{<#{media_type} src="#{CGI.escape(name)}" controls="controls">#{text}</#{media_type}>}
else
text
end
when :publish
if known_vid
%{<video src="#{href}" controls="controls">#{text}</video>}
if known_media
%{<#{media_type} src="#{href}" controls="controls">#{text}</#{media_type}>}
else
%{<span class="newWikiWord">#{text}</span>}
end
else
if known_vid
%{<video src="#{href}" controls="controls">#{text}</video>}
if known_media
%{<#{media_type} src="#{href}" controls="controls">#{text}</#{media_type}>}
else
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
end
Expand Down
6 changes: 3 additions & 3 deletions vendor/plugins/HTML5lib/lib/html5/sanitizer.rb
Expand Up @@ -19,7 +19,7 @@ module HTML5

module HTMLSanitizeModule

ACCEPTABLE_ELEMENTS = %w[a abbr acronym address area b big blockquote br
ACCEPTABLE_ELEMENTS = %w[a abbr acronym address area audio b big blockquote br
button caption center cite code col colgroup dd del dfn dir div dl dt
em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label
legend li map menu ol optgroup option p pre q s samp select small span
Expand All @@ -41,8 +41,8 @@ module HTMLSanitizeModule
align alt axis border cellpadding cellspacing char charoff charset
checked cite class clear cols colspan color compact controls coords datetime
dir disabled enctype for frame headers height href hreflang hspace id
ismap label lang longdesc maxlength media method multiple name nohref
noshade nowrap prompt readonly rel rev rows rowspan rules scope
ismap label lang longdesc loop maxlength media method multiple name nohref
noshade nowrap poster prompt readonly rel rev rows rowspan rules scope
selected shape size span src start style summary tabindex target title
type usemap valign value vspace width xml:lang]

Expand Down

0 comments on commit c7418af

Please sign in to comment.