auto_html 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +6 -1
- data/README.md +19 -7
- data/Rakefile +1 -1
- data/TODO +12 -0
- data/VERSION.yml +1 -1
- data/auto_html.gemspec +5 -4
- data/{rails/init.rb → init.rb} +0 -0
- data/lib/auto_html/filters/link.rb +1 -1
- data/lib/auto_html/filters/simple_format.rb +9 -2
- data/lib/auto_html/filters/vimeo.rb +10 -8
- data/test/test_helper.rb +1 -1
- data/test/unit/filters/link_test.rb +6 -4
- data/test/unit/filters/vimeo_test.rb +18 -23
- metadata +7 -5
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
##
|
1
|
+
## 1.3.1, released 2010-08-22
|
2
|
+
* Rails 3 initialization fix
|
3
|
+
* fixes to conform Rails 3.0.0.rc, sanitization by default in text_helpers (auto_link, simple_format)
|
4
|
+
* added vimeo html5 universal embed player
|
5
|
+
|
6
|
+
## 1.3.0, released 2010-08-14
|
2
7
|
* no need for explicit call to auto_html_prepare
|
3
8
|
* no need for DB column for cache (ie. _html)
|
4
9
|
* Rails 3 support
|
data/README.md
CHANGED
@@ -6,7 +6,14 @@ auto_html is a Rails extension for transforming URLs to appropriate resource (im
|
|
6
6
|
|
7
7
|
## Example usage
|
8
8
|
|
9
|
-
|
9
|
+
Transforming string with text and URLs is done with *auto_html* method:
|
10
|
+
|
11
|
+
inlcude AutoHtml
|
12
|
+
|
13
|
+
auto_html('Hey! Checkout out: http://vukajlija.com') { simple_format; link(:target => 'blank') }
|
14
|
+
=> "<p>Hey! Checkout out: <a href='http://vukajlija.com' target='blank'>http://vukajlija.com</a></p>"
|
15
|
+
|
16
|
+
You'll probably have user input stored in model, so it's a good place to automate and even store this conversion for performance reason. This is done with *auto_html_for* method. Let's say you have model Comment with attribute body. Create another column in table Comments called body_html (again, this is optional but recommended for performance reasons). Now have something like this:
|
10
17
|
|
11
18
|
class Comment < ActiveRecord::Base
|
12
19
|
auto_html_for :body do
|
@@ -21,7 +28,7 @@ Let's say you have model Comment with attribute body. Create another column in t
|
|
21
28
|
... and you'll have this behaviour:
|
22
29
|
|
23
30
|
Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
|
24
|
-
=> #<Comment id: 123, body: '
|
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>'>
|
25
32
|
|
26
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.
|
27
34
|
|
@@ -49,6 +56,7 @@ Plugin is highly customizable, and you can easily create new filters that will t
|
|
49
56
|
end
|
50
57
|
|
51
58
|
|
59
|
+
|
52
60
|
## Bundled filters
|
53
61
|
|
54
62
|
For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
|
@@ -60,19 +68,23 @@ For filter list and options they support check: <http://github.com/dejan/auto_ht
|
|
60
68
|
|
61
69
|
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
70
|
|
63
|
-
|
64
|
-
|
71
|
+
for Rails <= 2.3.1 use auto_html 1.1.2<br/>
|
72
|
+
for Rails >= 2.3.2 use the latest auto_html
|
65
73
|
|
66
|
-
auto_html has been tested to work with Rails 3 and Ruby 1.9.
|
74
|
+
As from version 1.3.0, auto_html has been tested to work with Rails 3 and Ruby 1.9.
|
67
75
|
|
68
76
|
### As a gem
|
69
77
|
|
70
|
-
To enable the library in your Rails 2.1
|
78
|
+
To enable the library in your Rails 2.1-2.3 project, use the gem configuration method in "config/environment.rb"
|
71
79
|
|
72
80
|
Rails::Initializer.run do |config|
|
73
|
-
config.gem 'auto_html'
|
81
|
+
config.gem 'auto_html'
|
74
82
|
end
|
75
83
|
|
84
|
+
In Rails 3.0 specify the gem in your Gemfile
|
85
|
+
|
86
|
+
gem "auto_html"
|
87
|
+
|
76
88
|
### As a Rails plugin
|
77
89
|
|
78
90
|
script/plugin install git://github.com/dejan/auto_html.git
|
data/Rakefile
CHANGED
data/TODO
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
v 1.3
|
2
|
+
* add bunch of new filters: twitter (check campfire's markup/styling), twitpic, http://twaud.io/, see more: http://www.oembed.com/, http://api.embed.ly/
|
3
|
+
|
4
|
+
|
5
|
+
v 2
|
6
|
+
* refactoring (class/var names, code style, etc.)
|
7
|
+
* inline testing
|
8
|
+
* more tests
|
9
|
+
* test coverage
|
10
|
+
* performance testing
|
11
|
+
* oembed object as result?
|
12
|
+
* fancy filters: click to play youtube, lightbox, ...
|
data/VERSION.yml
CHANGED
data/auto_html.gemspec
CHANGED
@@ -5,15 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{auto_html}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.1"
|
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{2010-08-
|
12
|
+
s.date = %q{2010-08-22}
|
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.md"
|
16
|
+
"README.md",
|
17
|
+
"TODO"
|
17
18
|
]
|
18
19
|
s.files = [
|
19
20
|
".gitignore",
|
@@ -23,6 +24,7 @@ Gem::Specification.new do |s|
|
|
23
24
|
"Rakefile",
|
24
25
|
"VERSION.yml",
|
25
26
|
"auto_html.gemspec",
|
27
|
+
"init.rb",
|
26
28
|
"lib/auto_html.rb",
|
27
29
|
"lib/auto_html/auto_html_for.rb",
|
28
30
|
"lib/auto_html/base.rb",
|
@@ -38,7 +40,6 @@ Gem::Specification.new do |s|
|
|
38
40
|
"lib/auto_html/filters/vimeo.rb",
|
39
41
|
"lib/auto_html/filters/youtube.rb",
|
40
42
|
"lib/auto_html/filters/youtube_js_api.rb",
|
41
|
-
"rails/init.rb",
|
42
43
|
"test/fixture_setup.rb",
|
43
44
|
"test/fixtures/database.yml",
|
44
45
|
"test/fixtures/schema.rb",
|
data/{rails/init.rb → init.rb}
RENAMED
File without changes
|
@@ -1,5 +1,12 @@
|
|
1
1
|
require 'action_view'
|
2
2
|
|
3
|
-
AutoHtml.add_filter(:simple_format) do |text|
|
4
|
-
|
3
|
+
AutoHtml.add_filter(:simple_format).with({}) do |text, html_options|
|
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
|
5
12
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :
|
1
|
+
AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :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
4
|
width = options[:width]
|
5
5
|
height = options[:height]
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
+
%{<iframe src="http://player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>}
|
12
14
|
end
|
13
|
-
end
|
15
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -28,8 +28,9 @@ class LinkTest < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_transform_with_params
|
31
|
-
|
32
|
-
|
31
|
+
url = 'http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related'
|
32
|
+
# uses auto_link instead raw to support both Rails 2 & 3
|
33
|
+
assert_equal(ActionView::Base.new.auto_link(url), auto_html(url) { link })
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_transform_with_commas
|
@@ -38,8 +39,9 @@ class LinkTest < Test::Unit::TestCase
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def test_transform_complex_url
|
41
|
-
|
42
|
-
|
42
|
+
url = 'http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0'
|
43
|
+
# uses auto_link instead raw to support both Rails 2 & 3
|
44
|
+
assert_equal(ActionView::Base.new.auto_link(url), auto_html(url) { link })
|
43
45
|
end
|
44
46
|
|
45
47
|
def test_transform_with_options
|
@@ -4,47 +4,42 @@ class VimeoTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def test_transform_url_with_www
|
6
6
|
result = auto_html('http://www.vimeo.com/3300155') { vimeo }
|
7
|
-
assert_equal '<
|
7
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&byline=0&portrait=0" width="440" height="248" frameborder="0"></iframe>', result
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_transform_url_without_www
|
11
11
|
result = auto_html('http://vimeo.com/3300155') { vimeo }
|
12
|
-
assert_equal '<
|
12
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&byline=0&portrait=0" width="440" height="248" frameborder="0"></iframe>', result
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_transform_url_with_params
|
16
|
-
result = auto_html('http://vimeo.com/
|
17
|
-
assert_equal '<
|
16
|
+
result = auto_html('http://vimeo.com/3300155?pg=embed&sec=') { vimeo }
|
17
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&byline=0&portrait=0" width="440" height="248" frameborder="0"></iframe>', result
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_transform_url_with_anchor
|
21
|
-
result = auto_html('http://vimeo.com/
|
22
|
-
assert_equal '<
|
21
|
+
result = auto_html('http://vimeo.com/3300155#skirt') { vimeo }
|
22
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&byline=0&portrait=0" width="440" height="248" frameborder="0"></iframe>', result
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_transform_with_options
|
26
|
-
result = auto_html("http://www.vimeo.com/
|
27
|
-
assert_equal '<
|
26
|
+
result = auto_html("http://www.vimeo.com/3300155") { vimeo(:width => 300, :height => 250) }
|
27
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&byline=0&portrait=0" width="300" height="250" frameborder="0"></iframe>', result
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
result = auto_html("http://www.vimeo.com/
|
32
|
-
assert_equal '<
|
30
|
+
def test_transform_with_title
|
31
|
+
result = auto_html("http://www.vimeo.com/3300155") { vimeo(:width => 300, :height => 250, :show_title => true) }
|
32
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?byline=0&portrait=0" width="300" height="250" frameborder="0"></iframe>', result
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
result = auto_html("http://www.vimeo.com/
|
37
|
-
assert_equal '<
|
35
|
+
def test_transform_with_byline
|
36
|
+
result = auto_html("http://www.vimeo.com/3300155") { vimeo(:width => 300, :height => 250, :show_byline => true) }
|
37
|
+
assert_equal '<iframe src="http://player.vimeo.com/video/3300155?title=0&portrait=0" width="300" height="250" frameborder="0"></iframe>', result
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
result = auto_html("http://www.vimeo.com/
|
42
|
-
assert_equal '<
|
40
|
+
def test_transform_with_portrait
|
41
|
+
result = auto_html("http://www.vimeo.com/3300155") { vimeo(:width => 300, :height => 250, :show_portrait => true) }
|
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
44
|
|
45
|
-
|
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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="250"></embed></object>', result
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dejan Simic
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-22 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -27,6 +27,7 @@ extensions: []
|
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- README.md
|
30
|
+
- TODO
|
30
31
|
files:
|
31
32
|
- .gitignore
|
32
33
|
- CHANGELOG.md
|
@@ -35,6 +36,7 @@ files:
|
|
35
36
|
- Rakefile
|
36
37
|
- VERSION.yml
|
37
38
|
- auto_html.gemspec
|
39
|
+
- init.rb
|
38
40
|
- lib/auto_html.rb
|
39
41
|
- lib/auto_html/auto_html_for.rb
|
40
42
|
- lib/auto_html/base.rb
|
@@ -50,7 +52,6 @@ files:
|
|
50
52
|
- lib/auto_html/filters/vimeo.rb
|
51
53
|
- lib/auto_html/filters/youtube.rb
|
52
54
|
- lib/auto_html/filters/youtube_js_api.rb
|
53
|
-
- rails/init.rb
|
54
55
|
- test/fixture_setup.rb
|
55
56
|
- test/fixtures/database.yml
|
56
57
|
- test/fixtures/schema.rb
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- test/unit/filters/youtube_js_api_test.rb
|
70
71
|
- test/unit/filters/youtube_test.rb
|
71
72
|
- test/unit/unit_test_helper.rb
|
73
|
+
- TODO
|
72
74
|
has_rdoc: true
|
73
75
|
homepage: http://github.com/dejan/auto_html
|
74
76
|
licenses: []
|