pink_shirt 0.0.5 → 0.0.6

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/changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.0.6
2
+ - tables are always explicit
3
+ - vertical-align by symbol
1
4
  0.0.5
2
5
  - MIT licence.
3
6
  0.0.4
@@ -1,16 +1,16 @@
1
1
  class PinkShirt
2
2
  # = Attributes
3
- #
3
+ #
4
4
  # the sax parser passes an array of attributes along with each tag
5
5
  # attrs = ['href', 'http://www.example.com', 'style', 'background-color: snake;']
6
6
  #
7
7
  # Textile displays attributes in a certain way
8
- #
8
+ #
9
9
  # = USAGE
10
- #
10
+ #
11
11
  # Attributes.new(attrs).write
12
12
  #
13
- #
13
+ #
14
14
  # * colspan=2 => \2
15
15
  # * rowspan=3 => /3
16
16
  # * style='padding-left:1em' => (
@@ -19,6 +19,9 @@ class PinkShirt
19
19
  # * style='text-align:left' => <
20
20
  # * style='text-align:center' => =
21
21
  # * style='text-align:justify'=> <>
22
+ # * style='vertical-align:top' => ^
23
+ # * style='vertical-align:center' => -
24
+ # * style='vertical-align:bottom' => ~
22
25
  # * class = 'panthers' => (panthers)
23
26
  # * id = 'banner' => (#banner)
24
27
  # * class='this' id='that' => (this#that)
@@ -28,13 +31,14 @@ class PinkShirt
28
31
  #
29
32
  class Attributes
30
33
  # @param attrs [Array] formatted [key, value, key, value]
31
- #
34
+ #
32
35
  def initialize(attrs)
33
36
  @attrs = attrs
34
37
  @attrs_hash = Hash[attrs]
35
38
  @styles_hash = parse_styles
36
39
  @nudges = steal_nudges
37
40
  @padding = steal_padding
41
+ @vertical = steal_vertical
38
42
  end
39
43
 
40
44
  def attrs
@@ -50,19 +54,20 @@ class PinkShirt
50
54
  add << colspan
51
55
  add << rowspan
52
56
  add << nudges
57
+ add << vertical
53
58
  add << padding
54
59
  add << klass_and_id
55
60
  add << style
56
61
  add << lang
57
62
  out = add.join
58
63
  return nil if out == ""
59
-
64
+
60
65
  out
61
66
  end
62
67
 
63
68
  def parse_styles
64
69
  return nil unless attrs['style']
65
-
70
+
66
71
  rules_list = attrs['style'].split(";").map{|rule|
67
72
  rule.split(":")
68
73
  }
@@ -96,7 +101,7 @@ class PinkShirt
96
101
 
97
102
  def steal_padding
98
103
  return nil unless attrs['style']
99
-
104
+
100
105
  left = case styles.delete('padding-left')
101
106
  when '1em'; "(" ;
102
107
  when '2em'; "((";
@@ -114,9 +119,20 @@ class PinkShirt
114
119
  padding = "#{left}#{right}"
115
120
  end
116
121
 
122
+ def steal_vertical
123
+ return nil unless attrs['style']
124
+
125
+ vertical = case styles.delete('vertical-align')
126
+ when 'top'; "^";
127
+ when 'middle'; "-";
128
+ when 'bottom'; "~";
129
+ end
130
+ vertical
131
+ end
132
+
117
133
  def colspan
118
134
  return nil unless attrs['colspan']
119
-
135
+
120
136
  width = attrs['colspan']
121
137
  colspan = ""
122
138
  colspan << "\\" #literal backslash
@@ -126,7 +142,7 @@ class PinkShirt
126
142
 
127
143
  def rowspan
128
144
  return nil unless attrs['rowspan']
129
-
145
+
130
146
  height = attrs['rowspan']
131
147
  colspan = '/' + "#{height}" if height
132
148
  end
@@ -139,12 +155,16 @@ class PinkShirt
139
155
  @padding
140
156
  end
141
157
 
158
+ def vertical
159
+ @vertical
160
+ end
161
+
142
162
 
143
163
  def klass_and_id
144
164
  klass = attrs['class']
145
165
  id = attrs['id']
146
166
  return nil unless klass || id
147
-
167
+
148
168
  output = ""
149
169
  output += "("
150
170
  output += klass if klass
@@ -163,7 +183,7 @@ class PinkShirt
163
183
 
164
184
  def lang
165
185
  return nil unless attrs.include?('lang')
166
-
186
+
167
187
  output = ""
168
188
  output += "["
169
189
  output += attrs['lang']
@@ -3,9 +3,10 @@ class PinkShirt
3
3
  TAGS = %w(table th tr td tbody thead)
4
4
 
5
5
  def start_table attrs
6
- if add_attributes(attrs)
7
- @output << "table#{add_attributes(attrs)}.\n"
8
- end
6
+ @output << "\n"
7
+ # if add_attributes(attrs)
8
+ @output << "table#{add_attributes(attrs)}.\n"
9
+ # end
9
10
  end
10
11
 
11
12
  def end_table
@@ -48,4 +49,4 @@ class PinkShirt
48
49
  def end_td
49
50
  end
50
51
  end
