Skip to content

Commit

Permalink
Update the TIP formatter to handle multiline tips
Browse files Browse the repository at this point in the history
- includes 3 tests
  • Loading branch information
vrish88 committed Jul 24, 2011
1 parent 4b189bd commit e3dbe66
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion railties/guides/rails_guides/textile_extensions.rb
Expand Up @@ -15,10 +15,11 @@ def notestuff(body)
end

def tip(body)
body.gsub!(/^TIP[.:](.*)$/) do |m|
body.gsub!(/^TIP[.:](.*?)(\n\Z|\n\n+|\Z)/m) do |m|
result = "<div class='info'><p>"
result << $1.strip
result << '</p></div>'
result << $2 if $2
result
end
end
Expand Down
37 changes: 37 additions & 0 deletions railties/test/guides/textile_extionsions_test.rb
@@ -0,0 +1,37 @@
require 'isolation/abstract_unit'
require 'guides/rails_guides/textile_extensions'

class TextileExtensionsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
include RailsGuides::TextileExtensions

test "tips can handle a single line" do
expected_output = "<div class='info'><p>this is a single line tip</p></div>"
assert_equal expected_output, tip('TIP. this is a single line tip')
end

def setup
@multi_line_tip = "This is a multi-line tip.\n" +
"Isn't it fantastic?"
end

test "tips can handle a multi-line tip" do
expected_output = "<div class='info'><p>#{@multi_line_tip}</p></div>"

assert_equal expected_output, tip("TIP. #{@multi_line_tip}")
end

test "muli-line tips handles text before and after the tip" do
pre_line = "This is text before hand.\n\n"
post_line = "\n\nThis is some text after"
input_text = pre_line +
"TIP. #{@multi_line_tip}" +
post_line

expected_output = pre_line +
"<div class='info'><p>#{@multi_line_tip}</p></div>" +
post_line

assert_equal expected_output, tip(input_text)
end
end

0 comments on commit e3dbe66

Please sign in to comment.