Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow extensions that gsub! the input string for backward compatibili…
…ty. [#2 state:resolved]
- Loading branch information
Jason Garber
authored and
Jason Garber
committed
Jun 19, 2008
1 parent
5a319ab
commit 5512498
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class TestExtensions < Test::Unit::TestCase | ||
|
||
require 'redcloth' | ||
|
||
# http://www.ralree.info/2006/9/13/extending-redcloth | ||
module RedClothSmileyExtension | ||
def refs_smiley(text) | ||
text.gsub!(/(\s)~(:P|:D|:O|:o|:S|:\||;\)|:'\(|:\)|:\()/) do |m| | ||
bef,ma = $~[1..2] | ||
filename = "/images/emoticons/"+(ma.split(//).collect{|l| l[0] }.join('_'))+".png" | ||
"#{bef}<img src='#{filename}' title='#{ma}' class='smiley' />" | ||
end | ||
end | ||
end | ||
|
||
RedCloth.send(:include, RedClothSmileyExtension) | ||
|
||
def test_smiley | ||
input = %Q{You're so silly! ~:P} | ||
|
||
str = RedCloth.new(input).to_html(:textile, :refs_smiley) | ||
|
||
html = %Q{<p>You’re so silly! <img src='/images/emoticons/58_80.png' title=':P' class='smiley' /></p>} | ||
|
||
assert_equal(html, str) | ||
end | ||
end |