51
- end
52
+ end
@@ -1,3 +1,3 @@
1
1
  class PinkShirt
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -6,7 +6,7 @@ describe 'PinkShirt against redcloth in reality' do
6
6
 
7
7
  examples.each do |heading, example|
8
8
  it "#{heading} #{example['desc']}" do
9
- html = RedCloth.new(example['textile']).to_html.chomp
9
+ html = RedCloth.new(example['textile']).to_html.chomp
10
10
  decoded = PinkShirt.new(html).to_textile.to_s.chomp.chomp
11
11
  actual = example['textile']
12
12
  decoded.should == actual
@@ -14,3 +14,17 @@ describe 'PinkShirt against redcloth in reality' do
14
14
  end
15
15
 
16
16
  end
17
+
18
+ describe 'PinkShirt against Expectations in reality' do
19
+
20
+ examples = YAML::load(File.read('./spec/examples/basics.yaml'))
21
+ it "Spaces around fonty markup" do
22
+ example = examples['Spaces Around fonty Markups']
23
+ puts example
24
+ html = example['html']
25
+ decoded = PinkShirt.new(html).to_textile.to_s.chomp.chomp
26
+ actual = example['textile']
27
+ decoded.should == actual
28
+ end
29
+
30
+ end
@@ -38,10 +38,10 @@ OL Lists:
38
38
  Fonty Markup:
39
39
  desc: bold italic and the rest
40
40
  textile: |-
41
- *b*
41
+ **b**
42
42
  *strong*
43
43
  ??cite??
44
- _i_
44
+ __i__
45
45
  _em_
46
46
  -del-
47
47
  +ins+
@@ -50,10 +50,10 @@ Fonty Markup:
50
50
  %span%
51
51
  @code@
52
52
  html: |-
53
- <strong>b</strong><br />
53
+ <b>b</b><br />
54
54
  <strong>strong</strong><br />
55
55
  <cite>cite</cite><br />
56
- <em>i</em><br />
56
+ <i>i</i><br />
57
57
  <em>em</em><br />
58
58
  <del>del</del><br />
59
59
  <ins>ins</ins><br />
@@ -61,7 +61,12 @@ Fonty Markup:
61
61
  <sup>sup</sup><br />
62
62
  <span>span</span><br />
63
63
  <code>code</code>
64
-
64
+ Spaces Around fonty Markups:
65
+ desc: bold italic and the rest need room to breathe
66
+ textile: |-
67
+ **b** *strong* ??cite?? __i__ _em_ -del- +ins+ ~sub~ ^sup^ %span% @code@
68
+ html: |-
69
+ <b>b</b><strong>strong</strong><cite>cite</cite><i>i</i><em>em</em><del>del</del><ins>ins</ins><sub>sub</sub><sup>sup</sup><span>span</span><code>code</code>
65
70
  Nested Lists:
66
71
  desc: list nesting is hard
67
72
  textile: |-
@@ -109,6 +114,8 @@ Nested Mixed Lists:
109
114
  Tables:
110
115
  desc: plain Tables
111
116
  textile: |-
117
+
118
+ table.
112
119
  |a|table|row|
113
120
  |a|table|row|
114
121
  html: |-
@@ -125,9 +132,40 @@ Tables:
125
132
  </tr>
126
133
  </table>
127
134
 
135
+ Tables with vertical alignment:
136
+ desc: plain Tables
137
+ textile: |-
138
+
139
+ table.
140
+ |^. a|table|row|
141
+ |-. a|table|row|
142
+ |~. a|table|row|
143
+
144
+ html: |-
145
+ <table>
146
+ <tr>
147
+ <td style='verical-align:top;'>a</td>
148
+ <td>table</td>
149
+ <td>row</td>
150
+ </tr>
151
+ <tr>
152
+ <td style='verical-align:middle;'>a</td>
153
+ <td>table</td>
154
+ <td>row</td>
155
+ </tr>
156
+ <tr>
157
+ <td style='verical-align:bottom;'>a</td>
158
+ <td>table</td>
159
+ <td>row</td>
160
+ </tr>
161
+
162
+ </table>
163
+
128
164
  Tables With headers:
129
165
  desc: a table with a header
130
166
  textile: |-
167
+
168
+ table.
131
169
  |_. a|_. table|_. header|
132
170
  |a|table|row|
133
171
  |a|table|row|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pink_shirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000 Z
12
+ date: 2012-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: RedCloth
16
- requirement: &70259168798420 !ruby/object:Gem::Requirement
16
+ requirement: &70364991723920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70259168798420
24
+ version_requirements: *70364991723920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70259168797920 !ruby/object:Gem::Requirement
27
+ requirement: &70364991723500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70259168797920
35
+ version_requirements: *70364991723500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70259168797460 !ruby/object:Gem::Requirement
38
+ requirement: &70364991723080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70259168797460
46
+ version_requirements: *70364991723080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
- requirement: &70259168797000 !ruby/object:Gem::Requirement
49
+ requirement: &70364991722660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70259168797000
57
+ version_requirements: *70364991722660
58
58
  description: Converts Html to Textile, or as some say 'html2textile', it's built on
59
59
  nokogiri
60
60
  email: