Skip to content

Commit

Permalink
Removed textilize, textilize_without_paragraph and markdown helpers
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
spastorino authored and josevalim committed Jun 9, 2010
1 parent f48aa14 commit 0919c0d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 195 deletions.
4 changes: 0 additions & 4 deletions Gemfile
Expand Up @@ -44,10 +44,6 @@ elsif RUBY_ENGINE == "jruby"
end
end

# AP
gem "RedCloth", ">= 4.2.2"
gem "bluecloth", ">= 2.0.7"

group :documentation do
gem 'rdoc', '2.1'
end
Expand Down
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,3 +1,5 @@
* Removed textilize, textilize_without_paragraph and markdown helpers. [Santiago Pastorino]

*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* Remove middleware laziness [José Valim]
Expand Down
83 changes: 0 additions & 83 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -220,89 +220,6 @@ def word_wrap(text, *args)
end * "\n"
end

# Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags.
#
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
# <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
#
# ==== Examples
# textilize("*This is Textile!* Rejoice!")
# # => "<p><strong>This is Textile!</strong> Rejoice!</p>"
#
# textilize("I _love_ ROR(Ruby on Rails)!")
# # => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>"
#
# textilize("h2. Textile makes markup -easy- simple!")
# # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
#
# textilize("Visit the Rails website "here":http://www.rubyonrails.org/.)
# # => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>"
#
# textilize("This is worded <strong>strongly</strong>")
# # => "<p>This is worded <strong>strongly</strong></p>"
#
# textilize("This is worded <strong>strongly</strong>", :filter_html)
# # => "<p>This is worded &lt;strong&gt;strongly&lt;/strong&gt;</p>"
#
def textilize(text, *options)
options ||= [:hard_breaks]
text = sanitize(text) unless text.html_safe? || options.delete(:safe)

if text.blank?
""
else
textilized = RedCloth.new(text, options)
textilized.to_html
end.html_safe
end

# Returns the text with all the Textile codes turned into HTML tags,
# but without the bounding <p> tag that RedCloth adds.
#
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
# <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
#
# ==== Examples
# textilize_without_paragraph("*This is Textile!* Rejoice!")
# # => "<strong>This is Textile!</strong> Rejoice!"
#
# textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
# # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
#
# textilize_without_paragraph("h2. Textile makes markup -easy- simple!")
# # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
#
# textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
# # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
def textilize_without_paragraph(text, *options)
textiled = textilize(text, *options)
if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
return textiled
end

# Returns the text with all the Markdown codes turned into HTML tags.
# <i>This method requires BlueCloth[http://www.deveiate.org/projects/BlueCloth]
# to be available</i>.
#
# ==== Examples
# markdown("We are using __Markdown__ now!")
# # => "<p>We are using <strong>Markdown</strong> now!</p>"
#
# markdown("We like to _write_ `code`, not just _read_ it!")
# # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
#
# markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
# # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
# # has more information.</p>"
#
# markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
# # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
def markdown(text, *options)
text = sanitize(text) unless text.html_safe? || options.delete(:safe)
(text.blank? ? "" : BlueCloth.new(text).to_html).html_safe
end

# Returns +text+ transformed into HTML using simple formatting rules.
# Two or more consecutive newlines(<tt>\n\n</tt>) are considered as a
# paragraph and wrapped in <tt><p></tt> tags. One newline (<tt>\n</tt>) is
Expand Down
108 changes: 0 additions & 108 deletions actionpack/test/template/text_helper_test.rb
@@ -1,17 +1,6 @@
# encoding: us-ascii
require 'abstract_unit'
require 'testing_sandbox'
begin
require 'redcloth'
rescue LoadError
$stderr.puts "Skipping textilize tests. `gem install RedCloth` to enable."
end

begin
require 'bluecloth'
rescue LoadError
$stderr.puts "Skipping markdown tests. 'gem install bluecloth' to enable."
end

class TextHelperTest < ActionView::TestCase
tests ActionView::Helpers::TextHelper
Expand Down Expand Up @@ -665,101 +654,4 @@ def test_cycle_no_instance_variable_clashes
assert_equal("red", cycle("red", "blue"))
assert_equal(%w{Specialized Fuji Giant}, @cycles)
end

# TODO test textilize_without_paragraph and markdown
if defined? RedCloth
def test_textilize_should_be_html_safe
assert textilize("*This is Textile!* Rejoice!").html_safe?
end

def test_textilize
assert_equal("<p><strong>This is Textile!</strong> Rejoice!</p>", textilize("*This is Textile!* Rejoice!"))
end

def test_textilize_with_blank
assert_equal("", textilize(""))
end

def test_textilize_with_options
assert_equal("<p>This is worded &lt;strong&gt;strongly&lt;/strong&gt;</p>", textilize("This is worded <strong>strongly</strong>", :filter_html))
end

def test_textilize_should_sanitize_unsafe_input
assert_equal("<p>This is worded <strong>strongly</strong></p>", textilize("This is worded <strong>strongly</strong><script>code!</script>"))
end

def test_textilize_should_not_sanitize_input_if_safe_option
assert_equal("<p>This is worded <strong>strongly</strong><script>code!</script></p>", textilize("This is worded <strong>strongly</strong><script>code!</script>", :safe))
end

def test_textilize_should_not_sanitize_safe_input
assert_equal("<p>This is worded <strong>strongly</strong><script>code!</script></p>", textilize("This is worded <strong>strongly</strong><script>code!</script>".html_safe))
end

