auto_html-whistlerbrk 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +123 -0
- data/Rakefile +9 -0
- data/lib/auto_html.rb +17 -0
- data/lib/auto_html/auto_html_for.rb +64 -0
- data/lib/auto_html/base.rb +21 -0
- data/lib/auto_html/builder.rb +22 -0
- data/lib/auto_html/capistrano.rb +17 -0
- data/lib/auto_html/filter.rb +22 -0
- data/lib/auto_html/filters/dailymotion.rb +6 -0
- data/lib/auto_html/filters/flickr.rb +20 -0
- data/lib/auto_html/filters/gist.rb +8 -0
- data/lib/auto_html/filters/google_map.rb +19 -0
- data/lib/auto_html/filters/hashtag.rb +7 -0
- data/lib/auto_html/filters/html_escape.rb +9 -0
- data/lib/auto_html/filters/image.rb +16 -0
- data/lib/auto_html/filters/instagram.rb +10 -0
- data/lib/auto_html/filters/link.rb +16 -0
- data/lib/auto_html/filters/liveleak.rb +19 -0
- data/lib/auto_html/filters/metacafe.rb +13 -0
- data/lib/auto_html/filters/redcarpet.rb +4 -0
- data/lib/auto_html/filters/sanitize.rb +5 -0
- data/lib/auto_html/filters/simple_format.rb +12 -0
- data/lib/auto_html/filters/soundcloud.rb +19 -0
- data/lib/auto_html/filters/ted.rb +13 -0
- data/lib/auto_html/filters/twitter.rb +19 -0
- data/lib/auto_html/filters/vimeo.rb +15 -0
- data/lib/auto_html/filters/worldstar.rb +8 -0
- data/lib/auto_html/filters/youtube.rb +19 -0
- data/lib/auto_html/filters/youtube_image.rb +17 -0
- data/lib/auto_html/filters/youtube_js_api.rb +6 -0
- data/lib/auto_html/railtie.rb +10 -0
- data/lib/auto_html/rake_tasks.rb +27 -0
- data/lib/auto_html/task.rb +9 -0
- data/test/fixture_setup.rb +13 -0
- data/test/fixtures/database.yml +5 -0
- data/test/fixtures/schema.rb +20 -0
- data/test/functional/auto_html_for_options_test.rb +26 -0
- data/test/functional/auto_html_for_test.rb +56 -0
- data/test/functional/filter_test.rb +27 -0
- data/test/test_helper.rb +16 -0
- data/test/unit/auto_html_test.rb +37 -0
- data/test/unit/filters/dailymotion_test.rb +34 -0
- data/test/unit/filters/gist_test.rb +15 -0
- data/test/unit/filters/google_map_test.rb +24 -0
- data/test/unit/filters/hashtag_test.rb +25 -0
- data/test/unit/filters/html_escape_test.rb +15 -0
- data/test/unit/filters/image_test.rb +77 -0
- data/test/unit/filters/instagram_test.rb +35 -0
- data/test/unit/filters/link_test.rb +55 -0
- data/test/unit/filters/liveleak_test.rb +17 -0
- data/test/unit/filters/metacafe_test.rb +29 -0
- data/test/unit/filters/redcarpet_test.rb +38 -0
- data/test/unit/filters/sanitize_test.rb +36 -0
- data/test/unit/filters/simple_format_test.rb +15 -0
- data/test/unit/filters/soundcloud_test.rb +52 -0
- data/test/unit/filters/ted_test.rb +18 -0
- data/test/unit/filters/twitter_test.rb +45 -0
- data/test/unit/filters/vimeo_test.rb +64 -0
- data/test/unit/filters/worldstar_test.rb +27 -0
- data/test/unit/filters/youtube_image_test.rb +59 -0
- data/test/unit/filters/youtube_js_api_test.rb +30 -0
- data/test/unit/filters/youtube_test.rb +73 -0
- data/test/unit/unit_test_helper.rb +3 -0
- metadata +134 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
AutoHtml.add_filter(:metacafe).with(:width => 440, :height => 272, :show_stats => false, :autoplay => false) do |text, options|
|
2
|
+
text.gsub(/http:\/\/www\.metacafe\.com\/watch\/([A-Za-z0-9._%-]*)\/([A-Za-z0-9._%-]*)(\/)?/) do
|
3
|
+
metacafe_id = $1
|
4
|
+
metacafe_slug = $2
|
5
|
+
width = options[:width]
|
6
|
+
height = options[:height]
|
7
|
+
show_stats = options[:show_stats] ? "showStats=yes" : "showStats=no"
|
8
|
+
autoplay = options[:autoplay] ? "autoPlay=yes" : "autoPlay=no"
|
9
|
+
flash_vars = [show_stats, autoplay].join("|")
|
10
|
+
|
11
|
+
%{<div style="background:#000000;width:#{width}px;height:#{height}px"><embed flashVars="playerVars=#{flash_vars}" src="http://www.metacafe.com/fplayer/#{metacafe_id}/#{metacafe_slug}.swf" width="#{width}" height="#{height}" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_#{metacafe_id}" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>}
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
AutoHtml.add_filter(:simple_format).with({}) do |text, html_options|
|
2
|
+
require 'action_view'
|
3
|
+
|
4
|
+
args = [text, {}, {:sanitize => false}]
|
5
|
+
begin
|
6
|
+
ActionView::Base.new.simple_format(*args)
|
7
|
+
rescue ArgumentError
|
8
|
+
# Rails 2 support
|
9
|
+
args.pop
|
10
|
+
retry
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# set these options and default values
|
4
|
+
# :width => '100%', :height => 166, :auto_play => false, :theme_color => '00FF00', :color => '915f33', :show_comments => false
|
5
|
+
AutoHtml.add_filter(:soundcloud).with(:width => '100%', :height => 166, :auto_play => false, :theme_color => '00FF00', :color => '915f33', :show_comments => false, :show_artwork => false) do |text, options|
|
6
|
+
text.gsub(/(https?:\/\/)?(www.)?soundcloud\.com\/\S*/) do |match|
|
7
|
+
new_uri = match.to_s
|
8
|
+
new_uri = (new_uri =~ /^https?\:\/\/.*/) ? new_uri : "http://#{new_uri}"
|
9
|
+
new_uri.strip!
|
10
|
+
width = options[:width]
|
11
|
+
height = options[:height]
|
12
|
+
auto_play = options[:auto_play]
|
13
|
+
theme_color = options[:theme_color]
|
14
|
+
color = options[:color]
|
15
|
+
show_artwork = options[:show_artwork]
|
16
|
+
show_comments = options[:show_comments]
|
17
|
+
%{<iframe width="#{width}" height="#{height}" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=#{new_uri}&show_artwork=#{show_artwork}&show_comments=#{show_comments}&auto_play=#{auto_play}&color=#{color}&theme_color=#{theme_color}"></iframe>}
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# TED talks (http://www.ted.com)
|
2
|
+
AutoHtml.add_filter(:ted).with(:width => 640, :height => 360, :scrolling => "no", :frameborder => 0, :allow_full_screen => false) do |text, options|
|
3
|
+
text.gsub(/https?:\/\/(www.|embed.)?ted\.com\/talks\/([A-Za-z0-9._%-]*)\.html((\?|#)\S+)?/) do
|
4
|
+
ted_page = $2
|
5
|
+
width = options[:width]
|
6
|
+
height = options[:height]
|
7
|
+
scrolling = options[:scrolling]
|
8
|
+
frameborder = options[:frameborder]
|
9
|
+
allow_full_screen = options[:allow_full_screen]
|
10
|
+
|
11
|
+
%{<iframe width="#{width}" height="#{height}" frameborder="#{frameborder}" scrolling="#{scrolling}" src="http://embed.ted.com/talks/#{ted_page}.html"#{allow_full_screen ? ' webkitAllowFullScreen mozallowfullscreen allowFullScreen' : ''}></iframe>}
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
AutoHtml.add_filter(:twitter).with({}) do |text, options|
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+(/?)}
|
6
|
+
|
7
|
+
text.gsub(regex) do |match|
|
8
|
+
params = { :url => match }.merge(options)
|
9
|
+
|
10
|
+
uri = URI("https://api.twitter.com/1/statuses/oembed.json")
|
11
|
+
uri.query = URI.encode_www_form(params)
|
12
|
+
|
13
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
14
|
+
http.use_ssl = true
|
15
|
+
|
16
|
+
response = JSON.parse(http.get(uri.request_uri).body)
|
17
|
+
response["html"]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :show_byline => false, :show_portrait => false) do |text, options|
|
2
|
+
text.gsub(/https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
|
3
|
+
vimeo_id = $2
|
4
|
+
width = options[:width]
|
5
|
+
height = options[:height]
|
6
|
+
show_title = "title=0" unless options[:show_title]
|
7
|
+
show_byline = "byline=0" unless options[:show_byline]
|
8
|
+
show_portrait = "portrait=0" unless options[:show_portrait]
|
9
|
+
frameborder = options[:frameborder] || 0
|
10
|
+
query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
|
11
|
+
query_string = "?" + query_string_variables unless query_string_variables.empty?
|
12
|
+
|
13
|
+
%{<div class="video-container vimeo"><iframe src="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe></div>}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
AutoHtml.add_filter(:worldstar).with(:width => 448, :height => 374) do |text,options|
|
2
|
+
text.gsub(/http:\/\/www\.worldstarhiphop\.com\/videos\/video\.php\?v\=(wshh[A-Za-z0-9]+)/) do
|
3
|
+
video_id = $1
|
4
|
+
width = options[:width]
|
5
|
+
height = options[:height]
|
6
|
+
%{<div class="video-container worldstar"><object width="#{width}" height="#{height}"><param name="movie" value="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}"><param name="allowFullScreen" value="true"></param><embed src="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}" type="application/x-shockwave-flash" allowFullscreen="true" width="#{width}" height="#{height}"></embed></object></div>}
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
|
2
|
+
regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
|
3
|
+
text.gsub(regex) do
|
4
|
+
youtube_id = $4
|
5
|
+
width = options[:width]
|
6
|
+
height = options[:height]
|
7
|
+
frameborder = options[:frameborder]
|
8
|
+
wmode = options[:wmode]
|
9
|
+
autoplay = options[:autoplay]
|
10
|
+
hide_related = options[:hide_related]
|
11
|
+
src = "//www.youtube.com/embed/#{youtube_id}"
|
12
|
+
params = []
|
13
|
+
params << "wmode=#{wmode}" if wmode
|
14
|
+
params << "autoplay=1" if autoplay
|
15
|
+
params << "rel=0" if hide_related
|
16
|
+
src += "?#{params.join '&'}" unless params.empty?
|
17
|
+
%{<div class="video-container youtube"><iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe></div>}
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
AutoHtml.add_filter(:youtube_image).with(:width => 320, :height => 315, :style => 'medium', :target => 'blank', :border => '0') do |text, options|
|
2
|
+
styles = { 'default' => 'default', 'high' => 'hqdefault',
|
3
|
+
'medium' => 'mqdefault', 'normal' => 'sddefault',
|
4
|
+
'max' => 'maxresdefault' }
|
5
|
+
regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
|
6
|
+
text.gsub(regex) do
|
7
|
+
youtube_id = $4
|
8
|
+
video_url = "https://www.youtube.com/watch?v=#{youtube_id}"
|
9
|
+
target = options[:target]
|
10
|
+
width = options[:width]
|
11
|
+
height = options[:height]
|
12
|
+
border = options[:border]
|
13
|
+
style = styles[options[:style]] rescue styles['default']
|
14
|
+
src = "//img.youtube.com/vi/#{youtube_id}/#{style}.jpg"
|
15
|
+
%{<div class="thumbnail youtube"><a href="#{video_url}" target="_#{target}"><img src="#{src}" width="#{width}" height="#{height}" border="#{border}"></a></div>}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:youtube_js_api).with(:width => 390, :height => 250) do |text, options|
|
2
|
+
text.gsub(/https?:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/) do
|
3
|
+
youtube_id = $2
|
4
|
+
%{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}" allowscriptaccess="always"></embed></object>}
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'auto_html/task'
|
2
|
+
|
3
|
+
# Rake task for rebuilding cached in DB auto_html columns values
|
4
|
+
# Usage: rake auto_html:rebuild CLASS=[your model]
|
5
|
+
# Where [your model] is the name of model which contains auto_html_for columns
|
6
|
+
|
7
|
+
namespace :auto_html do
|
8
|
+
desc "Rebuild auto_html columns"
|
9
|
+
task :rebuild => :environment do
|
10
|
+
|
11
|
+
klass = AutoHtml::Task.obtain_class.constantize
|
12
|
+
suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
13
|
+
column_names = klass.respond_to?(:column_names) ? klass.column_names : klass.fields.keys
|
14
|
+
observed_attributes = column_names.select { |c| c=~/#{suffix}$/ }.map { |c| c.gsub(/#{suffix}$/, '')}
|
15
|
+
|
16
|
+
i = 0
|
17
|
+
klass.find_each do |item|
|
18
|
+
observed_attributes.each do |field|
|
19
|
+
item.send("#{field}=", item.send(field))
|
20
|
+
end
|
21
|
+
item.save
|
22
|
+
i += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
puts "Done! Processed #{i} items."
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FixtureSetup
|
2
|
+
fixtures_dir = File.dirname(__FILE__) + '/fixtures'
|
3
|
+
connections = YAML.load_file("#{fixtures_dir}/database.yml")
|
4
|
+
ActiveRecord::Base.establish_connection(connections['sqlite3'])
|
5
|
+
ActiveRecord::Migration.verbose = false
|
6
|
+
load "#{fixtures_dir}/schema.rb"
|
7
|
+
|
8
|
+
def setup
|
9
|
+
fixtures_dir = File.dirname(__FILE__) + '/fixtures'
|
10
|
+
ActiveRecord::Migration.verbose = false
|
11
|
+
load "#{fixtures_dir}/schema.rb"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => Time.now.to_i) do
|
2
|
+
create_table "articles", :force => true do |t|
|
3
|
+
t.column "title", :string
|
4
|
+
t.column "body", :text
|
5
|
+
t.column "body_html", :text
|
6
|
+
t.column "created_at", :datetime
|
7
|
+
t.column "updated_at", :datetime
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table "users", :force => true do |t|
|
11
|
+
t.column "name", :string
|
12
|
+
t.column "bio", :text
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table "posts", :force => true do |t|
|
16
|
+
t.column "topic_id", :integer
|
17
|
+
t.column "user_id", :integer
|
18
|
+
t.column "content", :text
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require File.expand_path('../../fixture_setup', __FILE__)
|
3
|
+
|
4
|
+
# store default so we can revert so that other tests use default option
|
5
|
+
default_suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
6
|
+
AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = '_htmlized'
|
7
|
+
|
8
|
+
class Post < ActiveRecord::Base
|
9
|
+
auto_html_for :content do
|
10
|
+
simple_format
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class AutoHtmlForOptionsTest < Minitest::Test
|
15
|
+
include FixtureSetup
|
16
|
+
|
17
|
+
def test_transform_after_save
|
18
|
+
@article = Post.new(:content => 'Yo!')
|
19
|
+
assert_equal '<p>Yo!</p>', @article.content_htmlized
|
20
|
+
@article.save!
|
21
|
+
assert_equal '<p>Yo!</p>', @article.content_htmlized
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# reverting to default so that other tests use default option
|
26
|
+
AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = default_suffix
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require File.expand_path('../../fixture_setup', __FILE__)
|
3
|
+
|
4
|
+
class Article < ActiveRecord::Base
|
5
|
+
auto_html_for :body do
|
6
|
+
html_escape
|
7
|
+
youtube(:width => 400, :height => 250)
|
8
|
+
image
|
9
|
+
link(:target => "_blank")
|
10
|
+
simple_format
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_attribute :plain_body, :body
|
14
|
+
auto_html_for :plain_body do
|
15
|
+
html_escape
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class AutoHtmlForTest < Minitest::Test
|
20
|
+
include FixtureSetup
|
21
|
+
|
22
|
+
def test_transform_on_initialization
|
23
|
+
@article = Article.new(:body => 'Yo!')
|
24
|
+
assert_equal '<p>Yo!</p>', @article.body_html
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_html_safe
|
28
|
+
return unless "".respond_to?(:html_safe?)
|
29
|
+
@article = Article.new(:body => 'Yo!')
|
30
|
+
assert @article.body_html.html_safe?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_transform_after_save
|
34
|
+
@article = Article.new(:body => 'Yo!')
|
35
|
+
@article.save!
|
36
|
+
assert_equal '<p>Yo!</p>', @article.body_html
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_transform_of_nil
|
40
|
+
@article = Article.new(:body => nil)
|
41
|
+
@article.save!
|
42
|
+
assert_equal '', @article.body_html
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_transform_after_update
|
46
|
+
@article = Article.create!(:body => 'Yo!')
|
47
|
+
@article.update_attributes(:body => 'http://vukajlija.com')
|
48
|
+
@article.save!
|
49
|
+
assert_equal '<p><a href="http://vukajlija.com" target="_blank">http://vukajlija.com</a></p>', @article.body_html
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_transform_of_alias_attribute
|
53
|
+
@article = Article.new(:body => 'Hello there.')
|
54
|
+
assert_equal 'Hello there.', @article.plain_body_html
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require File.expand_path('../../fixture_setup', __FILE__)
|
3
|
+
|
4
|
+
AutoHtml.add_filter(:foo) do |text|
|
5
|
+
nil
|
6
|
+
end
|
7
|
+
|
8
|
+
AutoHtml.add_filter(:bar) do |text|
|
9
|
+
"bar"
|
10
|
+
end
|
11
|
+
|
12
|
+
class User < ActiveRecord::Base
|
13
|
+
auto_html_for :bio do
|
14
|
+
foo
|
15
|
+
foo
|
16
|
+
bar
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class FilterTest < Minitest::Test
|
21
|
+
include FixtureSetup
|
22
|
+
|
23
|
+
def test_transform_after_save
|
24
|
+
@article = User.new(:bio => 'in progress...')
|
25
|
+
assert_equal 'bar', @article.bio_html
|
26
|
+
end
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require 'active_record'
|
6
|
+
require 'action_view'
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_support/core_ext/class'
|
9
|
+
|
10
|
+
require 'minitest'
|
11
|
+
require 'minitest/focus'
|
12
|
+
|
13
|
+
require File.dirname(__FILE__) + '/../init'
|
14
|
+
|
15
|
+
require 'minitest/reporters'
|
16
|
+
MiniTest::Reporters.use!
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../unit_test_helper', __FILE__)
|
2
|
+
|
3
|
+
|
4
|
+
class AutoHtmlTest < Minitest::Test
|
5
|
+
|
6
|
+
def test_should_be_raw_input_when_no_filters_provided
|
7
|
+
input = "Hey check out my blog => http://rors.org"
|
8
|
+
result = auto_html(input) { }
|
9
|
+
assert_equal result, input
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_apply_simple_format_filter
|
13
|
+
result = auto_html("Hey check out my blog => http://rors.org") { simple_format }
|
14
|
+
assert_equal "<p>Hey check out my blog => http://rors.org</p>", result
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_apply_simple_format_and_image_filter
|
18
|
+
result = auto_html("Check the logo: http://rors.org/images/rails.png") { simple_format; image(:alt => nil) }
|
19
|
+
assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/></p>', result
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_apply_simple_format_image_and_link_filter
|
23
|
+
result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image(:alt => nil); link }
|
24
|
+
assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/>. Visit: <a href="http://rubyonrails.org" >http://rubyonrails.org</a></p>', result
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_return_blank_if_input_is_blank
|
28
|
+
result = auto_html("") { simple_format; image(:alt => nil); link }
|
29
|
+
assert_equal "", result
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_not_apply_simple_format_if_input_is_nil
|
33
|
+
result = auto_html(nil) { simple_format; image(:alt => nil); link }
|
34
|
+
assert_equal "", result
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../../unit_test_helper', __FILE__)
|
2
|
+
|
3
|
+
class DailyMotionTest < Minitest::Test
|
4
|
+
|
5
|
+
DIV_START = '<div class="video-container dailymotion">'
|
6
|
+
|
7
|
+
def test_transform
|
8
|
+
result = auto_html("http://www.dailymotion.com/en/featured/video/xag4p2_tempsmorttv-episode-01_shortfilms") { dailymotion }
|
9
|
+
assert_equal %Q|#{DIV_START}<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xag4p2_tempsmorttv-episode-01_shortfilms&related=0" width="480" height="360"><param name="movie" value="http://www.dailymotion.com/swf/xag4p2_tempsmorttv-episode-01_shortfilms&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xag4p2_tempsmorttv-episode-01_shortfilms?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xag4p2_tempsmorttv-episode-01_shortfilms" width="480" height="360"/></a></object></div>|, result
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_transform_with_tweaked_width
|
13
|
+
result = auto_html("http://www.dailymotion.com/related/x9cyf6/video/x9tinl_happy-tree-friends-as-you-wish-part_fun") { dailymotion :width => 500 }
|
14
|
+
assert_equal %Q|#{DIV_START}<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/x9tinl_happy-tree-friends-as-you-wish-part_fun&related=0" width="500" height="360"><param name="movie" value="http://www.dailymotion.com/swf/x9tinl_happy-tree-friends-as-you-wish-part_fun&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/x9tinl_happy-tree-friends-as-you-wish-part_fun?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/x9tinl_happy-tree-friends-as-you-wish-part_fun" width="500" height="360"/></a></object></div>|, result
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_transform_with_options
|
18
|
+
result = auto_html("http://www.dailymotion.com/video/xakv5i") { dailymotion(:width => 500, :height => 300) }
|
19
|
+
assert_equal %Q|#{DIV_START}<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xakv5i&related=0" width="500" height="300"><param name="movie" value="http://www.dailymotion.com/swf/xakv5i&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xakv5i?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xakv5i" width="500" height="300"/></a></object></div>|, result
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def test_prevent_html_transform
|
24
|
+
str = '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xakv5i&related=0" width="500" height="300"><param name="movie" value="http://www.dailymotion.com/swf/xakv5i&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xakv5i?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xakv5i" width="500" height="300"/></a></object>'
|
25
|
+
|
26
|
+
result = auto_html(str) { dailymotion(:width => 500, :height => 300) }
|
27
|
+
|
28
|
+
assert_equal(
|
29
|
+
str, result,
|
30
|
+
"Should not re-transform HTML with dailymotion links inside of it"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|