formatize 1.1.0rc1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -23
- data/lib/formatize/helper.rb +57 -54
- data/lib/formatize/version.rb +1 -1
- metadata +22 -11
data/README.md
CHANGED
@@ -6,6 +6,8 @@ As of version 3, Rails doesn't have the `textilize`,
|
|
6
6
|
them back. Drop it into the old application you're upgrading and it'll smoothen
|
7
7
|
the process just that little bit more.
|
8
8
|
|
9
|
+
[![Build status badge](https://secure.travis-ci.org/dtrasbo/formatize.png)](http://travis-ci.org/dtrasbo/formatize)
|
10
|
+
|
9
11
|
Installation
|
10
12
|
------------
|
11
13
|
|
@@ -19,41 +21,49 @@ Usage
|
|
19
21
|
### The `textilize` & `textilize_without_paragraph` helper methods
|
20
22
|
|
21
23
|
The `textilize` helper method accepts a string of
|
22
|
-
[Textile](http://redcloth.org/textile) and one or more
|
23
|
-
|
24
|
+
[Textile](http://redcloth.org/textile) and one or more flags. Often, the
|
25
|
+
default behavior will be suitable and you will not have to pass it any flags:
|
24
26
|
|
25
27
|
textilize("*This is Textile!* Rejoice!")
|
26
28
|
# => "<p><strong>This is Textile!</strong> Rejoice!</p>"
|
27
29
|
|
28
|
-
|
29
|
-
can specify a single option:
|
30
|
-
|
31
|
-
textilize("This is worded <strong>strongly</strong>", :filter_html)
|
32
|
-
# => "<p>This is worded <strong>strongly</strong></p>"
|
33
|
-
|
34
|
-
Or you can specify multiple options:
|
30
|
+
When necessary, flags are listed as such:
|
35
31
|
|
36
|
-
textilize("
|
37
|
-
# => "
|
32
|
+
textilize("(snip)", :flag1, :flag2, :flag3)
|
33
|
+
# => "(snip)"
|
38
34
|
|
39
|
-
The `
|
40
|
-
|
41
|
-
|
42
|
-
for an overview on the options available.
|
35
|
+
[The `RedCloth` documentation](http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html)
|
36
|
+
lists the available flags. The `textilize_without_paragraps` method
|
37
|
+
delegates to `textilize` but strips the surrounding `<p>` tags.
|
43
38
|
|
44
39
|
### The `markdown` helper method
|
45
40
|
|
46
41
|
The `markdown` helper method accepts a string of
|
47
|
-
[Markdown](http://daringfireball.net/projects/markdown/)
|
42
|
+
[Markdown](http://daringfireball.net/projects/markdown/) and one or more
|
43
|
+
flags. Often, the default behavior will be suitable and you will not have
|
44
|
+
to pass it any flags:
|
48
45
|
|
49
46
|
markdown("We are using __Markdown__ now!")
|
50
47
|
# => "<p>We are using <strong>Markdown</strong> now!</p>"
|
51
48
|
|
52
|
-
|
53
|
-
|
49
|
+
When necessary, flags are listed as such:
|
50
|
+
|
51
|
+
markdown("(snip)", :flag1, :flag2, :flag3)
|
52
|
+
# => "(snip)"
|
53
|
+
|
54
|
+
[The `bluecloth` documentation](http://rubydoc.info/gems/bluecloth/BlueCloth)
|
55
|
+
lists the available flags.
|
56
|
+
|
57
|
+
Sanitization
|
58
|
+
------------
|
59
|
+
|
60
|
+
Both `textilize` and `markdown` sanitizes the input using Rails'
|
61
|
+
`sanitize` prior to parsing. Since both gems can do this themselves,
|
62
|
+
it's useful to be able to bypass the pre-parsing sanitization. Two ways:
|
54
63
|
|
55
|
-
|
56
|
-
|
64
|
+
1. Pass a string that has been marked HTML safe. (Preferred).
|
65
|
+
2. Use the special `:safe` flag, which is not passed on to the parser.
|
66
|
+
_(Deprecated in 1.1, removed in 2.0)._
|
57
67
|
|
58
68
|
Compatibility
|
59
69
|
-------------
|
@@ -70,13 +80,21 @@ jump through hoops to support other versions. 1.8 support may be dropped
|
|
70
80
|
eventually.
|
71
81
|
|
72
82
|
### Rails versions
|
73
|
-
* 3.2.
|
74
|
-
* 3.1.
|
75
|
-
* 3.0.
|
83
|
+
* 3.2.2
|
84
|
+
* 3.1.4
|
85
|
+
* 3.0.12
|
76
86
|
|
77
87
|
The latest versions in all the 3.0 series. This is likely to change when
|
78
88
|
4.0 is released.
|
79
89
|
|
90
|
+
Dependencies
|
91
|
+
------------
|
92
|
+
|
93
|
+
* `RedCloth` gem
|
94
|
+
* `bluecloth` gem
|
95
|
+
|
96
|
+
[![Dependency status badge](https://gemnasium.com/dtrasbo/formatize.png)](https://gemnasium.com/dtrasbo/formatize)
|
97
|
+
|
80
98
|
Copyright & Licensing
|
81
99
|
---------------------
|
82
100
|
|
data/lib/formatize/helper.rb
CHANGED
@@ -1,91 +1,94 @@
|
|
1
1
|
module Formatize
|
2
2
|
module Helper
|
3
|
-
#
|
3
|
+
# Accepts a string of Textile {http://redcloth.org/textile} and one or
|
4
|
+
# more flags. Often, the default behavior will be suitable and you will not
|
5
|
+
# have to pass it any flags:
|
4
6
|
#
|
5
|
-
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
|
6
|
-
# <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
|
7
|
-
#
|
8
|
-
# ==== Examples
|
9
7
|
# textilize("*This is Textile!* Rejoice!")
|
10
8
|
# # => "<p><strong>This is Textile!</strong> Rejoice!</p>"
|
11
9
|
#
|
12
|
-
#
|
13
|
-
# # => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>"
|
10
|
+
# When necessary, flags are listed as such:
|
14
11
|
#
|
15
|
-
# textilize("
|
16
|
-
# # => "
|
12
|
+
# textilize("(snip)", :flag1, :flag2, :flag3)
|
13
|
+
# # => "(snip)"
|
17
14
|
#
|
18
|
-
#
|
19
|
-
#
|
15
|
+
# The +RedCloth+ documentation {http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html}
|
16
|
+
# lists the available flags.
|
20
17
|
#
|
21
|
-
#
|
22
|
-
#
|
18
|
+
# It sanitizes the input using Rails' +sanitize+ prior to parsing.
|
19
|
+
# There are two ways to bypass pre-parsing sanitization:
|
23
20
|
#
|
24
|
-
#
|
25
|
-
#
|
21
|
+
# 1. Pass a string that has been marked HTML safe. (Preferred).
|
22
|
+
# 2. Use the special <tt>:safe</tt> flag, which is not passed on to the
|
23
|
+
# parser. _(Deprecated in 1.1, removed in 2.0)._
|
26
24
|
#
|
27
|
-
def textilize(text, *
|
25
|
+
def textilize(text, *flags)
|
28
26
|
require 'RedCloth'
|
29
27
|
|
30
|
-
|
28
|
+
if safe = flags.delete(:safe)
|
29
|
+
ActiveSupport::Deprecation.warn('The :safe flag is deprecated. Mark the input HTML safe instead.')
|
30
|
+
end
|
31
|
+
|
32
|
+
text = sanitize(text) unless text.html_safe? || safe
|
31
33
|
|
32
34
|
if text.blank?
|
33
35
|
""
|
34
36
|
else
|
35
|
-
|
36
|
-
textilized.to_html
|
37
|
+
RedCloth.new(text, flags).to_html
|
37
38
|
end.html_safe
|
38
39
|
end
|
39
40
|
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
|
44
|
-
# <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
|
45
|
-
#
|
46
|
-
# ==== Examples
|
47
|
-
# textilize_without_paragraph("*This is Textile!* Rejoice!")
|
48
|
-
# # => "<strong>This is Textile!</strong> Rejoice!"
|
49
|
-
#
|
50
|
-
# textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
|
51
|
-
# # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
|
41
|
+
# Delegates to +textilize+ but strips the surrounding <tt><p></tt>
|
42
|
+
# tags.
|
52
43
|
#
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
# textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
|
57
|
-
# # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
|
58
|
-
def textilize_without_paragraph(text, *options)
|
59
|
-
require 'RedCloth'
|
60
|
-
|
61
|
-
textiled = textilize(text, *options)
|
44
|
+
def textilize_without_paragraph(text, *flags)
|
45
|
+
textiled = textilize(text, *flags)
|
62
46
|
if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
|
63
47
|
if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
|
64
48
|
return textiled
|
65
49
|
end
|
66
50
|
|
67
|
-
#
|
68
|
-
#
|
69
|
-
# to
|
51
|
+
# Accepts a string of Markdown {http://daringfireball.net/projects/markdown/}
|
52
|
+
# and one or more flags. Often, the default behavior will be suitable and
|
53
|
+
# you will not have to pass it any flags:
|
70
54
|
#
|
71
|
-
# ==== Examples
|
72
55
|
# markdown("We are using __Markdown__ now!")
|
73
56
|
# # => "<p>We are using <strong>Markdown</strong> now!</p>"
|
74
57
|
#
|
75
|
-
#
|
76
|
-
#
|
58
|
+
# When necessary, flags are listed as such:
|
59
|
+
#
|
60
|
+
# markdown("(snip)", :flag1, :flag2, :flag3)
|
61
|
+
# # => "(snip)"
|
77
62
|
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
# # has more information.</p>"
|
63
|
+
# The +bluecloth+ documentation {http://rubydoc.info/gems/bluecloth/BlueCloth}
|
64
|
+
# lists the available flags.
|
81
65
|
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
|
66
|
+
# It sanitizes the input using Rails' +sanitize+ prior to parsing.
|
67
|
+
# There are two ways to bypass pre-parsing sanitization:
|
68
|
+
#
|
69
|
+
# 1. Pass a string that has been marked HTML safe. (Preferred).
|
70
|
+
# 2. Use the special <tt>:safe</tt> flag, which is not passed on to the
|
71
|
+
# parser. _(Deprecated in 1.1, removed in 2.0)._
|
72
|
+
#
|
73
|
+
def markdown(text, *flags)
|
85
74
|
require 'bluecloth'
|
86
75
|
|
87
|
-
|
88
|
-
|
76
|
+
if safe = flags.delete(:safe)
|
77
|
+
ActiveSupport::Deprecation.warn('The :safe flag is deprecated. Mark the input HTML safe instead.')
|
78
|
+
end
|
79
|
+
|
80
|
+
text = sanitize(text) unless text.html_safe? || safe
|
81
|
+
|
82
|
+
if text.blank?
|
83
|
+
""
|
84
|
+
else
|
85
|
+
flags_hash = {}
|
86
|
+
flags.each do |flag|
|
87
|
+
flags_hash[flag] = true
|
88
|
+
end
|
89
|
+
|
90
|
+
BlueCloth.new(text, flags_hash).to_html
|
91
|
+
end.html_safe
|
89
92
|
end
|
90
93
|
end
|
91
94
|
end
|
data/lib/formatize/version.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- David Trasbo
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02
|
12
|
+
date: 2012-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: RedCloth
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152485440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '4.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152485440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bluecloth
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152343560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152343560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: actionpack
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152259580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '3.0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152259580
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &2152136760 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152136760
|
47
58
|
description:
|
48
59
|
email: me@dtrasbo.com
|
49
60
|
executables: []
|
@@ -70,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
82
|
none: false
|
72
83
|
requirements:
|
73
|
-
- - ! '
|
84
|
+
- - ! '>='
|
74
85
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
86
|
+
version: '0'
|
76
87
|
requirements: []
|
77
88
|
rubyforge_project:
|
78
89
|
rubygems_version: 1.8.16
|