prarupa 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ Prarupa
2
+ =======
3
+
4
+ Prarupa is plugin for Rails 3 that provides the `textilize`, `textilize_without_paragraph` and `markdown` helpers. These were extracted from Rails and have been modified slightly. Instead of using `BlueCloth` for `markdown`, Prarupa uses `RDiscount` which is supposed to be faster and better maintained. Other minor internal tweaks have been made.
5
+
6
+ Install
7
+ =======
8
+
9
+ You can either install Prarupa as a gem or plugin. Installing as a gem is the preferred choice.
10
+
11
+ Install as a gem
12
+ ----------------
13
+
14
+ Simply add `prarupa` to the Gemfile. Also add `RedCloth` for textilize & textilize_without_paragraph and/or add `rdiscount` for markdown. Now just `bundle install` and you should be good to go. Note that installing `prarupa` will also install `rdiscount` and `markdown` as dependencies.
15
+
16
+ Install as a plugin
17
+ -------------------
18
+
19
+ To install as a plugin simply do `rails plugin install git://github.com/rohit/prarupa.git`
20
+
21
+ Example
22
+ =======
23
+
24
+ In your views you can do the following.
25
+
26
+ The `textilize` and `textilize_without_paragraph` helpers
27
+ ---------------------------------------------------------
28
+
29
+ The `textilize` helper accepts a string of [Textile](http://redcloth.org/textile) and optionally one or more options.
30
+
31
+ Without any options:
32
+
33
+ textilize("This is *how* we _textilize_ in Rails!")
34
+ # => "<p>This is <strong>how</strong> we <em>textilize</em> in Rails!</p>"
35
+
36
+ With options:
37
+
38
+ textilize("This is *how* we <em>textilize</em> in Rails!", :filter_html)
39
+ # => "<p>This is <strong>how</strong> we &lt;em&gt;textilize&lt;/em&gt; in Rails!</p>"
40
+
41
+ Note that you can provide multiple options like `textilize("text", :filter_html, :lite_mode)`
42
+
43
+ The `textilize_without_paragraph` is similar to `textilize`, except that the surrounding &lt;p&gt; and &lt;/p&gt; tags are removed. It accepts options just like `textilize`
44
+
45
+ textilize_without_paragraph("This is *how* we _textilize_ in Rails!")
46
+ # => "This is <strong>how</strong> we <em>textilize</em> in Rails!"
47
+
48
+ The `markdown` helper
49
+ ---------------------
50
+
51
+ The `markdown` helper accepts a string of [Markdown](http://daringfireball.net/projects/markdown/) and optionally one or more options.
52
+
53
+ Without any options:
54
+
55
+ markdown("This is *how* we **markdown** in Rails!")
56
+ # => "<p>This is <em>how</em> we <strong>markdown</strong> in Rails!</p>"
57
+
58
+ With options:
59
+
60
+ markdown("Greedy urls are here! http://rohitarondekar.com", :autolink)
61
+ # => "<p>Greedy urls are here! <a href=\"http://rohitarondekar.com\">http://rohitarondekar.com</a></p>"
62
+
63
+ To be `:safe`
64
+ ============
65
+
66
+ Being Rails text helpers, all three methods accept the `:safe` option that tells the helpers that the input text need not be sanitized.
67
+
68
+ Credits
69
+ =======
70
+
71
+ [David Trasbo](http://github.com/dtrasbo) for making the awesome (official?) plugin [formatize](http://github.com/dtrasbo/formatize) which extracts the helpers without any modification. I liberally used his gem as reference.
72
+
73
+ Todo
74
+ ====
75
+
76
+ * Tidy up the rdocs
77
+
78
+ Copyright (c) 2010 Rohit Arondekar, released under the MIT license
@@ -0,0 +1,92 @@
1
+ module Prarupa
2
+ module TextHelpers
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 requires RedCloth[http://redcloth.org/] to be installed</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 &lt;strong&gt;strongly&lt;/strong&gt;</p>"
26
+ #
27
+ def textilize(text, *options)
28
+ options ||= [:hard_breaks]
29
+ text = sanitize(text) unless text.html_safe? || options.delete(:safe)
30
+
31
+ if text.blank?
32
+ ""
33
+ else
34
+ textilized = RedCloth.new(text, options)
35
+ textilized.to_html.html_safe
36
+ end
37
+ end
38
+
39
+ # Returns the text with all the Textile codes turned into HTML tags,
40
+ # but without the bounding <p> tag that RedCloth adds.
41
+ #
42
+ # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
43
+ # <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
44
+ #
45
+ # ==== Examples
46
+ # textilize_without_paragraph("*This is Textile!* Rejoice!")
47
+ # # => "<strong>This is Textile!</strong> Rejoice!"
48
+ #
49
+ # textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
50
+ # # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
51
+ #
52
+ # textilize_without_paragraph("h2. Textile makes markup -easy- simple!")
53
+ # # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
54
+ #
55
+ # textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
56
+ # # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
57
+ def textilize_without_paragraph(text, *options)
58
+ textiled = textilize(text, *options)
59
+ if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
60
+ if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
61
+ return textiled
62
+ end
63
+
64
+ # Returns the text with all the Markdown codes turned into HTML tags.
65
+ # <i>This method requires RDiscount[http://github.com/rtomayko/rdiscount/]
66
+ # to be available</i>.
67
+ #
68
+ # ==== Examples
69
+ # markdown("We are using __Markdown__ now!")
70
+ # # => "<p>We are using <strong>Markdown</strong> now!</p>"
71
+ #
72
+ # markdown("We like to _write_ `code`, not just _read_ it!")
73
+ # # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
74
+ #
75
+ # markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
76
+ # # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
77
+ # # has more information.</p>"
78
+ #
79
+ # markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
80
+ # # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
81
+ def markdown(text, *options)
82
+ text = sanitize(text) unless text.html_safe? || options.delete(:safe)
83
+
84
+ if text.blank?
85
+ ""
86
+ else
87
+ markdowned = RDiscount.new(text, *options)
88
+ markdowned.to_html.chomp.html_safe #used chomp to remove the \n appended by RDiscount
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Prarupa
2
+ VERSION = '0.1'
3
+ end
data/lib/prarupa.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'prarupa/text_helpers'
2
+
3
+ class ActionView::Base
4
+ include Prarupa::TextHelpers
5
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prarupa
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Rohit Arondekar
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-06-10 00:00:00 +05:30
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: RedCloth
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 4
29
+ - 2
30
+ version: "4.2"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rdiscount
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 6
44
+ version: "1.6"
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description:
48
+ email: hello@rohitarondekar.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ files:
56
+ - lib/prarupa.rb
57
+ - lib/prarupa/text_helpers.rb
58
+ - lib/prarupa/version.rb
59
+ - README.md
60
+ has_rdoc: true
61
+ homepage: http://github.com/rohit/prarupa
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Plugin that adds the textilized, textilize_without_paragraph and markdown helpers to Rails 3
92
+ test_files: []
93
+