auto_html 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  test.sqlite3
2
+ TODO
@@ -0,0 +1,38 @@
1
+ ## edge (planned for 1.3)
2
+ * no need for explicit call to auto_html_prepare
3
+ * no need for DB column for cache (ie. _html)
4
+ * Rails 3 support
5
+ * correctly handle blank and nil values when applying auto_html
6
+ * more filters: youtube_js_api
7
+ * youtube filter supports html5
8
+
9
+
10
+ ## 1.2.1, released 2009-10-28
11
+
12
+ * more options for vimeo filter
13
+ * switch to gemcutter
14
+
15
+ ## 1.2.0, released 2009-09-26
16
+
17
+ * link filter now uses Rails' link discovery engine. Closes: <http://github.com/dejan/auto_html/issues#issue/2> and <http://github.com/dejan/auto_html/issues#issue/3> if Rails 2.3+ is in use.
18
+ * added dailymotion filter
19
+ * added sanitize filter
20
+
21
+ ## 1.1.2, released 2009-09-24
22
+
23
+ * link filter fix. Closes: <http://github.com/dejan/auto_html/issues#issue/2>
24
+
25
+ ## 1.1.1, released 2009-09-06
26
+
27
+ * test_helper fix
28
+
29
+ ## 1.1.0, released 2009-09-05
30
+
31
+ * Plugin gemified
32
+ * AutoHtmlFor.options[:htmlized_attribute_suffix] is now AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]. Closes gh-1
33
+ * Removed deezer filter since deezer.com no longer provides sharing of this kind
34
+
35
+ ## 1.0.0
36
+
37
+ * Stuff described here: <http://www.elctech.com/projects/auto_html-plugin>
38
+
@@ -0,0 +1,84 @@
1
+ auto_html
2
+ =========
3
+
4
+ auto_html is a Rails extension for transforming URLs to appropriate resource (image, link, YouTube, Vimeo video,...). It's 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. Check out the [live demo](http://auto-html.rors.org).
5
+
6
+
7
+ ## Example usage
8
+
9
+ Let's say you have model Comment with attribute body. Create another column in table Comments called body_html (this is optional, but recommended for performance reasons). Now have something like this:
10
+
11
+ class Comment < ActiveRecord::Base
12
+ auto_html_for :body do
13
+ html_escape
14
+ image
15
+ youtube(:width => 400, :height => 250)
16
+ link :target => "_blank", :rel => "nofollow"
17
+ simple_format
18
+ end
19
+ end
20
+
21
+ ... and you'll have this behaviour:
22
+
23
+ Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
24
+ => #<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>'>
25
+
26
+ 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.
27
+
28
+
29
+ Now all you have to do is to display it in template without escaping, since plugin took care of that:
30
+
31
+ <% for comment in @comments %>
32
+ <li><%= comment.body_html %></li>
33
+ <% end %>
34
+
35
+
36
+ If you need to display preview, no problem. Have something like this as action in your controller:
37
+
38
+ def preview
39
+ comment = Comment.new(params[:comment])
40
+ render :text => comment.body_html
41
+ end
42
+
43
+ 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:
44
+
45
+ AutoHtml.add_filter(:image) do |text|
46
+ text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
47
+ %|<img src="#{match}" alt=""/>|
48
+ end
49
+ end
50
+
51
+
52
+ ## Bundled filters
53
+
54
+ For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
55
+
56
+
57
+ ## Install
58
+
59
+ ### Important note on versions
60
+
61
+ As from version 1.2.0 auto_html uses Rails' engine for discovering links. There are some bugs with that engine in versions under Rails 2.3.2. so it's recommended you use auto_html 1.1.2 in that case, since internal engine is used in that version.
62
+
63
+ > for Rails <= 2.3.1 use auto_html 1.1.2<br/>
64
+ > for Rails >= 2.3.2 use auto_html 1.2.1
65
+
66
+ auto_html has been tested to work with Rails 3 and Ruby 1.9.
67
+
68
+ ### As a gem
69
+
70
+ To enable the library in your Rails 2.1 (or greater) project, use the gem configuration method in "config/environment.rb"
71
+
72
+ Rails::Initializer.run do |config|
73
+ config.gem 'auto_html', :version => '~> 1.2.1'
74
+ end
75
+
76
+ ### As a Rails plugin
77
+
78
+ script/plugin install git://github.com/dejan/auto_html.git
79
+
80
+
81
+ ## Credits
82
+
83
+ Author: [Dejan Simic](http://github.com/dejan)<br/>
84
+ Contributors: [Claudio Perez Gamayo](http://github.com/crossblaim), [Matt Polito](http://github.com/mattpolito), [Ryan Heneise](http://github.com/mysmallidea), [Caleb Wright](http://github.com/fabrikagency)
data/Rakefile CHANGED
@@ -8,6 +8,28 @@ Rake::TestTask.new(:test) do |t|
8
8
  t.pattern = 'test/**/*_test.rb'
9
9
  end
10
10
 
11
+ desc 'Test with recent versions of Rails'
12
+ task :test_with_recent do
13
+ versions = ['2.3.6', '3.0.0.beta4']
14
+ versions.each do |v|
15
+ puts "\n###### TESTING WITH RAILS #{v}"
16
+ ENV['RAILS_VERSION'] = v
17
+ Rake::Task['test'].execute
18
+ end
19
+ end
20
+
21
+ desc 'Test with versions of Rails available on the system'
22
+ task :test_with_installed do
23
+ versions = `gem list rails | grep rails`.gsub("rails (", "").chop.split(', ')
24
+ exclude = []
25
+ (versions-exclude).each do |v|
26
+ puts "\n###### TESTING WITH RAILS #{v}"
27
+ ENV['RAILS_VERSION'] = v
28
+ Rake::Task['test'].execute
29
+ end
30
+ end
31
+
32
+
11
33
  begin
12
34
  require 'jeweler'
13
35
  Jeweler::Tasks.new do |gem|
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 2
4
- :patch: 1
3
+ :minor: 3
4
+ :patch: 0
@@ -1,25 +1,25 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{auto_html}
8
- s.version = "1.2.1"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dejan Simic"]
12
- s.date = %q{2009-10-28}
12
+ s.date = %q{2010-08-14}
13
13
  s.description = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
14
14
  s.email = %q{desimic@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "README.rdoc"
16
+ "README.md"
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
- "CHANGELOG.rdoc",
20
+ "CHANGELOG.md",
21
21
  "MIT-LICENCE",
22
- "README.rdoc",
22
+ "README.md",
23
23
  "Rakefile",
24
24
  "VERSION.yml",
25
25
  "auto_html.gemspec",
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  "lib/auto_html/filters/simple_format.rb",
38
38
  "lib/auto_html/filters/vimeo.rb",
39
39
  "lib/auto_html/filters/youtube.rb",
40
+ "lib/auto_html/filters/youtube_js_api.rb",
40
41
  "rails/init.rb",
41
42
  "test/fixture_setup.rb",
42
43
  "test/fixtures/database.yml",
@@ -53,13 +54,14 @@ Gem::Specification.new do |s|
53
54
  "test/unit/filters/sanitize_test.rb",
54
55
  "test/unit/filters/simple_format_test.rb",
55
56
  "test/unit/filters/vimeo_test.rb",
57
+ "test/unit/filters/youtube_js_api_test.rb",
56
58
  "test/unit/filters/youtube_test.rb",
57
59
  "test/unit/unit_test_helper.rb"
58
60
  ]
59
61
  s.homepage = %q{http://github.com/dejan/auto_html}
60
62
  s.rdoc_options = ["--charset=UTF-8"]
61
63
  s.require_paths = ["lib"]
62
- s.rubygems_version = %q{1.3.5}
64
+ s.rubygems_version = %q{1.3.7}
63
65
  s.summary = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
64
66
  s.test_files = [
65
67
  "test/fixture_setup.rb",
@@ -76,6 +78,7 @@ Gem::Specification.new do |s|
76
78
  "test/unit/filters/sanitize_test.rb",
77
79
  "test/unit/filters/simple_format_test.rb",
78
80
  "test/unit/filters/vimeo_test.rb",
81
+ "test/unit/filters/youtube_js_api_test.rb",
79
82
  "test/unit/filters/youtube_test.rb",
80
83
  "test/unit/unit_test_helper.rb"
81
84
  ]
@@ -84,9 +87,10 @@ Gem::Specification.new do |s|
84
87
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
85
88
  s.specification_version = 3
86
89
 
87
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
90
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
88
91
  else
89
92
  end
90
93
  else
91
94
  end
92
95
  end
96
+
@@ -3,7 +3,6 @@
3
3
  end
4
4
 
5
5
  # Register built-in filters
6
- #
7
6
  Dir["#{File.dirname(__FILE__) + '/auto_html/filters'}/**/*"].each do |filter|
8
7
  require "#{filter}"
9
8
  end
@@ -22,11 +22,16 @@ module AutoHtmlFor
22
22
  end
23
23
  end
24
24
 
25
+ suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
26
+
25
27
  [raw_attrs].flatten.each do |raw_attr|
28
+ define_method("#{raw_attr}#{suffix}=") do |val|
29
+ write_attribute("#{raw_attr}#{suffix}", val)
30
+ end
31
+ define_method("#{raw_attr}#{suffix}") do
32
+ read_attribute("#{raw_attr}#{suffix}") || send("auto_html_prepare_#{raw_attr}")
33
+ end
26
34
  define_method("auto_html_prepare_#{raw_attr}") do
27
- suffix =
28
- AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] ||
29
- AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
30
35
  self.send(raw_attr.to_s + suffix + "=",
31
36
  auto_html(self.send(raw_attr), &proc))
32
37
  end
@@ -4,8 +4,8 @@ module AutoHtml
4
4
  end
5
5
 
6
6
  def auto_html(raw, &proc)
7
+ return "" if raw.blank?
7
8
  builder = Builder.new(raw)
8
9
  builder.instance_eval(&proc)
9
10
  end
10
11
  end
11
-
@@ -1,6 +1,5 @@
1
1
  module AutoHtml
2
2
  class Builder
3
-
4
3
  @@filters = {}
5
4
 
6
5
  def initialize(text)
@@ -1,5 +1,4 @@
1
1
  module AutoHtml
2
-
3
2
  class Filter
4
3
  def initialize(block)
5
4
  @block = block
@@ -20,5 +19,4 @@ module AutoHtml
20
19
  end
21
20
  end
22
21
  end
23
-
24
22
  end
@@ -1,8 +1,5 @@
1
+ require 'action_view'
2
+
1
3
  AutoHtml.add_filter(:simple_format) do |text|
2
- start_tag = '<p>'
3
- text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
4
- text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
5
- text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
6
- text.insert 0, start_tag
7
- text << "</p>"
4
+ ActionView::Base.new.simple_format(text)
8
5
  end
@@ -1,10 +1,8 @@
1
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
2
  text.gsub(/http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
3
3
  vimeo_id = $2
4
-
5
4
  width = options[:width]
6
5
  height = options[:height]
7
-
8
6
  allowfullscreen = options[:fullscreen]
9
7
  fullscreen = options[:fullscreen] ? 1 : 0
10
8
  show_title = options[:show_title] ? 1 : 0
@@ -1,6 +1,12 @@
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
1
+ AutoHtml.add_filter(:youtube).with(:width => 390, :height => 250, :frameborder => 0) do |text, options|
2
+ regex = /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
3
+ text.gsub(regex) do
3
4
  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
+ width = options[:width]
6
+ height = options[:height]
7
+ frameborder = options[:frameborder]
8
+ %{<iframe class="youtube-player" type="text/html" width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{youtube_id}" frameborder="#{frameborder}">
9
+ </iframe>}
5
10
  end
6
- end
11
+ end
12
+
@@ -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
@@ -3,7 +3,6 @@ ActiveRecord::Schema.define do
3
3
  t.column "title", :string
4
4
  t.column "body", :text
5
5
  t.column "body_html", :text
6
- t.column "body_htmlized", :text
7
6
  t.column "created_at", :datetime
8
7
  t.column "updated_at", :datetime
9
8
  end
@@ -16,6 +16,7 @@ class AutoHtmlForTest < Test::Unit::TestCase
16
16
 
17
17
  def test_transform_after_save
18
18
  @article = Article.new(:body => 'Yo!')
19
+ assert_equal '<p>Yo!</p>', @article.body_htmlized
19
20
  @article.save!
20
21
  assert_equal '<p>Yo!</p>', @article.body_htmlized
21
22
  end
@@ -14,6 +14,11 @@ end
14
14
  class AutoHtmlForTest < Test::Unit::TestCase
15
15
  include FixtureSetup
16
16
 
17
+ def test_transform_on_initialization
18
+ @article = Article.new(:body => 'Yo!')
19
+ assert_equal '<p>Yo!</p>', @article.body_html
20
+ end
21
+
17
22
  def test_transform_after_save
18
23
  @article = Article.new(:body => 'Yo!')
19
24
  @article.save!
@@ -1,4 +1,11 @@
1
1
  require 'rubygems'
2
+
3
+ rails_version = ENV['RAILS_VERSION']
4
+ if rails_version
5
+ gem "activerecord", rails_version
6
+ gem "actionpack", rails_version
7
+ end
8
+
2
9
  require 'test/unit'
3
10
  require 'active_record'
4
11
 
@@ -21,5 +21,15 @@ class AutoHtmlTest < Test::Unit::TestCase
21
21
  result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image; link }
22
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
23
  end
24
+
25
+ def test_should_return_blank_if_input_is_blank
26
+ result = auto_html("") { simple_format; image; link }
27
+ assert_equal "", result
28
+ end
29
+
30
+ def test_should_not_apply_simple_format_if_input_is_nil
31
+ result = auto_html(nil) { simple_format; image; link }
32
+ assert_equal "", result
33
+ end
24
34
 
25
35
  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
@@ -4,27 +4,32 @@ class YouTubeTest < Test::Unit::TestCase
4
4
 
5
5
  def test_transform
6
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
7
+ assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
8
+ </iframe>', result
8
9
  end
9
10
 
10
11
  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
12
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube }
13
+ assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
14
+ </iframe>', result
13
15
  end
14
16
 
15
17
  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
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&feature=related') { youtube }
19
+ assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
20
+ </iframe>', result
18
21
  end
19
22
 
20
23
  def test_transform_url_without_www
21
24
  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
25
+ assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
26
+ </iframe>', result
23
27
  end
24
28
 
25
29
  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
30
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube(:width => 300, :height => 255, :frameborder => 1) }
31
+ assert_equal '<iframe class="youtube-player" type="text/html" width="300" height="255" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="1">
32
+ </iframe>', result
28
33
  end
