make video urls have correct href
This commit is contained in:
parent
17f41f1291
commit
74b8921c09
2 changed files with 32 additions and 16 deletions
|
|
@ -10,10 +10,6 @@ module ApplicationHelper
|
||||||
content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time
|
content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time
|
||||||
end
|
end
|
||||||
|
|
||||||
def modern_browser?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def page_title text=nil
|
def page_title text=nil
|
||||||
title = ""
|
title = ""
|
||||||
if text.blank?
|
if text.blank?
|
||||||
|
|
@ -68,7 +64,7 @@ module ApplicationHelper
|
||||||
param_string << "#{k}=#{v}"
|
param_string << "#{k}=#{v}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"<li>
|
"<li>
|
||||||
<a href='/aspects/#{aspect.id}#{param_string}'>
|
<a href='/aspects/#{aspect.id}#{param_string}'>
|
||||||
#{aspect.name}
|
#{aspect.name}
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -210,25 +206,29 @@ module ApplicationHelper
|
||||||
|
|
||||||
def process_youtube(message, youtube_maps)
|
def process_youtube(message, youtube_maps)
|
||||||
regex = /( |^)(http:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_\-]+)(&[^ ]*|)/
|
regex = /( |^)(http:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_\-]+)(&[^ ]*|)/
|
||||||
while youtube = message.match(regex)
|
processed_message = message.gsub(regex) do |matched_string|
|
||||||
video_id = youtube[3]
|
match_data = matched_string.match(regex)
|
||||||
|
video_id = match_data[3]
|
||||||
if youtube_maps && youtube_maps[video_id]
|
if youtube_maps && youtube_maps[video_id]
|
||||||
title = h(CGI::unescape(youtube_maps[video_id]))
|
title = h(CGI::unescape(youtube_maps[video_id]))
|
||||||
else
|
else
|
||||||
title = I18n.t 'application.helper.video_title.unknown'
|
title = I18n.t 'application.helper.video_title.unknown'
|
||||||
end
|
end
|
||||||
message.gsub!(youtube[0], '<a class="video-link" data-host="youtube.com" data-video-id="' + video_id + '" href="#video">Youtube: ' + title + '</a>')
|
'<a class="video-link" data-host="youtube.com" data-video-id="' + video_id + '" href="'+ match_data[0].strip + '">Youtube: ' + title + '</a>'
|
||||||
end
|
end
|
||||||
return message
|
return processed_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_autolinks(message)
|
def process_autolinks(message)
|
||||||
message.gsub!(/( |^)(www\.[^\s]+\.[^\s])/, '\1http://\2')
|
message.gsub!(/( |^)(www\.[^\s]+\.[^\s])/, '\1http://\2')
|
||||||
message.gsub!(/(<a target="\\?_blank" href=")?(https|http|ftp):\/\/([^\s]+)/) do |m|
|
message.gsub!(/(<a target="\\?_blank" href=")?(https|http|ftp):\/\/([^\s]+)/) do |m|
|
||||||
if !$1.nil?
|
captures = [$1,$2,$3]
|
||||||
|
if !captures[0].nil?
|
||||||
m
|
m
|
||||||
|
elsif m.match(/(youtube|vimeo)/)
|
||||||
|
m.gsub(/(\*|_)/) { |m| "\\#{$1}" } #remove markers on markdown chars to not markdown inside links
|
||||||
else
|
else
|
||||||
res = %{<a target="_blank" href="#{$2}://#{$3}">#{$3}</a>}
|
res = %{<a target="_blank" href="#{captures[1]}://#{captures[2]}">#{captures[2]}</a>}
|
||||||
res.gsub!(/(\*|_)/) { |m| "\\#{$1}" }
|
res.gsub!(/(\*|_)/) { |m| "\\#{$1}" }
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
@ -253,23 +253,23 @@ module ApplicationHelper
|
||||||
|
|
||||||
def process_vimeo(message, vimeo_maps)
|
def process_vimeo(message, vimeo_maps)
|
||||||
regex = /https?:\/\/(?:w{3}\.)?vimeo.com\/(\d{6,})/
|
regex = /https?:\/\/(?:w{3}\.)?vimeo.com\/(\d{6,})/
|
||||||
while vimeo = message.match(regex)
|
processed_message = message.gsub(regex) do |matched_string|
|
||||||
video_id = vimeo[1]
|
match_data = message.match(regex)
|
||||||
|
video_id = match_data[1]
|
||||||
if vimeo_maps && vimeo_maps[video_id]
|
if vimeo_maps && vimeo_maps[video_id]
|
||||||
title = h(CGI::unescape(vimeo_maps[video_id]))
|
title = h(CGI::unescape(vimeo_maps[video_id]))
|
||||||
else
|
else
|
||||||
title = I18n.t 'application.helper.video_title.unknown'
|
title = I18n.t 'application.helper.video_title.unknown'
|
||||||
end
|
end
|
||||||
message.gsub!(vimeo[0], '<a class="video-link" data-host="vimeo.com" data-video-id="' + video_id + '" href="#video">Vimeo: ' + title + '</a>')
|
'<a class="video-link" data-host="vimeo.com" data-video-id="' + video_id + '" href="' + match_data[0] + '">Vimeo: ' + title + '</a>'
|
||||||
end
|
end
|
||||||
return message
|
return processed_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def info_text(text)
|
def info_text(text)
|
||||||
image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text
|
image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def get_javascript_strings_for(language)
|
def get_javascript_strings_for(language)
|
||||||
defaults = I18n.t('javascripts', :locale => DEFAULT_LANGUAGE)
|
defaults = I18n.t('javascripts', :locale => DEFAULT_LANGUAGE)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,22 @@ describe ApplicationHelper do
|
||||||
res.should =~ /data-host="youtube.com"/
|
res.should =~ /data-host="youtube.com"/
|
||||||
res.should =~ /data-video-id="#{video_id}"/
|
res.should =~ /data-video-id="#{video_id}"/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "leaves the links in the href of the #a tag" do
|
||||||
|
video_id = "ABYnqp-bxvg"
|
||||||
|
start_url ="http://www.youtube.com/watch?v=" + video_id
|
||||||
|
url = start_url + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
||||||
|
res = markdownify(url)
|
||||||
|
res.should =~ /href=[\S]+v=#{video_id}/
|
||||||
|
end
|
||||||
|
it 'does not autolink inside the link' do
|
||||||
|
video_id = "ABYnqp-bxvg"
|
||||||
|
start_url ="http://www.youtube.com/watch?v=" + video_id
|
||||||
|
url = start_url + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
||||||
|
res = markdownify(url)
|
||||||
|
pp res
|
||||||
|
res.match(/href="<a/).should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "recognizes multiple links of different types" do
|
it "recognizes multiple links of different types" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue