auto_html 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -11
- data/lib/auto_html/auto_html_for.rb +22 -7
- metadata +2 -2
data/README.md
CHANGED
@@ -4,6 +4,14 @@ auto_html [![Build Status](https://secure.travis-ci.org/dejan/auto_html.png)](ht
|
|
4
4
|
|
5
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
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Specify the gem in Gemfile of the project
|
11
|
+
|
12
|
+
gem "auto_html"
|
13
|
+
|
14
|
+
|
7
15
|
## Example usage
|
8
16
|
|
9
17
|
Transforming string with text and URLs is done with *auto_html* method:
|
@@ -56,6 +64,11 @@ AutoHtml is highly customizable, and you can easily create new filters that will
|
|
56
64
|
end
|
57
65
|
|
58
66
|
|
67
|
+
## Bundled filters
|
68
|
+
|
69
|
+
For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
|
70
|
+
|
71
|
+
|
59
72
|
## Non-ActiveRecord models
|
60
73
|
|
61
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:
|
@@ -72,6 +85,7 @@ AutoHtml uses standard ActiveModel API, which means that you can include AutoHtm
|
|
72
85
|
end
|
73
86
|
end
|
74
87
|
|
88
|
+
|
75
89
|
## Rake and Capistrano tasks
|
76
90
|
|
77
91
|
AutoHtml has a Rake task for rebuilding cached in DB column values
|
@@ -84,19 +98,26 @@ If you want to run it on remote server, just add this to your `deploy.rb`:
|
|
84
98
|
|
85
99
|
Now you can run `cap auto_html:rebuild CLASS=[your_model]`.
|
86
100
|
|
87
|
-
## Bundled filters
|
88
|
-
|
89
|
-
For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
|
90
101
|
|
102
|
+
## Licence
|
91
103
|
|
92
|
-
|
93
|
-
|
94
|
-
Specify the gem in Gemfile of the project
|
95
|
-
|
96
|
-
gem "auto_html"
|
104
|
+
Copyright (c) 2009 Dejan Simic
|
97
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:
|
98
113
|
|
99
|
-
|
114
|
+
The above copyright notice and this permission notice shall be
|
115
|
+
included in all copies or substantial portions of the Software.
|
100
116
|
|
101
|
-
|
102
|
-
|
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.
|
@@ -15,19 +15,34 @@ module AutoHtmlFor
|
|
15
15
|
include AutoHtmlFor::InstanceMethods
|
16
16
|
|
17
17
|
suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
18
|
-
|
19
|
-
|
18
|
+
auto_html_for_columns = [raw_attrs].flatten.map { |a| "#{a}#{suffix}" }
|
19
|
+
|
20
|
+
# Needed for Mongoid
|
21
|
+
column_names = self.respond_to?(:column_names) ? self.column_names : fields.keys
|
22
|
+
|
23
|
+
missing_cache_columns = auto_html_for_columns - column_names
|
24
|
+
missing_cache_columns.each do |missing_cache_column|
|
25
|
+
raw_attr = missing_cache_column.gsub(suffix, '')
|
26
|
+
define_method(missing_cache_column) do
|
27
|
+
val = self[raw_attr]
|
28
|
+
auto_html(val, &proc)
|
29
|
+
end
|
20
30
|
end
|
21
|
-
|
31
|
+
|
32
|
+
cache_columns = auto_html_for_columns - missing_cache_columns
|
33
|
+
cache_columns.each do |cache_column|
|
34
|
+
raw_attr = cache_column.gsub(suffix, '')
|
22
35
|
define_method("#{raw_attr}=") do |val|
|
23
36
|
self[raw_attr] = val
|
24
37
|
result = auto_html(val, &proc)
|
25
|
-
|
26
|
-
result = result.html_safe
|
27
|
-
end
|
28
|
-
self.send("#{raw_attr}#{suffix}=", result)
|
38
|
+
self.send("#{cache_column}=", result)
|
29
39
|
val
|
30
40
|
end
|
41
|
+
|
42
|
+
define_method(cache_column) do
|
43
|
+
result = self[cache_column]
|
44
|
+
result.respond_to?(:html_safe) ? result.html_safe : result
|
45
|
+
end
|
31
46
|
end
|
32
47
|
|
33
48
|
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.
|
4
|
+
version: 1.5.3
|
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: 2012-05-
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rinku
|