ClothRed 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/clothred.rb CHANGED
@@ -17,7 +17,7 @@ License:: BSD
17
17
 
18
18
  class ClothRed < String
19
19
  #--
20
- FORMATTING_HTML = [
20
+ TEXT_FORMATTING = [
21
21
  ["<b>", "**"], ["</b>","**"], ["<em>","_"], ["</em>", "_"], ["<b>", "*"],
22
22
  ["</b>", "*"], ["<cite>", "??"], ["</cite>", "??"], ["<code>", "@"],
23
23
  ["</code>", "@"], ["<del>", "-"], ["</del>", "-"], ["<ins>", "+"],
@@ -25,18 +25,69 @@ class ClothRed < String
25
25
  ["<strong>", "*"], ["</strong>", "*"], ["<i>","__"], ["</i>", "__"]
26
26
  ]
27
27
 
28
+ HEADINGS = [
29
+ ["<h1>","h1. "], ["</h1>", ""], ["<h2>","h2. "],["</h2>", ""],
30
+ ["<h3>","h3. "], ["</h3>", ""], ["<h4>","h4. "],["</h4>", ""],
31
+ ["<h5>","h5. "], ["</h5>", ""], ["<h6>","h6. "],["</h6>", ""]
32
+ ]
33
+
34
+ STRUCTURES = [
35
+ ["<p>", ""],["</p>","\n\n"], ["<blockquote>", "bq. "], ["</blockquote>",""]
36
+ ]
37
+
28
38
  def initialize (html)
29
39
  super(html)
40
+ @workingcopy = html.dup
30
41
  end
31
42
  #++
32
43
  #Call all necessary methods to convert a string of HTML into Textile markup.
33
44
 
34
45
  def to_textile
35
- html = self.dup
36
- FORMATTING_HTML.each do |htmltag, textiletag|
37
- html.gsub!(htmltag, textiletag)
46
+
47
+ headings(@workingcopy)
48
+ structure(@workingcopy)
49
+ text_formatting(@workingcopy)
50
+
51
+ @workingcopy
52
+
53
+ end
54
+
55
+ #--
56
+ #The conversion methods themselves are private.
57
+ private
58
+
59
+ def text_formatting(text)
60
+ TEXT_FORMATTING.each do |htmltag, textiletag|
61
+ text.gsub!(htmltag, textiletag)
38
62
  end
39
- html
63
+ text
40
64
  end
41
65
 
66
+
67
+ def headings(text)
68
+ HEADINGS.each do |htmltag, textiletag|
69
+ text.gsub!(htmltag, textiletag)
70
+ end
71
+ text
72
+ end
73
+
74
+
75
+ def structure(text)
76
+ STRUCTURES.each do |htmltag, textiletag|
77
+ text.gsub!(htmltag, textiletag)
78
+ end
79
+ text
80
+ end
81
+
82
+ def tables(text)
83
+ #TODO: Translate Tables
84
+ text
85
+ end
86
+
87
+
88
+ def css_styles(text)
89
+ #TODO: Translate CSS-styles
90
+ text
91
+ end
92
+ #++
42
93
  end
@@ -24,12 +24,12 @@ class TestClothRedFormatting < Test::Unit::TestCase
24
24
  ["<del>delete</del>", "-delete-"], ["<ins>underline</ins>", "+underline+"],
25
25
  ["<sup>superscript</sup>","^superscript^"], ["<sub>subscript</sub>","~subscript~"]
26
26
  ]
27
-
27
+
28
28
  def test_textformatting
29
29
  FORMATTING_STRINGS.each do |html, textile|
30
30
  test_html = ClothRed.new(html)
31
31
  result = test_html.to_textile
32
- assert_equal(textile,result.to_s)
32
+ assert_equal(textile,result)
33
33
  end
34
34
  end
35
35
 
@@ -0,0 +1,32 @@
1
+ # test_headings.rb
2
+ # 12. April 2007
3
+ #
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
6
+
7
+ begin
8
+ require "rubygems"
9
+ require "clothred"
10
+ rescue LoadError
11
+ require "clothred"
12
+ end
13
+
14
+ require 'test/unit'
15
+
16
+ class TestClothRedHeadings < Test::Unit::TestCase
17
+
18
+ HEADING_TEST = [
19
+ ["<h1>Heading 1</h1>","h1. Heading 1"], ["<h2>Heading 2</h2>", "h2. Heading 2"],
20
+ ["<h3>Heading 3", "h3. Heading 3"], ["<h4>Heading 4</h4>", "h4. Heading 4"],
21
+ ["<h5>Heading 5", "h5. Heading 5"], ["<h6>Heading 6</h6>", "h6. Heading 6"]
22
+ ]
23
+
24
+
25
+ def test_headings
26
+ HEADING_TEST.each do |html, textile|
27
+ test_html = ClothRed.new(html)
28
+ result = test_html.to_textile
29
+ assert_equal(textile,result)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ # test_structure.rb
2
+ # 12. April 2007
3
+ #
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
6
+
7
+ begin
8
+ require "rubygems"
9
+ require "clothred"
10
+ rescue LoadError
11
+ require "clothred"
12
+ end
13
+
14
+ require 'test/unit'
15
+
16
+ class TestClothRedStructures < Test::Unit::TestCase
17
+
18
+ STRUCTURE_TEST = [
19
+ ["<blockquote>blockquote</blockquote>","bq. blockquote"],
20
+ ["<p>paragraph</p><p>another paragraph</p>", "paragraph\n\nanother paragraph\n\n"]
21
+ ]
22
+
23
+
24
+ def test_structures
25
+ STRUCTURE_TEST.each do |html, textile|
26
+ test_html = ClothRed.new(html)
27
+ result = test_html.to_textile
28
+ assert_equal(textile,result)
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -3,14 +3,14 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: ClothRed
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-04-11 00:00:00 +02:00
6
+ version: 0.2.0
7
+ date: 2007-04-12 00:00:00 +02:00
8
8
  summary: "RedCloth in reverse: Converting HTML into Textile markup"
9
9
  require_paths:
10
10
  - lib
11
11
  email: cmdjackryan@gmail.com
12
12
  homepage:
13
- rubyforge_project:
13
+ rubyforge_project: clothred
14
14
  description:
15
15
  autorequire: clothred
16
16
  default_executable:
@@ -32,6 +32,8 @@ files:
32
32
  - lib/clothred.rb
33
33
  - lib/README.rdoc
34
34
  - test/test_formatting.rb
35
+ - test/test_headings.rb
36
+ - test/test_structure.rb
35
37
  - doc/html
36
38
  - doc/html/classes
37
39
  - doc/html/created.rid