29
34
 
30
- end
35
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Dejan Simic
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-28 00:00:00 +01:00
18
+ date: 2010-08-14 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -20,12 +26,12 @@ executables: []
20
26
  extensions: []
21
27
 
22
28
  extra_rdoc_files:
23
- - README.rdoc
29
+ - README.md
24
30
  files:
25
31
  - .gitignore
26
- - CHANGELOG.rdoc
32
+ - CHANGELOG.md
27
33
  - MIT-LICENCE
28
- - README.rdoc
34
+ - README.md
29
35
  - Rakefile
30
36
  - VERSION.yml
31
37
  - auto_html.gemspec
@@ -43,6 +49,7 @@ files:
43
49
  - lib/auto_html/filters/simple_format.rb
44
50
  - lib/auto_html/filters/vimeo.rb
45
51
  - lib/auto_html/filters/youtube.rb
52
+ - lib/auto_html/filters/youtube_js_api.rb
46
53
  - rails/init.rb
47
54
  - test/fixture_setup.rb
48
55
  - test/fixtures/database.yml
@@ -59,6 +66,7 @@ files:
59
66
  - test/unit/filters/sanitize_test.rb
60
67
  - test/unit/filters/simple_format_test.rb
61
68
  - test/unit/filters/vimeo_test.rb
