galetahub-auto_html 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/MIT-LICENCE +20 -0
  2. data/README.rdoc +111 -0
  3. data/Rakefile +26 -0
  4. data/VERSION +1 -0
  5. data/galetahub-auto_html.gemspec +75 -0
  6. data/init.rb +2 -0
  7. data/lib/auto_html.rb +15 -0
  8. data/lib/auto_html/auto_html_for.rb +37 -0
  9. data/lib/auto_html/base.rb +14 -0
  10. data/lib/auto_html/builder.rb +22 -0
  11. data/lib/auto_html/engine.rb +18 -0
  12. data/lib/auto_html/filter.rb +23 -0
  13. data/lib/auto_html/filters/big_words.rb +9 -0
  14. data/lib/auto_html/filters/dailymotion.rb +6 -0
  15. data/lib/auto_html/filters/google_video.rb +6 -0
  16. data/lib/auto_html/filters/html_escape.rb +9 -0
  17. data/lib/auto_html/filters/image.rb +5 -0
  18. data/lib/auto_html/filters/link.rb +5 -0
  19. data/lib/auto_html/filters/sanitize.rb +6 -0
  20. data/lib/auto_html/filters/simple_format.rb +9 -0
  21. data/lib/auto_html/filters/vimeo.rb +15 -0
  22. data/lib/auto_html/filters/youtube.rb +6 -0
  23. data/lib/auto_html/filters/youtube_js_api.rb +6 -0
  24. data/test/fixture_setup.rb +9 -0
  25. data/test/fixtures/database.yml +5 -0
  26. data/test/fixtures/schema.rb +10 -0
  27. data/test/functional/auto_html_for_options_test.rb +25 -0
  28. data/test/functional/auto_html_for_test.rb +29 -0
  29. data/test/test_helper.rb +6 -0
  30. data/test/unit/auto_html_test.rb +25 -0
  31. data/test/unit/filters/dailymotion_test.rb +20 -0
  32. data/test/unit/filters/google_video_test.rb +15 -0
  33. data/test/unit/filters/html_escape_test.rb +15 -0
  34. data/test/unit/filters/image_test.rb +45 -0
  35. data/test/unit/filters/link_test.rb +50 -0
  36. data/test/unit/filters/sanitize_test.rb +36 -0
  37. data/test/unit/filters/simple_format_test.rb +15 -0
  38. data/test/unit/filters/vimeo_test.rb +50 -0
  39. data/test/unit/filters/youtube_js_api_test.rb +30 -0
  40. data/test/unit/filters/youtube_test.rb +30 -0
  41. data/test/unit/unit_test_helper.rb +3 -0
  42. metadata +107 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dejan Simic
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ = Auto html
2
+
3
+ Rails plugin for transforming urls to appropriate resource (image, link, YouTube, Vimeo video,...).
4
+ Check out the {live demo}[http://auto-html.rors.org].
5
+
6
+ == Synopsis
7
+
8
+ auto_html plugin is the perfect choice if you don't want to bother visitors with rich HTML editor or markup code, but you still want to allow them to embed video, images, links and more on your site, purely by pasting URL.
9
+
10
+ Let's say you have model Comment with attribute body. Create another column in table Comments called body_html. Now have something like this:
11
+
12
+ class Comment < ActiveRecord::Base
13
+ auto_html_for :body do
14
+ html_escape
15
+ image
16
+ youtube :width => 400, :height => 250
17
+ link :target => "_blank", :rel => "nofollow"
18
+ simple_format
19
+ end
20
+ end
21
+
22
+ ... and you'll have this behaviour:
23
+
24
+ Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
25
+ => #<Comment id: 123, body: 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4', body_html: '<p>Hey check out this cool video: <object height="250" width="400"><param name="movie" value="http://www.youtube.com/v/WdsGihou8J4" /><param name="wmode" value="transparent" /><embed src="http://www.youtube.com/v/WdsGihou8J4" type="application/x-shockwave-flash" height="250" wmode="transparent" width="400"></embed></object></p>'>
26
+
27
+ Note that order of invoking filters is important, ie. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
28
+
29
+
30
+ Now all you have to do is to display it in template without escaping, since plugin took care of that:
31
+
32
+ <% for comment in @comments %>
33
+ <li><%= comment.body_html %></li>
34
+ <% end %>
35
+
36
+
37
+ If you need to display preview, no problem. Have something like this as action in your controller:
38
+
39
+ def preview
40
+ comment = Comment.new(params[:comment])
41
+ comment.auto_html_prepare
42
+ render :text => comment.body_html
43
+ end
44
+
45
+ Plugin is highly customizable, and you can easily create new filters that will transform user input any way you like. For instance, this is the image filter that comes bundled with plugin:
46
+
47
+ AutoHtml.add_filter(:image) do |text|
48
+ text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
49
+ %|<img src="#{match}" alt=""/>|
50
+ end
51
+ end
52
+
53
+
54
+ == Bundled filters
55
+
56
+ * Big words - take big words in special tags
57
+
58
+ big_words :length => 80, :tag => "span"
59
+
60
+ * Dailymotion
61
+
62
+ dailymotion :width => 480, :height => 360
63
+
64
+ * Google video
65
+
66
+ google_video :width => 650, :height => 391
67
+
68
+ * HTML escaping
69
+
70
+ html_escape
71
+
72
+ * Image - replace image url to url with <a>
73
+
74
+ image
75
+
76
+ * Link - replace url to url with <a>
77
+
78
+ link :target => "_blank", :rel => "nofollow"
79
+
80
+ * HTML White List Sanitizer
81
+
82
+ sanitize
83
+
84
+ * Simple format
85
+
86
+ simple_format
87
+
88
+ * Vimeo
89
+
90
+ vimeo :width => 440, :height => 248, :show_title => false, :fullscreen => true, :show_byline => false, :show_portrait => false
91
+
92
+ * Youtube
93
+
94
+ youtube :width => 390, :height => 250
95
+
96
+ youtube_js_api :width => 390, :height => 250
97
+
98
+ == Install
99
+
100
+ gem 'auto_html', :git => 'git://github.com/galetahub/auto_html.git'
101
+
102
+ == Links:
103
+
104
+ * http://auto-html.rors.org
105
+ * http://www.elctech.com/projects/auto_html-plugin
106
+
107
+
108
+ == Credits
109
+
110
+ Author:: {Dejan Simic}[http://github.com/dejan]
111
+ Contributor:: {Claudio Perez Gamayo}[http://github.com/crossblaim]
@@ -0,0 +1,26 @@
1
+ require 'rake/testtask'
2
+
3
+ desc 'Default: run tests'
4
+ task :default => :test
5
+
6
+ desc 'Test AutoHtml'
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.pattern = 'test/**/*_test.rb'
9
+ end
10
+
11
+ begin
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "galetahub-auto_html"
15
+ gem.summary = %{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
16
+ gem.email = "galeta.igor@gmail.com"
17
+ gem.homepage = "https://github.com/galetahub/auto_html"
18
+ gem.description = "Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document"
19
+ gem.authors = ["Igor Galeta"]
20
+ gem.files.exclude 'test.sqlite3'
21
+ gem.has_rdoc = false
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ end
26
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{galetahub-auto_html}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Igor Galeta"]
12
+ s.date = %q{2011-08-16}
13
+ s.description = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
14
+ s.email = %q{galeta.igor@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENCE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "galetahub-auto_html.gemspec",
24
+ "init.rb",
25
+ "lib/auto_html.rb",
26
+ "lib/auto_html/auto_html_for.rb",
27
+ "lib/auto_html/base.rb",
28
+ "lib/auto_html/builder.rb",
29
+ "lib/auto_html/engine.rb",
30
+ "lib/auto_html/filter.rb",
31
+ "lib/auto_html/filters/big_words.rb",
32
+ "lib/auto_html/filters/dailymotion.rb",
33
+ "lib/auto_html/filters/google_video.rb",
34
+ "lib/auto_html/filters/html_escape.rb",
35
+ "lib/auto_html/filters/image.rb",
36
+ "lib/auto_html/filters/link.rb",
37
+ "lib/auto_html/filters/sanitize.rb",
38
+ "lib/auto_html/filters/simple_format.rb",
39
+ "lib/auto_html/filters/vimeo.rb",
40
+ "lib/auto_html/filters/youtube.rb",
41
+ "lib/auto_html/filters/youtube_js_api.rb",
42
+ "test/fixture_setup.rb",
43
+ "test/fixtures/database.yml",
44
+ "test/fixtures/schema.rb",
45
+ "test/functional/auto_html_for_options_test.rb",
46
+ "test/functional/auto_html_for_test.rb",
47
+ "test/test_helper.rb",
48
+ "test/unit/auto_html_test.rb",
49
+ "test/unit/filters/dailymotion_test.rb",
50
+ "test/unit/filters/google_video_test.rb",
51
+ "test/unit/filters/html_escape_test.rb",
52
+ "test/unit/filters/image_test.rb",
53
+ "test/unit/filters/link_test.rb",
54
+ "test/unit/filters/sanitize_test.rb",
55
+ "test/unit/filters/simple_format_test.rb",
56
+ "test/unit/filters/vimeo_test.rb",
57
+ "test/unit/filters/youtube_js_api_test.rb",
58
+ "test/unit/filters/youtube_test.rb",
59
+ "test/unit/unit_test_helper.rb"
60
+ ]
61
+ s.homepage = %q{https://github.com/galetahub/auto_html}
62
+ s.require_paths = ["lib"]
63
+ s.rubygems_version = %q{1.6.2}
64
+ s.summary = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
65
+
66
+ if s.respond_to? :specification_version then
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
+ else
71
+ end
72
+ else
73
+ end
74
+ end
75
+
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'auto_html'
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module AutoHtml
3
+ autoload :Base, 'auto_html/base'
4
+ autoload :Filter, 'auto_html/filter'
5
+ autoload :Builder, 'auto_html/builder'
6
+ autoload :AutoHtmlFor, 'auto_html/auto_html_for'
7
+
8
+ class << self
9
+ def add_filter(name, &block)
10
+ Builder.add_filter(name, &block)
11
+ end
12
+ end
13
+ end
14
+
15
+ require 'auto_html/engine' if defined?(Rails)
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module AutoHtml
3
+ module AutoHtmlFor
4
+
5
+ # default options that can be overridden on the global level
6
+ @@auto_html_for_options = {
7
+ :htmlized_attribute_suffix => '_html'
8
+ }
9
+ mattr_reader :auto_html_for_options
10
+
11
+ def self.included(base)
12
+ base.send(:extend, ClassMethods)
13
+ end
14
+
15
+ module ClassMethods
16
+ def auto_html_for(raw_attrs, &proc)
17
+ include AutoHtml::Base::InstanceMethods
18
+
19
+ before_save :auto_html_prepare
20
+
21
+ define_method("auto_html_prepare") do
22
+ auto_html_methods = self.methods.select { |m| m=~/^auto_html_prepare_/ }
23
+ auto_html_methods.each do |method|
24
+ self.send(method)
25
+ end
26
+ end
27
+
28
+ [raw_attrs].flatten.each do |raw_attr|
29
+ define_method("auto_html_prepare_#{raw_attr}") do
30
+ suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
31
+ self.send("#{raw_attr}#{suffix}=", auto_html(self.send(raw_attr), &proc))
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ module AutoHtml
3
+ module Base
4
+ module InstanceMethods
5
+ def auto_html(raw, &proc)
6
+ unless raw.blank?
7
+ builder = AutoHtml::Builder.new(raw)
8
+ builder.instance_eval(&proc)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ module AutoHtml
3
+ class Builder
4
+ @@filters = {}
5
+
6
+ def initialize(text)
7
+ @text = text.dup
8
+ end
9
+
10
+ def self.add_filter(name, &block)
11
+ filter = Filter.new(block)
12
+ @@filters.merge!(name => filter)
13
+ src = %|
14
+ def #{name}(options = {})
15
+ @text = @@filters["#{name}".to_sym].apply(@text, options)
16
+ end
17
+ |
18
+ class_eval src, __FILE__, __LINE__
19
+ filter
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'rails'
3
+ require 'auto_html'
4
+
5
+ module AutoHtml
6
+ class Engine < ::Rails::Engine
7
+ config.before_initialize do
8
+ # Register built-in filters
9
+ Dir["#{File.dirname(__FILE__)}/filters/*.rb"].sort.each do |path|
10
+ require "auto_html/filters/#{File.basename(path, '.rb')}"
11
+ end
12
+
13
+ ActiveSupport.on_load :active_record do
14
+ ActiveRecord::Base.send :include, AutoHtml::AutoHtmlFor
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ module AutoHtml
3
+ class Filter
4
+ def initialize(block)
5
+ @block = block
6
+ @options = nil
7
+ end
8
+
9
+ def with(options, &block)
10
+ @options = options
11
+ @block = block
12
+ end
13
+
14
+ def apply(text, options = {})
15
+ _options = @options && @options.merge(options)
16
+ if _options
17
+ @block.call(text.dup, _options)
18
+ else
19
+ @block.call(text.dup)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ AutoHtml.add_filter(:big_words).with(:length => 80, :tag => "span") do |text, options|
2
+ text.gsub(/\w+/) do |word|
3
+ if word.size >= options[:length]
4
+ word.scan(/\w{1,5}/).collect { |item| "<#{options[:tag]}>#{item}</#{options[:tag]}>" }.join
5
+ else
6
+ word
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ AutoHtml.add_filter(:dailymotion).with(:width => 480, :height => 360) do |text, options|
2
+ text.gsub(/http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/) do
3
+ video_id = $1
4
+ %{<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/#{video_id}&related=0" width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://www.dailymotion.com/swf/#{video_id}&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/#{video_id}?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/#{video_id}" width="#{options[:width]}" height="#{options[:height]}"/></a></object>}
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ AutoHtml.add_filter(:google_video).with(:width => 650, :height => 391) do |text, options|
2
+ text.gsub(/http:\/\/video\.google\.com\/videoplay\?docid\=(-?[0-9]*)[&\w;=\+_\-]*/) do
3
+ docid = $1
4
+ %{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://video.google.com/googleplayer.swf?docid=#{docid}&hl=en&fs=true"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docid=#{docid}" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ AutoHtml.add_filter(:html_escape).with(
2
+ :map => {
3
+ '&' => '&amp;',
4
+ '>' => '&gt;',
5
+ '<' => '&lt;',
6
+ '"' => '&quot;' }) do |text, options|
7
+
8
+ text.to_s.gsub(/[&"><]/) { |special| options[:map][special] }
9
+ end
@@ -0,0 +1,5 @@
1
+ AutoHtml.add_filter(:image) do |text|
2
+ text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
3
+ %|<img src="#{match}" alt=""/>|
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'action_view'
2
+
3
+ AutoHtml.add_filter(:link).with({}) do |text, options|
4
+ ActionView::Base.new.auto_link(text, :all, options)
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'action_controller'
2
+ require 'cgi'
3
+
4
+ AutoHtml.add_filter(:sanitize).with({}) do |text, options|
5
+ HTML::WhiteListSanitizer.new.sanitize(text, options)
6
+ end
@@ -0,0 +1,9 @@
1
+ AutoHtml.add_filter(:simple_format) do |text|
2
+ start_tag = "<p>".html_safe
3
+ text = text.to_s.dup
4
+ text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
5
+ text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
6
+ text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
7
+ text.insert 0, start_tag
8
+ text.html_safe.safe_concat("</p>")
9
+ end
@@ -0,0 +1,15 @@
1
+ AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :fullscreen => true, :show_byline => false, :show_portrait => false) do |text, options|
2
+ text.gsub(/http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
3
+ vimeo_id = $2
4
+
5
+ width = options[:width]
6
+ height = options[:height]
7
+
8
+ allowfullscreen = options[:fullscreen]
9
+ fullscreen = options[:fullscreen] ? 1 : 0
10
+ show_title = options[:show_title] ? 1 : 0
11
+ show_byline = options[:show_byline] ? 1 : 0
12
+ show_portrait = options[:show_portrait] ? 1 : 0
13
+ %{<object width="#{width}" height="#{height}"><param name="allowfullscreen" value="#{allowfullscreen}" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=#{vimeo_id}&amp;server=vimeo.com&amp;show_title=#{show_title}&amp;show_byline=#{show_byline}&amp;show_portrait=#{show_portrait}&amp;color=00adef&amp;fullscreen=#{fullscreen}" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=#{vimeo_id}&amp;server=vimeo.com&amp;show_title=#{show_title}&amp;show_byline=#{show_byline}&amp;show_portrait=#{show_portrait}&amp;color=00adef&amp;fullscreen=#{fullscreen}" type="application/x-shockwave-flash" allowfullscreen="#{allowfullscreen}" allowscriptaccess="always" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ AutoHtml.add_filter(:youtube).with(:width => 390, :height => 250) do |text, options|
2
+ text.gsub(/http:\/\/(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="http://www.youtube.com/v/#{youtube_id}"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/#{youtube_id}" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ AutoHtml.add_filter(:youtube_js_api).with(:width => 390, :height => 250) do |text, options|
2
+ text.gsub(/http:\/\/(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="http://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="http://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,9 @@
1
+ module FixtureSetup
2
+ def setup
3
+ fixtures_dir = File.dirname(__FILE__) + '/fixtures'
4
+ connections = YAML.load_file("#{fixtures_dir}/database.yml")
5
+ ActiveRecord::Base.establish_connection(connections['sqlite3'])
6
+ ActiveRecord::Migration.verbose = false
7
+ load "#{fixtures_dir}/schema.rb"
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Schema.define 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 "body_htmlized", :text
7
+ t.column "created_at", :datetime
8
+ t.column "updated_at", :datetime
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../fixture_setup'
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 Article < ActiveRecord::Base
9
+ auto_html_for :body do
10
+ simple_format
11
+ end
12
+ end
13
+
14
+ class AutoHtmlForTest < Test::Unit::TestCase
15
+ include FixtureSetup
16
+
17
+ def test_transform_after_save
18
+ @article = Article.new(:body => 'Yo!')
19
+ @article.save!
20
+ assert_equal '<p>Yo!</p>', @article.body_htmlized
21
+ end
22
+ end
23
+
24
+ # reverting to default so that other tests use default option
25
+ AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = default_suffix
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../fixture_setup'
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", :rel => "nofollow")
10
+ simple_format
11
+ end
12
+ end
13
+
14
+ class AutoHtmlForTest < Test::Unit::TestCase
15
+ include FixtureSetup
16
+
17
+ def test_transform_after_save
18
+ @article = Article.new(:body => 'Yo!')
19
+ @article.save!
20
+ assert_equal '<p>Yo!</p>', @article.body_html
21
+ end
22
+
23
+ def test_transform_after_update
24
+ @article = Article.create!(:body => 'Yo!')
25
+ @article.update_attributes(:body => 'http://vukajlija.com')
26
+ @article.save!
27
+ assert_equal '<p><a href="http://vukajlija.com" rel="nofollow" target="_blank">http://vukajlija.com</a></p>', @article.body_html
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_record'
4
+
5
+ require File.dirname(__FILE__) + '/../rails/init'
6
+
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/unit_test_helper'
2
+
3
+ class AutoHtmlTest < Test::Unit::TestCase
4
+
5
+ def test_should_be_nil_no_filters_provided
6
+ result = auto_html("Hey check out my blog => http://rors.org") { }
7
+ assert_nil result
8
+ end
9
+
10
+ def test_should_apply_simple_format_filter
11
+ result = auto_html("Hey check out my blog => http://rors.org") { simple_format }
12
+ assert_equal "<p>Hey check out my blog => http://rors.org</p>", result
13
+ end
14
+
15
+ def test_should_apply_simple_format_and_image_filter
16
+ result = auto_html("Check the logo: http://rors.org/images/rails.png") { simple_format; image }
17
+ assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/></p>', result
18
+ end
19
+
20
+ def test_should_apply_simple_format_image_and_link_filter
21
+ result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image; link }
22
+ 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
23
+ end
24
+
25
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class GoogleVideoTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html("http://www.dailymotion.com/en/featured/video/xag4p2_tempsmorttv-episode-01_shortfilms") { dailymotion }
7
+ assert_equal '<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>', result
8
+ end
9
+
10
+ def test_transform_with_tweaked_width
11
+ result = auto_html("http://www.dailymotion.com/related/x9cyf6/video/x9tinl_happy-tree-friends-as-you-wish-part_fun") { dailymotion :width => 500 }
12
+ assert_equal '<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>', result
13
+ end
14
+
15
+ def test_transform_with_options
16
+ result = auto_html("http://www.dailymotion.com/video/xakv5i") { dailymotion(:width => 500, :height => 300) }
17
+ assert_equal '<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>', result
18
+ end
19
+
20
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class GoogleVideoTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html("http://video.google.com/videoplay?docid=-7533500868750350977&ei=Xin8Sc-KBYeg2ALXkKymAQ&q=office+space&emb=1") { google_video }
7
+ assert_equal '<object width="650" height="391"><param name="movie" value="http://video.google.com/googleplayer.swf?docid=-7533500868750350977&hl=en&fs=true"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docid=-7533500868750350977" type="application/x-shockwave-flash" wmode="transparent" width="650" height="391"></embed></object>', result
8
+ end
9
+
10
+ def test_transform_with_options
11
+ result = auto_html("http://video.google.com/videoplay?docid=7442132741322615356") { google_video(:width => 500, :height => 300) }
12
+ assert_equal '<object width="500" height="300"><param name="movie" value="http://video.google.com/googleplayer.swf?docid=7442132741322615356&hl=en&fs=true"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docid=7442132741322615356" type="application/x-shockwave-flash" wmode="transparent" width="500" height="300"></embed></object>', result
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class HtmlEscapeTest < Test::Unit::TestCase
4
+
5
+ def test_trasform
6
+ result = auto_html("<script>alert(0)</script>") { html_escape }
7
+ assert_equal "&lt;script&gt;alert(0)&lt;/script&gt;", result
8
+ end
9
+
10
+ def test_trasform2
11
+ result = auto_html("<div>test</div>") { html_escape }
12
+ assert_equal "&lt;div&gt;test&lt;/div&gt;", result
13
+ end
14
+
15
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class ImageTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html('http://rors.org/images/rails.png') { image }
7
+ assert_equal '<img src="http://rors.org/images/rails.png" alt=""/>', result
8
+ end
9
+
10
+ def test_dont_transform
11
+ result = auto_html('http://blog.phusion.nl/2009/04/16/phusions-one-year-anniversary-gift-phusion-passenger-220/') { image }
12
+ assert_equal 'http://blog.phusion.nl/2009/04/16/phusions-one-year-anniversary-gift-phusion-passenger-220/', result
13
+ end
14
+
15
+ def test_transform2
16
+ result = auto_html('http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg') { image }
17
+ assert_equal '<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" alt=""/>', result
18
+ end
19
+
20
+ def test_transform3
21
+ result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image }
22
+ assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
23
+ end
24
+
25
+ def test_transform4
26
+ result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image }
27
+ assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
28
+ end
29
+
30
+ def test_transform5
31
+ result = auto_html('http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0') { image }
32
+ assert_equal '<img src="http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0" alt=""/>', result
33
+ end
34
+
35
+ def test_transform6
36
+ result = auto_html('Do you like this logo http://rors.org/images/rails.png? Yeah?') { image }
37
+ assert_equal 'Do you like this logo <img src="http://rors.org/images/rails.png" alt=""/>? Yeah?', result
38
+ end
39
+
40
+ def test_transform7
41
+ result = auto_html('http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg') { image }
42
+ assert_equal '<img src="http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg" alt=""/>', result
43
+ end
44
+
45
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class LinkTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html("http://vukajlija.com") { link }
7
+ assert_equal '<a href="http://vukajlija.com">http://vukajlija.com</a>', result
8
+ end
9
+
10
+ def test_transform_with_the_slash_at_the_end
11
+ result = auto_html("http://github.com/") { link }
12
+ assert_equal '<a href="http://github.com/">http://github.com/</a>', result
13
+ end
14
+
15
+ def test_transform_with_param
16
+ result = auto_html('http://example.com/abc?query=ruby') { link }
17
+ assert_equal '<a href="http://example.com/abc?query=ruby">http://example.com/abc?query=ruby</a>', result
18
+ end
19
+
20
+ def test_transform_with_param_and_trailing_dot
21
+ result = auto_html('http://example.com/abc?query=ruby.') { link }
22
+ assert_equal '<a href="http://example.com/abc?query=ruby">http://example.com/abc?query=ruby</a>.', result
23
+ end
24
+
25
+ def test_transform_with_anchor_and_trailing_dot
26
+ result = auto_html('http://example.com/example#id=123.12.') { link }
27
+ assert_equal '<a href="http://example.com/example#id=123.12">http://example.com/example#id=123.12</a>.', result
28
+ end
29
+
30
+ def test_transform_with_params
31
+ result = auto_html('http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related') { link }
32
+ assert_equal '<a href="http://www.youtube.com/watch?v=s5C5Zk4kobo&amp;feature=related">http://www.youtube.com/watch?v=s5C5Zk4kobo&amp;feature=related</a>', result
33
+ end
34
+
35
+ def test_transform_with_commas
36
+ result = auto_html('http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf') { link }
37
+ assert_equal '<a href="http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf">http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf</a>', result
38
+ end
39
+
40
+ def test_transform_complex_url
41
+ result = auto_html("http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0") { link }
42
+ assert_equal '<a href="http://www.google.com/#q=nikola+tesla&amp;ct=tesla09&amp;oi=ddle&amp;fp=Xmf0jJ9P_V0">http://www.google.com/#q=nikola+tesla&amp;ct=tesla09&amp;oi=ddle&amp;fp=Xmf0jJ9P_V0</a>', result
43
+ end
44
+
45
+ def test_transform_with_options
46
+ result = auto_html("http://rors.org") { link :rel => "nofollow", :target => "_blank" }
47
+ assert_equal '<a href="http://rors.org" rel="nofollow" target="_blank">http://rors.org</a>', result
48
+ end
49
+
50
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class SanitizeTest < Test::Unit::TestCase
4
+
5
+ def test_trasform
6
+ result = auto_html("<script>alert(0)</script>") { sanitize }
7
+ assert_equal "", result
8
+ end
9
+
10
+ def test_trasform2
11
+ result = auto_html("<div>test</div>") { sanitize }
12
+ assert_equal "<div>test</div>", result
13
+ end
14
+
15
+ def test_trasform3
16
+ result = auto_html("<div>test</div>") { sanitize :tags => %w(div) }
17
+ assert_equal "<div>test</div>", result
18
+ end
19
+
20
+ def test_trasform4
21
+ result = auto_html("<div>test</div>") { sanitize :tags => %w(p) }
22
+ assert_equal "test", result
23
+ end
24
+
25
+ def test_trasform5
26
+ result = auto_html("<a rel='nofollow'>test</div>") { sanitize :tags => %w(a), :attributes => %w(href)}
27
+ assert_equal "<a>test", result
28
+ #
29
+ # from Rails doc:
30
+ #
31
+ # Please note that sanitizing user-provided text does not
32
+ # guarantee that the resulting markup is valid.
33
+ #
34
+ end
35
+
36
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class SimpleFormatTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html('Hey check out my blog => http://rors.org') { simple_format }
7
+ assert_equal '<p>Hey check out my blog => http://rors.org</p>', result
8
+ end
9
+
10
+ def test_trasform2
11
+ result = auto_html('Hey check out my code => http://github.com/dejan') { simple_format }
12
+ assert_equal '<p>Hey check out my code => http://github.com/dejan</p>', result
13
+ end
14
+
15
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class VimeoTest < Test::Unit::TestCase
4
+
5
+ def test_transform_url_with_www
6
+ result = auto_html('http://www.vimeo.com/3300155') { vimeo }
7
+ assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3300155&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3300155&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
8
+ end
9
+
10
+ def test_transform_url_without_www
11
+ result = auto_html('http://vimeo.com/3300155') { vimeo }
12
+ assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3300155&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3300155&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
13
+ end
14
+
15
+ def test_transform_url_with_params
16
+ result = auto_html('http://vimeo.com/4635843?pg=embed&sec=') { vimeo }
17
+ assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4635843&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4635843&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
18
+ end
19
+
20
+ def test_transform_url_with_anchor
21
+ result = auto_html('http://vimeo.com/4695198#skirt') { vimeo }
22
+ assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4695198&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4695198&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
23
+ end
24
+
25
+ def test_transform_with_options
26
+ result = auto_html("http://www.vimeo.com/1472714") { vimeo(:width => 300, :height => 250) }
27
+ assert_equal '<object width="300" height="250"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="250"></embed></object>', result
28
+ end
29
+
30
+ def test_transform_with_fullscreen_false
31
+ result = auto_html("http://www.vimeo.com/1472714") { vimeo(:width => 300, :height => 250, :fullscreen => false) }
32
+ assert_equal '<object width="300" height="250"><param name="allowfullscreen" value="false" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=0" type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="always" width="300" height="250"></embed></object>', result
33
+ end
34
+
35
+ def test_transform_with_show_title
36
+ result = auto_html("http://www.vimeo.com/1472714") { vimeo(:width => 300, :height => 250, :show_title => true) }
37
+ assert_equal '<object width="300" height="250"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="250"></embed></object>', result
38
+ end
39
+
40
+ def test_transform_with_show_byline
41
+ result = auto_html("http://www.vimeo.com/1472714") { vimeo(:width => 300, :height => 250, :show_title => true, :show_byline => true) }
42
+ assert_equal '<object width="300" height="250"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="250"></embed></object>', result
43
+ end
44
+
45
+ def test_transform_with_show_show_portrait
46
+ result = auto_html("http://www.vimeo.com/1472714") { vimeo(:width => 300, :height => 250, :show_title => true, :show_byline => true, :show_portrait => true) }
47
+ assert_equal '<object width="300" height="250"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="250"></embed></object>', result
48
+ end
49
+
50
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class YouTubeJsApiTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube_js_api }
7
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
8
+ end
9
+
10
+ def test_transform2
11
+ result = auto_html('http://www.youtube.com/watch?v=3-ewi9saKg8&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube_js_api }
12
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/3-ewi9saKg8?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/3-ewi9saKg8?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
13
+ end
14
+
15
+ def test_transform3
16
+ result = auto_html('http://www.youtube.com/watch?v=Mw8KJ29qph0&feature=related') { youtube_js_api }
17
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/Mw8KJ29qph0?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Mw8KJ29qph0?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
18
+ end
19
+
20
+ def test_transform_url_without_www
21
+ result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube_js_api }
22
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
23
+ end
24
+
25
+ def test_transform_with_options
26
+ result = auto_html('http://www.youtube.com/watch?v=ZA1NoOOoaNw') { youtube_js_api(:width => 300, :height => 250) }
27
+ assert_equal '<object width="300" height="250"><param name="movie" value="http://www.youtube.com/v/ZA1NoOOoaNw?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZA1NoOOoaNw?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="300" height="250" allowscriptaccess="always"></embed></object>', result
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class YouTubeTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube }
7
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></embed></object>', result
8
+ end
9
+
10
+ def test_transform2
11
+ result = auto_html('http://www.youtube.com/watch?v=3-ewi9saKg8&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube }
12
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/3-ewi9saKg8"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/3-ewi9saKg8" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></embed></object>', result
13
+ end
14
+
15
+ def test_transform3
16
+ result = auto_html('http://www.youtube.com/watch?v=Mw8KJ29qph0&feature=related') { youtube }
17
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/Mw8KJ29qph0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Mw8KJ29qph0" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></embed></object>', result
18
+ end
19
+
20
+ def test_transform_url_without_www
21
+ result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube }
22
+ assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></embed></object>', result
23
+ end
24
+
25
+ def test_transform_with_options
26
+ result = auto_html('http://www.youtube.com/watch?v=ZA1NoOOoaNw') { youtube(:width => 300, :height => 250) }
27
+ assert_equal '<object width="300" height="250"><param name="movie" value="http://www.youtube.com/v/ZA1NoOOoaNw"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ZA1NoOOoaNw" type="application/x-shockwave-flash" wmode="transparent" width="300" height="250"></embed></object>', result
28
+ end
29
+
30
+ end
@@ -0,0 +1,3 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ include AutoHtml
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: galetahub-auto_html
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Igor Galeta
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-16 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
23
+ email: galeta.igor@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - MIT-LICENCE
32
+ - README.rdoc
33
+ - Rakefile
34
+ - VERSION
35
+ - galetahub-auto_html.gemspec
36
+ - init.rb
37
+ - lib/auto_html.rb
38
+ - lib/auto_html/auto_html_for.rb
39
+ - lib/auto_html/base.rb
40
+ - lib/auto_html/builder.rb
41
+ - lib/auto_html/engine.rb
42
+ - lib/auto_html/filter.rb
43
+ - lib/auto_html/filters/big_words.rb
44
+ - lib/auto_html/filters/dailymotion.rb
45
+ - lib/auto_html/filters/google_video.rb
46
+ - lib/auto_html/filters/html_escape.rb
47
+ - lib/auto_html/filters/image.rb
48
+ - lib/auto_html/filters/link.rb
49
+ - lib/auto_html/filters/sanitize.rb
50
+ - lib/auto_html/filters/simple_format.rb
51
+ - lib/auto_html/filters/vimeo.rb
52
+ - lib/auto_html/filters/youtube.rb
53
+ - lib/auto_html/filters/youtube_js_api.rb
54
+ - test/fixture_setup.rb
55
+ - test/fixtures/database.yml
56
+ - test/fixtures/schema.rb
57
+ - test/functional/auto_html_for_options_test.rb
58
+ - test/functional/auto_html_for_test.rb
59
+ - test/test_helper.rb
60
+ - test/unit/auto_html_test.rb
61
+ - test/unit/filters/dailymotion_test.rb
62
+ - test/unit/filters/google_video_test.rb
63
+ - test/unit/filters/html_escape_test.rb
64
+ - test/unit/filters/image_test.rb
65
+ - test/unit/filters/link_test.rb
66
+ - test/unit/filters/sanitize_test.rb
67
+ - test/unit/filters/simple_format_test.rb
68
+ - test/unit/filters/vimeo_test.rb
69
+ - test/unit/filters/youtube_js_api_test.rb
70
+ - test/unit/filters/youtube_test.rb
71
+ - test/unit/unit_test_helper.rb
72
+ has_rdoc: true
73
+ homepage: https://github.com/galetahub/auto_html
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.6.2
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
106
+ test_files: []
107
+