auto_html 1.6.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +47 -98
- data/Rakefile +6 -7
- data/lib/auto_html.rb +9 -15
- data/lib/auto_html/emoji.rb +57 -0
- data/lib/auto_html/html_escape.rb +10 -0
- data/lib/auto_html/image.rb +23 -0
- data/lib/auto_html/link.rb +31 -0
- data/lib/auto_html/markdown.rb +15 -0
- data/lib/auto_html/pipeline.rb +15 -0
- data/lib/auto_html/simple_format.rb +22 -0
- data/spec/emoji_spec.rb +9 -0
- data/spec/html_escape_spec.rb +8 -0
- data/spec/image_spec.rb +39 -0
- data/spec/link_spec.rb +39 -0
- data/spec/markdown_spec.rb +7 -0
- data/spec/pipeline_spec.rb +24 -0
- data/spec/simple_format_spec.rb +16 -0
- data/spec/spec_helper.rb +11 -0
- metadata +121 -88
- data/lib/auto_html/auto_html_for.rb +0 -64
- data/lib/auto_html/base.rb +0 -18
- data/lib/auto_html/builder.rb +0 -21
- data/lib/auto_html/capistrano.rb +0 -17
- data/lib/auto_html/filter.rb +0 -22
- data/lib/auto_html/filters/dailymotion.rb +0 -6
- data/lib/auto_html/filters/flickr.rb +0 -20
- data/lib/auto_html/filters/gist.rb +0 -8
- data/lib/auto_html/filters/google_map.rb +0 -19
- data/lib/auto_html/filters/google_video.rb +0 -6
- data/lib/auto_html/filters/hashtag.rb +0 -7
- data/lib/auto_html/filters/html_escape.rb +0 -9
- data/lib/auto_html/filters/image.rb +0 -16
- data/lib/auto_html/filters/instagram.rb +0 -10
- data/lib/auto_html/filters/link.rb +0 -16
- data/lib/auto_html/filters/liveleak.rb +0 -19
- data/lib/auto_html/filters/metacafe.rb +0 -13
- data/lib/auto_html/filters/redcarpet.rb +0 -4
- data/lib/auto_html/filters/sanitize.rb +0 -5
- data/lib/auto_html/filters/simple_format.rb +0 -12
- data/lib/auto_html/filters/soundcloud.rb +0 -21
- data/lib/auto_html/filters/ted.rb +0 -13
- data/lib/auto_html/filters/twitter.rb +0 -19
- data/lib/auto_html/filters/vimeo.rb +0 -15
- data/lib/auto_html/filters/worldstar.rb +0 -8
- data/lib/auto_html/filters/youtube.rb +0 -19
- data/lib/auto_html/filters/youtube_image.rb +0 -17
- data/lib/auto_html/filters/youtube_js_api.rb +0 -6
- data/lib/auto_html/railtie.rb +0 -10
- data/lib/auto_html/rake_tasks.rb +0 -27
- data/lib/auto_html/task.rb +0 -9
- data/test/fixture_setup.rb +0 -13
- data/test/fixtures/database.yml +0 -5
- data/test/fixtures/schema.rb +0 -20
- data/test/functional/auto_html_for_options_test.rb +0 -26
- data/test/functional/auto_html_for_test.rb +0 -56
- data/test/functional/filter_test.rb +0 -27
- data/test/test_helper.rb +0 -9
- data/test/unit/auto_html_test.rb +0 -37
- data/test/unit/filters/dailymotion_test.rb +0 -20
- data/test/unit/filters/gist_test.rb +0 -15
- data/test/unit/filters/google_map_test.rb +0 -24
- data/test/unit/filters/hashtag_test.rb +0 -25
- data/test/unit/filters/html_escape_test.rb +0 -15
- data/test/unit/filters/image_test.rb +0 -65
- data/test/unit/filters/instagram_test.rb +0 -8
- data/test/unit/filters/link_test.rb +0 -55
- data/test/unit/filters/liveleak_test.rb +0 -15
- data/test/unit/filters/metacafe_test.rb +0 -29
- data/test/unit/filters/redcarpet_test.rb +0 -38
- data/test/unit/filters/sanitize_test.rb +0 -36
- data/test/unit/filters/simple_format_test.rb +0 -15
- data/test/unit/filters/soundcloud_test.rb +0 -29
- data/test/unit/filters/ted_test.rb +0 -18
- data/test/unit/filters/twitter_test.rb +0 -45
- data/test/unit/filters/vimeo_test.rb +0 -50
- data/test/unit/filters/worldstar_test.rb +0 -14
- data/test/unit/filters/youtube_image_test.rb +0 -59
- data/test/unit/filters/youtube_js_api_test.rb +0 -30
- data/test/unit/filters/youtube_test.rb +0 -59
- data/test/unit/unit_test_helper.rb +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a15b23417dc35ee0ff8097c15b5eba4847142e2
|
4
|
+
data.tar.gz: b94279092cc3fcb0f60affc58a733894e6f8993c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aef39b00d5a58cf5b32fcdeddd42f5c5c7691dbc506ff38b0f43784339bd55eeceed67f88aefa7badd8fc61c69b922970709f4a2a2661bd49fcb39dbd2d83fb6
|
7
|
+
data.tar.gz: bf49c7aa022c56fbc3b3d58b7e27d83e447dfac562c33e8bcd0a308e7180edc8c2274e326a9a88d0b83559d89af6724a650dd91e475f93091d31472e83887e2d
|
data/README.md
CHANGED
@@ -1,123 +1,72 @@
|
|
1
|
-
|
2
|
-
=========
|
1
|
+
# AutoHtml
|
3
2
|
|
3
|
+
AutoHtml is a collection of filters that transform plain text into HTML code.
|
4
4
|
|
5
|
-
|
5
|
+
## Installation
|
6
6
|
|
7
|
+
Add this line to your application's Gemfile:
|
7
8
|
|
8
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'auto_html'
|
11
|
+
```
|
9
12
|
|
10
|
-
|
13
|
+
And then execute:
|
11
14
|
|
12
|
-
|
15
|
+
```sh
|
16
|
+
$ bundle
|
17
|
+
```
|
13
18
|
|
19
|
+
Or install it yourself as:
|
14
20
|
|
15
|
-
|
21
|
+
```sh
|
22
|
+
$ gem install auto_html
|
23
|
+
```
|
16
24
|
|
17
|
-
|
25
|
+
## Abstract
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
auto_html('Hey! Checkout out: http://vukajlija.com') { simple_format; link(:target => 'blank') }
|
22
|
-
=> "<p>Hey! Checkout out: <a href='http://vukajlija.com' target='blank'>http://vukajlija.com</a></p>"
|
27
|
+
AutoHtml uses concepts found in "Pipes and Filters" processing design pattern:
|
23
28
|
|
24
|
-
|
29
|
+
* `Filter` - transforms an input. In AutoHtml context, this is any object that does the transformation through `#call(String)` method. Filter options should be passed in initializer. AutoHtml provides some filters already, ie Link, Image, Markdown, etc.
|
30
|
+
* `Pipeline` - a composition of filters that transforms input by passing the output of one filter as input for the next filter in line. In AutoHtml context, this is the `AutoHtml::Pipeline` class. Since the same interface (method `#call`) is used to pass input, we can say that Pipeline is just another Filter, which means it can be used as a building block for other Pipelines, in a mix with other filters.
|
25
31
|
|
26
|
-
|
27
|
-
auto_html_for :body do
|
28
|
-
html_escape
|
29
|
-
image
|
30
|
-
youtube(:width => 400, :height => 250, :autoplay => true)
|
31
|
-
link :target => "_blank", :rel => "nofollow"
|
32
|
-
simple_format
|
33
|
-
end
|
34
|
-
end
|
32
|
+
## Examples
|
35
33
|
|
36
|
-
|
34
|
+
```ruby
|
35
|
+
link_filter = AutoHtml::Link.new(target: '_blank')
|
36
|
+
link_filter.call('Checkout out my blog: http://rors.org')
|
37
|
+
# => 'Checkout out my blog: <a target="blank" href="http://rors.org">http://rors.org</a>'
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
emoji_filter = AutoHtml::Emoji.new
|
40
|
+
emoji_filter.call(':point_left: yo!')
|
41
|
+
# => '<img src="/images/emoji/unicode/1f448.png" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo!'
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
<% for comment in @comments %>
|
47
|
-
<li><%= comment.body_html %></li>
|
48
|
-
<% end %>
|
49
|
-
|
50
|
-
|
51
|
-
If you need to display preview, no problem. Have something like this as action in your controller:
|
52
|
-
|
53
|
-
def preview
|
54
|
-
comment = Comment.new(params[:comment])
|
55
|
-
render :text => comment.body_html
|
56
|
-
end
|
57
|
-
|
58
|
-
AutoHtml 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:
|
59
|
-
|
60
|
-
AutoHtml.add_filter(:image) do |text|
|
61
|
-
text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
|
62
|
-
%|<img src="#{match}" alt=""/>|
|
63
|
-
end
|
64
|
-
end
|
43
|
+
# Use Pipeline to combine filters
|
44
|
+
base_format = AutoHtml::Pipeline.new(link_filter, emoji_filter)
|
45
|
+
base_format.call('Checkout out my blog: http://rors.org :point_left: yo!')
|
46
|
+
# => 'Checkout out my blog: <a href="http://rors.org">http://rors.org</a> <img src="/images/emoji/unicode/1f448.png" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo!'
|
65
47
|
|
48
|
+
# A pipeline can be reused in another pipeline. Note that the order of filters is important - ie you want
|
49
|
+
# `Image` before `Link` filter so that URL of the image gets transformed to `img` tag and not `a` tag.
|
50
|
+
comment_format = AutoHtml::Pipeline.new(AutoHtml::Markdown.new, AutoHtml::Image.new, base_format)
|
51
|
+
comment_format.call("Hello!\n\n Checkout out my blog: http://rors.org :point_left: yo! \n\n http://gifs.joelglovier.com/boom/booyah.gif")
|
52
|
+
# => "<p>Hello!</p>\n\n<p>Checkout out my blog: <a href="<img src="http://rors.org" target="_blank">http://rors.org</a> <img src="/images/emoji/unicode/1f448.png" />" class="emoji" title=":point_left:" alt=":point_left:" height="20" witdh="20" align="absmiddle" /> yo! </p>\n\n<p><a href="<img src="http://gifs.joelglovier.com/boom/booyah.gif" />" target="_blank"><img src="http://gifs.joelglovier.com/boom/booyah.gif" /></a></p>\n"
|
53
|
+
```
|
66
54
|
|
67
55
|
## Bundled filters
|
68
56
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
## Non-ActiveRecord models
|
73
|
-
|
74
|
-
AutoHtml uses standard ActiveModel API, which means that you can include AutoHtmlFor module (that automates transformation of the field) in any non-ActiveRecord model that uses ActiveModel. Here's working [mongoid](http://mongoid.org/) example:
|
75
|
-
|
76
|
-
class Post
|
77
|
-
include Mongoid::Document
|
78
|
-
include AutoHtmlFor
|
79
|
-
|
80
|
-
field :body
|
81
|
-
|
82
|
-
auto_html_for :body do
|
83
|
-
simple_format
|
84
|
-
link
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
## Rake and Capistrano tasks
|
90
|
-
|
91
|
-
AutoHtml has a Rake task for rebuilding cached in DB column values
|
92
|
-
Usage: `rake auto_html:rebuild CLASS=[your model]`
|
93
|
-
Where `[your model]` is the name of model which values you want to rebuild.
|
57
|
+
Bellow is the list of bundled filters along with their optional arguments on initialization and their default values.
|
94
58
|
|
95
|
-
|
59
|
+
* `AutoHtml::Emoji`, width: 20, height: 20, asset_root: '/images'
|
60
|
+
* `AutoHtml::HtmlEscape`
|
61
|
+
* `AutoHtml::Image`, proxy: nil, alt: nil
|
62
|
+
* `AutoHtml::Link`, target: nil, rel: nil
|
63
|
+
* `AutoHtml::Markdown`
|
64
|
+
* `AutoHtml::SimpleFormat`
|
96
65
|
|
97
|
-
|
98
|
-
|
99
|
-
Now you can run `cap auto_html:rebuild CLASS=[your_model]`.
|
66
|
+
## Code status
|
100
67
|
|
68
|
+
[![Circle CI](https://circleci.com/gh/dejan/auto_html.svg?style=svg&circle-token=57823c8b62302106564f97b58b64643b9760ed99)](https://circleci.com/gh/dejan/auto_html)
|
101
69
|
|
102
70
|
## Licence
|
103
71
|
|
104
|
-
|
105
|
-
|
106
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
107
|
-
a copy of this software and associated documentation files (the
|
108
|
-
"Software"), to deal in the Software without restriction, including
|
109
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
110
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
111
|
-
permit persons to whom the Software is furnished to do so, subject to
|
112
|
-
the following conditions:
|
113
|
-
|
114
|
-
The above copyright notice and this permission notice shall be
|
115
|
-
included in all copies or substantial portions of the Software.
|
116
|
-
|
117
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
118
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
119
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
120
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
121
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
122
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
123
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
72
|
+
AutoHtml is released under the [MIT License](https://raw.githubusercontent.com/dejan/auto_html/master/MIT-LICENCE).
|
data/Rakefile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new
|
5
7
|
|
6
|
-
|
7
|
-
Rake::TestTask.new(:test) do |t|
|
8
|
-
t.pattern = 'test/**/*_test.rb'
|
9
|
-
end
|
8
|
+
task default: [:rubocop, :spec]
|
data/lib/auto_html.rb
CHANGED
@@ -1,17 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# AutoHtml is a collection of filters that transform plain text into HTML code.
|
2
|
+
module AutoHtml
|
3
|
+
autoload :Pipeline, 'auto_html/pipeline'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
autoload :Emoji, 'auto_html/emoji'
|
6
|
+
autoload :HtmlEscape, 'auto_html/html_escape'
|
7
|
+
autoload :Image, 'auto_html/image'
|
8
|
+
autoload :Link, 'auto_html/link'
|
9
|
+
autoload :Markdown, 'auto_html/markdown'
|
10
|
+
autoload :SimpleFormat, 'auto_html/simple_format'
|
7
11
|
end
|
8
|
-
|
9
|
-
# if rails
|
10
|
-
require 'auto_html/railtie' if defined?(Rails::Railtie)
|
11
|
-
if defined?(ActiveRecord::Base)
|
12
|
-
ActiveRecord::Base.send :include, AutoHtmlFor
|
13
|
-
|
14
|
-
module ActionView::Helpers::TextHelper
|
15
|
-
include AutoHtml
|
16
|
-
end
|
17
|
-
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
require 'gemoji'
|
3
|
+
|
4
|
+
module AutoHtml
|
5
|
+
# Emoji filter
|
6
|
+
class Emoji
|
7
|
+
def initialize(asset_root: '/images', width: 20, height: 20)
|
8
|
+
@asset_root = asset_root
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(text)
|
14
|
+
text.gsub(emoji_pattern) do
|
15
|
+
name = Regexp.last_match(1)
|
16
|
+
alt = ":#{name}:"
|
17
|
+
html_options = {
|
18
|
+
src: emoji_url(name),
|
19
|
+
class: 'emoji',
|
20
|
+
title: alt,
|
21
|
+
alt: alt,
|
22
|
+
height: @width,
|
23
|
+
witdh: @height,
|
24
|
+
align: 'absmiddle'
|
25
|
+
}
|
26
|
+
TagHelper.tag(:img, html_options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def emoji_url(name)
|
33
|
+
File.join(@asset_root, asset_path(name))
|
34
|
+
end
|
35
|
+
|
36
|
+
def asset_path(name)
|
37
|
+
File.join('emoji', emoji_filename(name))
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.emoji_pattern
|
41
|
+
@emoji_pattern ||=
|
42
|
+
/:(#{emoji_names.map { |name| Regexp.escape(name) }.join('|')}):/
|
43
|
+
end
|
44
|
+
|
45
|
+
def emoji_pattern
|
46
|
+
self.class.emoji_pattern
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.emoji_names
|
50
|
+
::Emoji.all.map(&:aliases).flatten.sort
|
51
|
+
end
|
52
|
+
|
53
|
+
def emoji_filename(name)
|
54
|
+
::Emoji.find_by_alias(name).image_filename
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# Image filter
|
5
|
+
class Image
|
6
|
+
def initialize(proxy: nil, alt: nil)
|
7
|
+
@proxy = proxy || ''
|
8
|
+
@alt = alt
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(text)
|
12
|
+
text.gsub(image_pattern) do |match|
|
13
|
+
TagHelper.tag(:img, src: @proxy + match, alt: @alt)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def image_pattern
|
20
|
+
%r{(?<!src=")https?:\/\/.+?\.(jpg|jpeg|bmp|gif|png)(\?\S+)?}i
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'rinku'
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
module AutoHtml
|
6
|
+
# Link filter
|
7
|
+
class Link
|
8
|
+
def initialize(target: nil, rel: nil)
|
9
|
+
@target = target
|
10
|
+
@rel = rel
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(text)
|
14
|
+
Rinku.auto_link(text, :all, target_attr)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def attributes
|
20
|
+
[target_attr, rel_attr].compact.join(' ')
|
21
|
+
end
|
22
|
+
|
23
|
+
def rel_attr
|
24
|
+
%(rel="#{@rel}") if @rel
|
25
|
+
end
|
26
|
+
|
27
|
+
def target_attr
|
28
|
+
%(target="#{@target}") if @target
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AutoHtml
|
2
|
+
# Applies collection of filters to a text
|
3
|
+
class Pipeline
|
4
|
+
def initialize(*filters)
|
5
|
+
@filters = filters.flatten
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(text)
|
9
|
+
return '' if text.nil? || text.empty?
|
10
|
+
@filters.inject(text) do |content, filter|
|
11
|
+
filter.call(content)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'tag_helper'
|
2
|
+
|
3
|
+
module AutoHtml
|
4
|
+
# SimpleFormat filter
|
5
|
+
class SimpleFormat
|
6
|
+
def call(text)
|
7
|
+
paragraphs = split_paragraphs(text)
|
8
|
+
paragraphs.map! do |paragraph|
|
9
|
+
TagHelper.tag(:p) { paragraph }
|
10
|
+
end.join("\n\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def split_paragraphs(text)
|
16
|
+
return [] if text.nil? || text.empty?
|
17
|
+
text.to_s.gsub(/\r\n?/, "\n").split(/\n\n+/).map! do |t|
|
18
|
+
t.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') || t
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/emoji_spec.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe AutoHtml::Emoji do
|
4
|
+
it 'converts emoji to HTML' do
|
5
|
+
expect(subject.call(':joy:')).to eq(
|
6
|
+
'<img src="/images/emoji/unicode/1f602.png" class="emoji" title=":joy:" '\
|
7
|
+
'alt=":joy:" height="20" witdh="20" align="absmiddle" />')
|
8
|
+
end
|
9
|
+
end
|
data/spec/image_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe AutoHtml::Image do
|
4
|
+
it 'transforms an image link to image tag' do
|
5
|
+
result = subject.call('http://rors.org/images/rails.png')
|
6
|
+
expect(result).to eq('<img src="http://rors.org/images/rails.png" />')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'transforms image link with a param to image tag' do
|
10
|
+
result = subject.call('http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0')
|
11
|
+
expect(result).to eq('<img src="http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0" />')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'transforms image link on https to image tag' do
|
15
|
+
result = subject.call('https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png')
|
16
|
+
expect(result).to eq('<img src="https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" />')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'transforms image link to a image tag with proxy as source' do
|
20
|
+
filter = AutoHtml::Image.new(proxy: 'https://proxy/?url=')
|
21
|
+
result = filter.call('http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png')
|
22
|
+
expect(result).to eq('<img src="https://proxy/?url=http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" />')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'does not transforms already transformed image' do
|
26
|
+
result = subject.call('<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" />')
|
27
|
+
expect(result).to eq('<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" />')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'transforms an image link within text to image tag' do
|
31
|
+
result = subject.call('Which do you prefer, this one http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG, or this one http://rors.org/images/rails.png?')
|
32
|
+
expect(result).to eq('Which do you prefer, this one <img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" />, or this one <img src="http://rors.org/images/rails.png" />?')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'transforms an image link with a lot of param to image tag' do
|
36
|
+
result = subject.call('http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg')
|
37
|
+
expect(result).to eq('<img src="http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg" />')
|
38
|
+
end
|
39
|
+
end
|