69
+ - test/unit/filters/youtube_js_api_test.rb
62
70
  - test/unit/filters/youtube_test.rb
63
71
  - test/unit/unit_test_helper.rb
64
72
  has_rdoc: true
@@ -71,21 +79,27 @@ rdoc_options:
71
79
  require_paths:
72
80
  - lib
73
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
74
83
  requirements:
75
84
  - - ">="
76
85
  - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
77
89
  version: "0"
78
- version:
79
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
80
92
  requirements:
81
93
  - - ">="
82
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
83
98
  version: "0"
84
- version:
85
99
  requirements: []
86
100
 
87
101
  rubyforge_project:
88
- rubygems_version: 1.3.5
102
+ rubygems_version: 1.3.7
89
103
  signing_key:
90
104
  specification_version: 3
91
105
  summary: Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
@@ -104,5 +118,6 @@ test_files:
104
118
  - test/unit/filters/sanitize_test.rb
105
119
  - test/unit/filters/simple_format_test.rb
106
120
  - test/unit/filters/vimeo_test.rb
121
+ - test/unit/filters/youtube_js_api_test.rb
107
122
  - test/unit/filters/youtube_test.rb
108
123
  - test/unit/unit_test_helper.rb
@@ -1,29 +0,0 @@
1
- == 1.2.1, released 2009-10-28
2
-
3
- * more options for vimeo filter
4
- * switch to gemcutter
5
-
6
- == 1.2.0, released 2009-09-26
7
-
8
- * link filter now uses Rails' link discovery engine. Closes: http://github.com/dejan/auto_html/issues#issue/2 and http://github.com/dejan/auto_html/issues#issue/3 if Rails 2.3+ is in use.
9
- * added dailymotion filter
10
- * added sanitize filter
11
-
12
- == 1.1.2, released 2009-09-24
13
-
14
- * link filter fix. Closes: http://github.com/dejan/auto_html/issues#issue/2
15
-
16
- == 1.1.1, released 2009-09-06
17
-
18
- * test_helper fix
19
-
20
- == 1.1.0, released 2009-09-05
21
-
22
- * Plugin gemified
23
- * AutoHtmlFor.options[:htmlized_attribute_suffix] is now AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]. Closes gh-1
24
- * Removed deezer filter since deezer.com no longer provides sharing of this kind
25
-
26
- == 1.0.0
27
-
28
- * Stuff described here: http://www.elctech.com/projects/auto_html-plugin
29
-
@@ -1,92 +0,0 @@
1
- = auto_html
2
-
3
- Rails plugin for transforming urls to appropriate resource (image, link, YouTube, Vimeo video,...). Check out the {live demo}[http://auto_html.rors.org].
4
-
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
- For filter list and options they support check: http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters
57
-
58
-
59
- == Install
60
-
61
- === Important note on versions
62
-
63
- As from version 1.2.0 auto_html uses Rails' engine for discovering links. There are some bugs with that engine in versions under Rails 2.3.2. so it's recommended you use auto_html 1.1.2 in that case, since internal engine is used in that version.
64
-
65
- Rails:: auto_html
66
- <= 2.3.1:: 1.1.2
67
- >= 2.3.2:: 1.2.1
68
-
69
-
70
- === As a gem
71
-
72
- To enable the library in your Rails 2.1 (or greater) project, use the gem configuration method in "config/environment.rb"
73
-
74
- Rails::Initializer.run do |config|
75
- config.gem 'dejan-auto_html', :version => '~> 1.2.1', :lib => 'auto_html', :source => 'http://gemcutter.org'
76
- end
77
-
78
- === As a Rails plugin
79
-
80
- script/plugin install git://github.com/dejan/auto_html.git
81
-
82
-
83
- == Links:
84
-
85
- * http://auto_html.rors.org
86
- * http://www.elctech.com/projects/auto_html-plugin
87
-
88
-
89
- == Credits
90
-
91
- Author:: {Dejan Simic}[http://github.com/dejan]
92
- Contributor:: {Claudio Perez Gamayo}[http://github.com/crossblaim]