File: extension_spec.rb

package info (click to toggle)
ruby-redcloth 4.3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: ruby: 1,233; ansic: 201; makefile: 22
file content (26 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require File.dirname(__FILE__) + '/spec_helper'

# 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.unpack("c*").join('_'))+".png"
      "#{bef}<img src='#{filename}' title='#{ma}' class='smiley' />"
    end
  end
end

RedCloth.send(:include, RedClothSmileyExtension)

describe RedClothSmileyExtension do
  
  it "should include the extension" do
    input  = %Q{You're so silly! ~:P}

    html  = %Q{<p>You&#8217;re so silly! <img src='/images/emoticons/58_80.png' title=':P' class='smiley' /></p>}

    expect(RedCloth.new(input).to_html(:textile, :refs_smiley)).to eq(html)
  end
  
end