Sha256: 2a198a8230bf332b127931c7787f0f035b06cca6ceb73d4ad8db0ab2582b1e6b

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

#!/usr/bin/env ruby

require File.expand_path('../helper', __FILE__)

class TestCustomTags < Test::Unit::TestCase

  module FigureTag
    def fig( opts )
      label, img = opts[:text].split('|').map! {|str| str.strip}

      html  = %Q{<div class="img" id="figure-#{label.tr('.', '-')}">\n}
      html << %Q{  <a class="fig" href="/images/#{img}">\n}
      html << %Q{    <img src="/images/thumbs/#{img}" alt="Figure #{label}" />\n}
      html << %Q{  </a>\n}
      html << %Q{  <p>Figure #{label}</p>\n}
      html << %Q{<div>\n}
    end
  end

  def test_fig_tag
    input  = %Q{The first line of text.\n\n}
    input << %Q{fig. 1.1 | img.jpg\n\n}
    input << %Q{The last line of text.\n}
    r = RedCloth.new input
    r.extend FigureTag
    str = r.to_html

    html  = %Q{<p>The first line of text.</p>\n}
    html << %Q{<div class="img" id="figure-1-1">\n}
    html << %Q{  <a class="fig" href="/images/img.jpg">\n}
    html << %Q{    <img src="/images/thumbs/img.jpg" alt="Figure 1.1" />\n}
    html << %Q{  </a>\n}
    html << %Q{  <p>Figure 1.1</p>\n}
    html << %Q{<div>\n}
    html << %Q{<p>The last line of text.</p>}

    assert_equal(html, str)
  end

  def test_fallback
    r = RedCloth.new %Q/fig()>[no]{color:red}. 1.1 | img.jpg/
    str = r.to_html

    assert_equal "<p>fig()>[no]{color:red}. 1.1 | img.jpg</p>", str
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
BBRedCloth-0.9.0.alpha1 test/test_custom_tags.rb
BBRedCloth-0.8.8 test/test_custom_tags.rb
BBRedCloth-0.8.7 test/test_custom_tags.rb
BBRedCloth-0.8.6 test/test_custom_tags.rb