Sha256: ebf35bc0322778760dda6e4665c9c921fc86880dd8071ca6fd0a99dde4c03bb9

Contents?: true

Size: 839 Bytes

Versions: 8

Compression:

Stored size: 839 Bytes

Contents

#!/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&#8217;re so silly! <img src='/images/emoticons/58_80.png' title=':P' class='smiley' /></p>}

    assert_equal(html, str)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
RedCloth-4.0.1 test/test_extensions.rb
RedCloth-4.0.2 test/test_extensions.rb
RedCloth-4.0.2-x86-mswin32-60 test/test_extensions.rb
RedCloth-4.0.3-x86-mswin32-60 test/test_extensions.rb
RedCloth-4.0.0 test/test_extensions.rb
RedCloth-4.0.0-x86-mswin32-60 test/test_extensions.rb
RedCloth-4.0.1-x86-mswin32-60 test/test_extensions.rb
RedCloth-4.0.3 test/test_extensions.rb