formatize 1.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +70 -0
- data/lib/formatize.rb +5 -0
- data/lib/formatize/helpers.rb +92 -0
- data/lib/formatize/version.rb +3 -0
- metadata +116 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 David Heinemeier Hansson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Formatize
|
2
|
+
=========
|
3
|
+
|
4
|
+
Plugin containing the `textilize`, `textilize_without_paragraph`, and
|
5
|
+
`markdown` helpers removed from Rails.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
To install as a gem (recommended), add this to the Gemfile of the application
|
11
|
+
and run `bundle install`:
|
12
|
+
|
13
|
+
gem 'formatize'
|
14
|
+
|
15
|
+
Alternatively, you can install as a plugin:
|
16
|
+
|
17
|
+
rails plugin install git://github.com/dtrasbo/formatize.git
|
18
|
+
|
19
|
+
Don't forget to add the `RedCloth` and/or `bluecloth` gems to the Gemfile if
|
20
|
+
you go with the plugin. They will be installed
|
21
|
+
automatically when installing the gem.
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
### The `textilize` & `textilize_without_paragraph` helpers
|
27
|
+
|
28
|
+
The `textilize` helper accepts a string of
|
29
|
+
[Textile](http://redcloth.org/textile) and one or more options. In most cases
|
30
|
+
the default behavior will be suitable and you will not have to pass it any options:
|
31
|
+
|
32
|
+
textilize("*This is Textile!* Rejoice!")
|
33
|
+
# => "<p><strong>This is Textile!</strong> Rejoice!</p>"
|
34
|
+
|
35
|
+
Sometimes, however, you want to customize how RedCloth parses your Textile. You
|
36
|
+
can specify a single option:
|
37
|
+
|
38
|
+
textilize("This is worded <strong>strongly</strong>", :filter_html)
|
39
|
+
# => "<p>This is worded <strong>strongly</strong></p>"
|
40
|
+
|
41
|
+
Or you can specify multiple options:
|
42
|
+
|
43
|
+
textilize("This is worded <strong>strongly</strong>", :filter_html, :lite_mode)
|
44
|
+
# => "This is worded <strong>strongly</strong>"
|
45
|
+
|
46
|
+
The `textilize_without_paragraph` works similarly except it omits the
|
47
|
+
surrounding `<p>` tag. Check out the documentation for
|
48
|
+
[`RedCloth::TextileDoc`](http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html)
|
49
|
+
for an overview on the options available.
|
50
|
+
|
51
|
+
### The `markdown` helper
|
52
|
+
|
53
|
+
The `markdown` helper accepts a string of
|
54
|
+
[Markdown](http://daringfireball.net/projects/markdown/):
|
55
|
+
|
56
|
+
markdown("We are using __Markdown__ now!")
|
57
|
+
# => "<p>We are using <strong>Markdown</strong> now!</p>"
|
58
|
+
|
59
|
+
If you set the `:safe` option to `true` the input string will be not sanitized
|
60
|
+
before conversion:
|
61
|
+
|
62
|
+
markdown("<em>We are using __Markdown__ now!</em>", :safe => true)
|
63
|
+
# => "<p><em>We are using <strong>Markdown</strong> now!</em></p>"
|
64
|
+
|
65
|
+
Copyright & Licensing
|
66
|
+
---------------------
|
67
|
+
|
68
|
+
Copyright (c) 2010 David Heinemeier Hansson
|
69
|
+
|
70
|
+
Released under the MIT License. See LICENSE for details.
|
data/lib/formatize.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
module Formatize
|
2
|
+
module Helpers
|
3
|
+
# Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags.
|
4
|
+
#
|
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
|
+
# textilize("*This is Textile!* Rejoice!")
|
10
|
+
# # => "<p><strong>This is Textile!</strong> Rejoice!</p>"
|
11
|
+
#
|
12
|
+
# textilize("I _love_ ROR(Ruby on Rails)!")
|
13
|
+
# # => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>"
|
14
|
+
#
|
15
|
+
# textilize("h2. Textile makes markup -easy- simple!")
|
16
|
+
# # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
|
17
|
+
#
|
18
|
+
# textilize("Visit the Rails website "here":http://www.rubyonrails.org/.)
|
19
|
+
# # => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>"
|
20
|
+
#
|
21
|
+
# textilize("This is worded <strong>strongly</strong>")
|
22
|
+
# # => "<p>This is worded <strong>strongly</strong></p>"
|
23
|
+
#
|
24
|
+
# textilize("This is worded <strong>strongly</strong>", :filter_html)
|
25
|
+
# # => "<p>This is worded <strong>strongly</strong></p>"
|
26
|
+
#
|
27
|
+
def textilize(text, *options)
|
28
|
+
require 'RedCloth'
|
29
|
+
|
30
|
+
options ||= [:hard_breaks]
|
31
|
+
text = sanitize(text) unless text.html_safe? || options.delete(:safe)
|
32
|
+
|
33
|
+
if text.blank?
|
34
|
+
""
|
35
|
+
else
|
36
|
+
textilized = RedCloth.new(text, options)
|
37
|
+
textilized.to_html
|
38
|
+
end.html_safe
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the text with all the Textile codes turned into HTML tags,
|
42
|
+
# but without the bounding <p> tag that RedCloth adds.
|
43
|
+
#
|
44
|
+
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
|
45
|
+
# <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
|
46
|
+
#
|
47
|
+
# ==== Examples
|
48
|
+
# textilize_without_paragraph("*This is Textile!* Rejoice!")
|
49
|
+
# # => "<strong>This is Textile!</strong> Rejoice!"
|
50
|
+
#
|
51
|
+
# textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
|
52
|
+
# # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
|
53
|
+
#
|
54
|
+
# textilize_without_paragraph("h2. Textile makes markup -easy- simple!")
|
55
|
+
# # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
|
56
|
+
#
|
57
|
+
# textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
|
58
|
+
# # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
|
59
|
+
def textilize_without_paragraph(text, *options)
|
60
|
+
require 'RedCloth'
|
61
|
+
|
62
|
+
textiled = textilize(text, *options)
|
63
|
+
if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
|
64
|
+
if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
|
65
|
+
return textiled
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns the text with all the Markdown codes turned into HTML tags.
|
69
|
+
# <i>This method requires BlueCloth[http://www.deveiate.org/projects/BlueCloth]
|
70
|
+
# to be available</i>.
|
71
|
+
#
|
72
|
+
# ==== Examples
|
73
|
+
# markdown("We are using __Markdown__ now!")
|
74
|
+
# # => "<p>We are using <strong>Markdown</strong> now!</p>"
|
75
|
+
#
|
76
|
+
# markdown("We like to _write_ `code`, not just _read_ it!")
|
77
|
+
# # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
|
78
|
+
#
|
79
|
+
# markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
|
80
|
+
# # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
|
81
|
+
# # has more information.</p>"
|
82
|
+
#
|
83
|
+
# markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
|
84
|
+
# # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
|
85
|
+
def markdown(text, *options)
|
86
|
+
require 'bluecloth'
|
87
|
+
|
88
|
+
text = sanitize(text) unless text.html_safe? || options.delete(:safe)
|
89
|
+
(text.blank? ? "" : BlueCloth.new(text).to_html).html_safe
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formatize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -245658376
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0rc1
|
10
|
+
version: 1.0.0rc1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Heinemeier Hansson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-09 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: RedCloth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 31
|
30
|
+
segments:
|
31
|
+
- 4
|
32
|
+
- 2
|
33
|
+
version: "4.2"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bluecloth
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 0
|
48
|
+
version: "2.0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: actionpack
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description:
|
66
|
+
email: david@loudthinking.com
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files: []
|
72
|
+
|
73
|
+
files:
|
74
|
+
- lib/formatize/helpers.rb
|
75
|
+
- lib/formatize/version.rb
|
76
|
+
- lib/formatize.rb
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://github.com/dtrasbo/formatize
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 25
|
103
|
+
segments:
|
104
|
+
- 1
|
105
|
+
- 3
|
106
|
+
- 1
|
107
|
+
version: 1.3.1
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.3.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Plugin containing the textilize, textilize_without_paragraph, and markdown helpers removed from Rails.
|
115
|
+
test_files: []
|
116
|
+
|