auto_html 1.5.1.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- auto_html
1
+ auto_html [![Build Status](https://secure.travis-ci.org/dejan/auto_html.png)](http://travis-ci.org/dejan/auto_html)
2
2
  =========
3
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
4
 
5
+ 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).
6
6
 
7
7
  ## Example usage
8
8
 
@@ -25,12 +25,12 @@ You'll probably have user input stored in model, so it's a good place to automat
25
25
  end
26
26
  end
27
27
 
28
- ... and you'll have this behaviour:
28
+ ... and you'll have this behavior:
29
29
 
30
30
  Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
31
31
  => #<Comment id: 123, body: '<p>Hey check out this cool video: <iframe class="youtube-player" type="text/html" width="587" height="350" src="http://www.youtube.com/embed/WdsGihou8J4" frameborder="0"> <br /></iframe></p>'>
32
32
 
33
- 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.
33
+ Note that order of invoking filters is important, i.e. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
34
34
 
35
35
 
36
36
  Now all you have to do is to display it in template without escaping, since plugin took care of that:
data/Rakefile CHANGED
@@ -8,24 +8,9 @@ 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_wit_all_rails_versions do
13
- versions = ['2.1.2',
14
- '2.2.3',
15
- # '2.3.14',
16
- '3.0.11',
17
- '3.1.3',
18
- '3.2.1']
19
- versions.each do |v|
20
- puts "\n###### TESTING WITH RAILS #{v}"
21
- ENV['RAILS_VERSION'] = v
22
- Rake::Task['test'].execute
23
- end
24
- end
25
-
26
11
  desc 'Test with versions of Rails available on the system'
27
12
  task :test_with_installed do
28
- versions = `gem list rails | grep rails`.gsub("rails (", "").chop.split(', ')
13
+ versions = `gem list rails | grep rails`.gsub("rails (", "").chop.chop.split(', ')
29
14
  exclude = []
30
15
  (versions-exclude).each do |v|
31
16
  puts "\n###### TESTING WITH RAILS #{v}"
@@ -13,34 +13,23 @@ module AutoHtmlFor
13
13
  module ClassMethods
14
14
  def auto_html_for(raw_attrs, &proc)
15
15
  include AutoHtmlFor::InstanceMethods
16
- before_save :auto_html_prepare
17
-
18
- define_method("auto_html_prepare") do
19
- auto_html_methods = self.methods.select { |m| m=~/^auto_html_prepare_/ }
20
- auto_html_methods.each do |method|
21
- self.send(method)
22
- end
23
- end
24
16
 
25
17
  suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
26
-
18
+ ([raw_attrs].flatten.map { |a| "#{a}#{suffix}" } - self.column_names).each do |missing_cache_column|
19
+ attr_accessor missing_cache_column
20
+ end
27
21
  [raw_attrs].flatten.each do |raw_attr|
28
- define_method("#{raw_attr}#{suffix}=") do |val|
29
- a = "#{raw_attr}#{suffix}"
30
- write_attribute(a, val) if attributes.has_key?(a)
31
- end
32
- define_method("#{raw_attr}#{suffix}") do
33
- result = read_attribute("#{raw_attr}#{suffix}") || send("auto_html_prepare_#{raw_attr}")
34
- result.respond_to?(:html_safe) ?
35
- result.html_safe :
36
- result
37
- end
38
- define_method("auto_html_prepare_#{raw_attr}") do
39
- result = auto_html(self.send(raw_attr), &proc)
40
- self.send(raw_attr.to_s + suffix + "=", result)
41
- result
22
+ define_method("#{raw_attr}=") do |val|
23
+ self[raw_attr] = val
24
+ result = auto_html(val, &proc)
25
+ if result.respond_to?(:html_safe)
26
+ result = result.html_safe
27
+ end
28
+ self.send("#{raw_attr}#{suffix}=", result)
29
+ val
42
30
  end
43
31
  end
32
+
44
33
  end
45
34
  end
46
35
 
@@ -48,3 +37,5 @@ module AutoHtmlFor
48
37
  include AutoHtml
49
38
  end
50
39
  end
40
+
41
+
@@ -9,7 +9,7 @@ end
9
9
  AutoHtml.add_filter(:image).with({:alt => ''}) do |text, options|
10
10
  r = Redcarpet::Markdown.new(NoParagraphRenderer)
11
11
  alt = options[:alt]
12
- text.gsub(/https?:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
12
+ text.gsub(/https?:\/\/.+?\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
13
13
  r.render("![#{alt}](#{match})")
14
14
  end
15
15
  end
@@ -1,6 +1,7 @@
1
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(/http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
3
- vimeo_id = $2
2
+ text.gsub(/(https?):\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
3
+ protocol = $1
4
+ vimeo_id = $3
4
5
  width = options[:width]
5
6
  height = options[:height]
6
7
  show_title = "title=0" unless options[:show_title]
@@ -10,6 +11,6 @@ AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => f
10
11
  query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
11
12
  query_string = "?" + query_string_variables unless query_string_variables.empty?
12
13
 
13
- %{<iframe src="http://player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>}
14
+ %{<iframe src="#{protocol}://player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>}
14
15
  end
15
16
  end
@@ -1,5 +1,5 @@
1
1
  AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil) do |text, options|
2
- regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]*)(\&\S+)?(\S)*/
2
+ regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\S)*/
3
3
  text.gsub(regex) do
4
4
  protocol = $1
5
5
  youtube_id = $4
@@ -1,8 +1,12 @@
1
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
+
2
8
  def setup
3
9
  fixtures_dir = File.dirname(__FILE__) + '/fixtures'
4
- connections = YAML.load_file("#{fixtures_dir}/database.yml")
5
- ActiveRecord::Base.establish_connection(connections['sqlite3'])
6
10
  ActiveRecord::Migration.verbose = false
7
11
  load "#{fixtures_dir}/schema.rb"
8
12
  end
@@ -1,4 +1,4 @@
1
- ActiveRecord::Schema.define do
1
+ ActiveRecord::Schema.define(:version => Time.now.to_i) do
2
2
  create_table "articles", :force => true do |t|
3
3
  t.column "title", :string
4
4
  t.column "body", :text
@@ -11,4 +11,10 @@ ActiveRecord::Schema.define do
11
11
  t.column "name", :string
12
12
  t.column "bio", :text
13
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
14
20
  end
@@ -5,8 +5,8 @@ require File.expand_path('../../fixture_setup', __FILE__)
5
5
  default_suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
6
6
  AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = '_htmlized'
7
7
 
8
- class Article < ActiveRecord::Base
9
- auto_html_for :body do
8
+ class Post < ActiveRecord::Base
9
+ auto_html_for :content do
10
10
  simple_format
11
11
  end
12
12
  end
@@ -15,10 +15,10 @@ class AutoHtmlForOptionsTest < Test::Unit::TestCase
15
15
  include FixtureSetup
16
16
 
17
17
  def test_transform_after_save
18
- @article = Article.new(:body => 'Yo!')
19
- assert_equal '<p>Yo!</p>', @article.body_htmlized
18
+ @article = Post.new(:content => 'Yo!')
19
+ assert_equal '<p>Yo!</p>', @article.content_htmlized
20
20
  @article.save!
21
- assert_equal '<p>Yo!</p>', @article.body_htmlized
21
+ assert_equal '<p>Yo!</p>', @article.content_htmlized
22
22
  end
23
23
  end
24
24
 
@@ -42,6 +42,11 @@ class ImageTest < Test::Unit::TestCase
42
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
43
  end
44
44
 
45
+ def test_transform8
46
+ result = auto_html('Which do you prefer, this one http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG, or this one http://rors.org/images/rails.png?') { image({:alt => nil}) }
47
+ assert_equal 'Which do you prefer, this one <img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>, or this one <img src="http://rors.org/images/rails.png" alt=""/>?', result
48
+ end
49
+
45
50
  def test_https
46
51
  result = auto_html('https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image({:alt => nil}) }
47
52
  assert_equal '<img src="https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" alt=""/>', result
@@ -41,5 +41,10 @@ class VimeoTest < Test::Unit::TestCase
41
41
  result = auto_html("http://www.vimeo.com/3300155") { vimeo(:width => 300, :height => 250, :show_portrait => true) }
42
42
  assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&byline=0" width="300" height="250" frameborder="0"></iframe>', result
43
43
  end
44
+
45
+ def test_transform_url_with_https
46
+ result = auto_html('https://vimeo.com/3300155') { vimeo }
47
+ assert_equal '<iframe src="https://player.vimeo.com/video/3300155?title=0&byline=0&portrait=0" width="440" height="248" frameborder="0"></iframe>', result
48
+ end
44
49
 
45
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1.1
4
+ version: 1.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-16 00:00:00.000000000 Z
12
+ date: 2012-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rinku
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 1.8.23
121
+ rubygems_version: 1.8.24
122
122
  signing_key:
123
123
  specification_version: 3
124
124
  summary: Transform URIs to appropriate markup