def test_textilize_with_hard_breaks
assert_equal("<p>This is one scary world.<br />\n True.</p>", textilize("This is one scary world.\n True."))
end

def test_textilize_without_paragraph_should_be_html_safe
textilize_without_paragraph("*This is Textile!* Rejoice!").html_safe?
end

def test_textilize_without_paragraph
assert_equal("<strong>This is Textile!</strong> Rejoice!", textilize_without_paragraph("*This is Textile!* Rejoice!"))
end

def test_textilize_without_paragraph_with_blank
assert_equal("", textilize_without_paragraph(""))
end

def test_textilize_without_paragraph_with_options
assert_equal("This is worded &lt;strong&gt;strongly&lt;/strong&gt;", textilize_without_paragraph("This is worded <strong>strongly</strong>", :filter_html))
end

def test_textilize_without_paragraph_should_sanitize_unsafe_input
assert_equal("This is worded <strong>strongly</strong>", textilize_without_paragraph("This is worded <strong>strongly</strong><script>code!</script>"))
end

def test_textilize_without_paragraph_should_not_sanitize_input_if_safe_option
assert_equal("This is worded <strong>strongly</strong><script>code!</script>", textilize_without_paragraph("This is worded <strong>strongly</strong><script>code!</script>", :safe))
end

def test_textilize_without_paragraph_should_not_sanitize_safe_input
assert_equal("This is worded <strong>strongly</strong><script>code!</script>", textilize_without_paragraph("This is worded <strong>strongly</strong><script>code!</script>".html_safe))
end

def test_textilize_without_paragraph_with_hard_breaks
assert_equal("This is one scary world.<br />\n True.", textilize_without_paragraph("This is one scary world.\n True."))
end
end

if defined? BlueCloth
def test_markdown_should_be_html_safe
assert markdown("We are using __Markdown__ now!").html_safe?
end

def test_markdown
assert_equal("<p>We are using <strong>Markdown</strong> now!</p>", markdown("We are using __Markdown__ now!"))
end

def test_markdown_with_blank
assert_equal("", markdown(""))
end

def test_markdown_should_sanitize_unsafe_input
assert_equal("<p>This is worded <strong>strongly</strong></p>", markdown("This is worded <strong>strongly</strong><script>code!</script>"))
end

def test_markdown_should_not_sanitize_input_if_safe_option
assert_equal("<p>This is worded <strong>strongly</strong><script>code!</script></p>", markdown("This is worded <strong>strongly</strong><script>code!</script>", :safe))
end

def test_markdown_should_not_sanitize_safe_input
assert_equal("<p>This is worded <strong>strongly</strong><script>code!</script></p>", markdown("This is worded <strong>strongly</strong><script>code!</script>".html_safe))
end

def test_markdown_with_hard_breaks
assert_equal("<p>This is one scary world.</p>\n\n<p>True.</p>", markdown("This is one scary world.\n\nTrue."))
end
end
end

16 comments on commit 0919c0d

@nicolasblanco
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted in a plugin?

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin extraction is in the to-do-list. If you want to go ahead and do it, we appreciate!

@rohitarondekar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MY PRECIOUSSS!!!

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL

@sikachu
Copy link
Member

@sikachu sikachu commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was complained with myself about 'Why do I need RedCloth and BlueCloth', and today you remove 'em both. Thanks a lot man!

@reu
Copy link
Contributor

@reu reu commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW Josevalim, I just extract them, if you want just clone the repo

http://github.com/reu/markup_helpers

@dtrasbo
Copy link
Contributor

@dtrasbo dtrasbo commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

José,

As a matter of fact I've extracted the helpers into a gem/plugin too. Didn't know someone else was working on it as well.

http://github.com/dtrasbo/formatize

reu: I'm not making this into a competition or anything - I just want to point out that Formatize has a thorough readme, plus it's been released as a gem. (It can also be installed as a plugin).

@jeremy
Copy link
Member

@jeremy jeremy commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks David and Rodrigo!

@reu
Copy link
Contributor

@reu reu commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey dtrasbo, no problems at all. I didn't know you were working on that too, and clearly your version of the extraction is way better.

@dtrasbo
Copy link
Contributor

@dtrasbo dtrasbo commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reu: Thanks! I'm glad you think that way. :)

@spastorino
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already did the plugin when i remove this code but of course as it was said on RailsIgnite we can have text_helper, text_helper_fu and sexy_text_helper plugins :P. I need a rails/text_helper repo created though.

@dtrasbo
Copy link
Contributor

@dtrasbo dtrasbo commented on 0919c0d Jun 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spastorino,

Well, in that case it might have been helpful to mention it in the commit message.

I spent quite a bit of time doing that extraction and I'm sure reu did too.

@spastorino
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go ahead dtrasbo is yours ;)

@rohitarondekar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? :O
Next time I don't sleep on an idea! I thought I would extract those helpers into a plugin in the morning. Wake up and find everybody has done it! :P

@rohitarondekar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote one too. :)
More for learning sake though, not to compete with David's formatize. Also I've used RDiscount instead of BlueCloth and made some minor internal tweaks. http://github.com/rohit/prarupa
P.S It's my 1st plugin/gem so things may explode. :)

@arnekolja
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why weren't this one put into the release notes for Rails 3.0.0 final? It cost me and a co-worker a lot of searching for the reason why this one is gone without any note about it. Especially because it was still there in the betas. It's a good step to modularize it that way, but I think there might be many people who run into errors because of not speaking it out loud.

Please sign in to comment.