facwparser 0.0.7 → 0.0.8

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.
@@ -122,7 +122,9 @@ module Facwparser
122
122
  "</table>\n"
123
123
  end
124
124
  end
125
- class TableHeaders < ElementBase
125
+ class TableRow < ElementBase
126
+ end
127
+ class TableHeaders < TableRow
126
128
  attr_reader :elements
127
129
  def initialize(source, value)
128
130
  super(source)
@@ -134,7 +136,7 @@ module Facwparser
134
136
  "</tr>"
135
137
  end
136
138
  end
137
- class TableData < ElementBase
139
+ class TableData < TableRow
138
140
  attr_reader :elements
139
141
  def initialize(source, value)
140
142
  super(source)
@@ -220,6 +222,11 @@ module Facwparser
220
222
  "</blockquote>\n"
221
223
  end
222
224
  end
225
+ class Nop < MacroBase
226
+ def render_html(options)
227
+ "\n"
228
+ end
229
+ end
223
230
 
224
231
  class InlineElementBase < ElementBase
225
232
  attr_reader :text
@@ -307,7 +314,7 @@ module Facwparser
307
314
  end
308
315
  def render_html(options)
309
316
  jira_browse_url = (options && options['jira_browse_url']) || ''
310
- return '<a href="' + CGI.escapeHTML(jira_browse_url + @options) +'">' + CGI.escapeHTML(@options) + '</a>'
317
+ render_html_by_name_and_value(['a', {'href' => jira_browse_url + @options}], @options)
311
318
  end
312
319
  end
313
320
 
@@ -7,18 +7,18 @@ require File.dirname(__FILE__) + '/element'
7
7
  module Facwparser
8
8
  module Parser
9
9
  def self.parse(content, options = {})
10
- elements = parse1(content, options)
10
+ elements = parse_block(content, options)
11
11
  process_elements(elements, options)
12
12
  end
13
13
 
14
14
  def self.process_elements(elements, options)
15
15
  processed = add_list_elements(elements, options)
16
16
  processed = add_table_elements(processed, options)
17
- processed = add_toc(processed, options)
17
+ processed = add_headings_to_toc(processed, options)
18
18
  processed
19
19
  end
20
20
 
21
- def self.add_toc(elements, options)
21
+ def self.add_headings_to_toc(elements, options)
22
22
  tocs = elements.select{ |e| e.class == Element::TocMacro}
23
23
  if !tocs.empty?
24
24
  headings = elements.select{ |e| e.class == Element::Heading && e.level == 1}
@@ -63,9 +63,8 @@ module Facwparser
63
63
  processed = []
64
64
  table = nil
65
65
  elements.each { |e|
66
- case
67
- when e.class == Element::TableHeaders || e.class == Element::TableData
68
- if e.class == Element::TableHeaders || !table
66
+ if e.is_a?(Element::TableRow)
67
+ if e.is_a?(Element::TableHeaders) || !table
69
68
  table = Element::Table.new
70
69
  processed << table
71
70
  end
@@ -78,7 +77,7 @@ module Facwparser
78
77
  processed
79
78
  end
80
79
 
81
- def self.parse1(content, options)
80
+ def self.parse_block(content, options)
82
81
  s = StringScanner.new(content.gsub("\r", '').gsub(/[\t\f]/, ' ') + "\n")
83
82
 
84
83
  elements = []
@@ -116,6 +115,7 @@ module Facwparser
116
115
  elements << Element::QuoteMacro.new(s[0], s[1])
117
116
  when s.scan(/ *\n/)
118
117
  p = nil
118
+ elements << Element::Nop.new(s[0])
119
119
  when s.scan(/(.+)\n/)
120
120
  if p
121
121
  p.append(s[0])
@@ -1,3 +1,3 @@
1
1
  module Facwparser
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
4
+
5
+
6
+ class TestJira < Test::Unit::TestCase
7
+
8
+ def test_toc_1
9
+ jira = Facwparser::Element::JiraMacro.new('{jira:TICKET-<}', 'TICKET-<')
10
+
11
+ assert_equal(%Q{<a href="TICKET-&lt;">TICKET-&lt;</a>},
12
+ jira.render_html({}))
13
+ assert_equal(%Q{<a href="http://jira/browse/TICKET-&lt;">TICKET-&lt;</a>},
14
+ jira.render_html({'jira_browse_url' => 'http://jira/browse/'}))
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ require 'test/unit'
4
+ require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
5
+
6
+ class TestNop < Test::Unit::TestCase
7
+
8
+ def test_nop_1
9
+ nop = Facwparser::Element::Nop.new("\n")
10
+ assert_equal(%Q{\n},
11
+ nop.render_html({}))
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../../../lib/facwparser/parser'
4
+
5
+
6
+ class TestAddHeadingsToToc < Test::Unit::TestCase
7
+
8
+ def test_add_headings_to_toc_1
9
+ toc = Facwparser::Element::TocMacro.new('{toc}');
10
+ pre = [
11
+ toc,
12
+ Facwparser::Element::Heading.new('h1. hoge', 1, 'hoge'),
13
+ Facwparser::Element::Heading.new('h2. hige', 2, 'hige'),
14
+ Facwparser::Element::Heading.new('h1. huge', 1, 'huge'),
15
+ ]
16
+ Facwparser::Parser.add_headings_to_toc(pre, {})
17
+ assert_equal([
18
+ Facwparser::Element::Heading.new('h1. hoge', 1, 'hoge'),
19
+ Facwparser::Element::Heading.new('h1. huge', 1, 'huge'),
20
+ ], toc.headings)
21
+
22
+ end
23
+
24
+ end
@@ -24,5 +24,23 @@ class TestAddListElements < Test::Unit::TestCase
24
24
 
25
25
  end
26
26
 
27
+ def test_add_list_elements_2
28
+ pre = [
29
+ Facwparser::Element::ListItem.new("* 4\n", '*', '4'),
30
+ Facwparser::Element::Nop.new("\n"),
31
+ Facwparser::Element::ListItem.new("* 5\n", '*', '5'),
32
+ ]
33
+
34
+ assert_equal([
35
+ Facwparser::Element::List.new('*').push(
36
+ Facwparser::Element::ListItem.new("* 4\n", '*', '4')),
37
+ Facwparser::Element::Nop.new("\n"),
38
+ Facwparser::Element::List.new('*').push(
39
+ Facwparser::Element::ListItem.new("* 5\n", '*', '5')),
40
+ ], Facwparser::Parser.add_list_elements(pre, {}))
41
+
42
+ end
43
+
44
+
27
45
  end
28
46
 
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../../../lib/facwparser/parser'
4
+
5
+
6
+ class TestAddTableElements < Test::Unit::TestCase
7
+
8
+ def test_add_table_elements_1
9
+ pre = [
10
+ Facwparser::Element::TableHeaders.new('||head1||head2||', '||head1||head2||'),
11
+ Facwparser::Element::TableData.new('|3|4|', '|3|4|' ),
12
+ Facwparser::Element::TableData.new('|5|6|', '|5|6|' ),
13
+ ]
14
+
15
+ assert_equal([
16
+ Facwparser::Element::Table.new.push(
17
+ Facwparser::Element::TableHeaders.new('||head1||head2||', '||head1||head2||' )).push(
18
+ Facwparser::Element::TableData.new('|3|4|', '|3|4|' )).push(
19
+ Facwparser::Element::TableData.new('|5|6|', '|5|6|' )),
20
+ ], Facwparser::Parser.add_table_elements(pre, {}))
21
+
22
+ end
23
+
24
+ def test_add_table_elements_2
25
+ pre = [
26
+ Facwparser::Element::TableHeaders.new('||head1||head2||', '||head1||head2||'),
27
+ Facwparser::Element::TableData.new('|3|4|', '|3|4|' ),
28
+ Facwparser::Element::TableData.new('|5|6|', '|5|6|' ),
29
+ Facwparser::Element::TableHeaders.new('||head1||head2||', '||head1||head2||'),
30
+ Facwparser::Element::TableData.new('|3|4|', '|3|4|' ),
31
+ Facwparser::Element::TableData.new('|5|6|', '|5|6|' ),
32
+ ]
33
+
34
+ assert_equal([
35
+ Facwparser::Element::Table.new.push(
36
+ Facwparser::Element::TableHeaders.new('||head1||head2||', '||head1||head2||' )).push(
37
+ Facwparser::Element::TableData.new('|3|4|', '|3|4|' )).push(
38
+ Facwparser::Element::TableData.new('|5|6|', '|5|6|' )),
39
+ Facwparser::Element::Table.new.push(
40
+ Facwparser::Element::TableHeaders.new('||head1||head2||', '||head1||head2||' )).push(
41
+ Facwparser::Element::TableData.new('|3|4|', '|3|4|' )).push(
42
+ Facwparser::Element::TableData.new('|5|6|', '|5|6|' )),
43
+ ], Facwparser::Parser.add_table_elements(pre, {}))
44
+
45
+ end
46
+
47
+ end
48
+
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../../lib/facwparser/parser'
5
5
 
6
6
  class TestParse1 < Test::Unit::TestCase
7
7
 
8
- def test_parse1_p
8
+ def test_parse_block_p
9
9
  source =<<EOS
10
10
  ほげ
11
11
 
@@ -17,14 +17,17 @@ EOS
17
17
  assert_equal(
18
18
  [
19
19
  Facwparser::Element::P.new("ほげ\n"),
20
+ Facwparser::Element::Nop.new("\n"),
20
21
  Facwparser::Element::P.new("ほげほげ\n"),
22
+ Facwparser::Element::Nop.new("\n"),
21
23
  Facwparser::Element::P.new("ほげほげげほ\nにゃ\n"),
24
+ Facwparser::Element::Nop.new("\n"),
22
25
  ],
23
- Facwparser::Parser.parse1(source, {}))
26
+ Facwparser::Parser.parse_block(source, {}))
24
27
 
25
28
  end
26
29
 
27
- def test_parse1_heading
30
+ def test_parse_block_heading
28
31
  source =<<EOS
29
32
  h1. ほげ
30
33
 
@@ -35,15 +38,17 @@ EOS
35
38
  assert_equal(
36
39
  [
37
40
  Facwparser::Element::Heading.new("h1. ほげ\n", 1, "ほげ"),
41
+ Facwparser::Element::Nop.new("\n"),
38
42
  Facwparser::Element::P.new("ほげほげ\n"),
39
43
  Facwparser::Element::Heading.new("h3. ほげほげげほ\n", 3, "ほげほげげほ"),
40
44
  Facwparser::Element::P.new("にゃ\n"),
45
+ Facwparser::Element::Nop.new("\n"),
41
46
  ],
42
- Facwparser::Parser.parse1(source, {}))
47
+ Facwparser::Parser.parse_block(source, {}))
43
48
 
44
49
  end
45
50
 
46
- def test_parse1_horizontal_rule
51
+ def test_parse_block_horizontal_rule
47
52
  source =<<EOS
48
53
  1
49
54
  ----
@@ -59,14 +64,16 @@ EOS
59
64
  Facwparser::Element::P.new("1\n"),
60
65
  Facwparser::Element::HorizontalRule.new("----\n"),
61
66
  Facwparser::Element::P.new("2\n---\n3\n"),
67
+ Facwparser::Element::Nop.new("\n"),
62
68
  Facwparser::Element::HorizontalRule.new("-----\n"),
63
69
  Facwparser::Element::P.new("4\n"),
70
+ Facwparser::Element::Nop.new("\n"),
64
71
  ],
65
- Facwparser::Parser.parse1(source, {}))
72
+ Facwparser::Parser.parse_block(source, {}))
66
73
 
67
74
  end
68
75
 
69
- def test_parse1_list_item
76
+ def test_parse_block_list_item
70
77
  source =<<EOS
71
78
  1
72
79
  - 2
@@ -83,12 +90,13 @@ EOS
83
90
  Facwparser::Element::ListItem.new("** 4\n", '**', '4'),
84
91
  Facwparser::Element::ListItem.new("### 5\n", '###', '5'),
85
92
  Facwparser::Element::ListItem.new("#*#* 6\n", '#*#*', '6'),
93
+ Facwparser::Element::Nop.new("\n"),
86
94
  ],
87
- Facwparser::Parser.parse1(source, {}))
95
+ Facwparser::Parser.parse_block(source, {}))
88
96
 
89
97
  end
90
98
 
91
- def test_parse1_table
99
+ def test_parse_block_table
92
100
  source =<<EOS
93
101
  1
94
102
  ||2||3||
@@ -101,12 +109,13 @@ EOS
101
109
  Facwparser::Element::TableHeaders.new("||2||3||\n", '||2||3||'),
102
110
  Facwparser::Element::TableData.new("|4|5|\n", '|4|5|'),
103
111
  Facwparser::Element::P.new("6\n"),
112
+ Facwparser::Element::Nop.new("\n"),
104
113
  ],
105
- Facwparser::Parser.parse1(source, {}))
114
+ Facwparser::Parser.parse_block(source, {}))
106
115
 
107
116
  end
108
117
 
109
- def test_parse1_toc_1
118
+ def test_parse_block_toc_1
110
119
  source =<<EOS
111
120
  1
112
121
  {toc}
@@ -117,12 +126,13 @@ EOS
117
126
  Facwparser::Element::P.new("1\n"),
118
127
  Facwparser::Element::TocMacro.new("{toc}\n"),
119
128
  Facwparser::Element::P.new("2\n"),
129
+ Facwparser::Element::Nop.new("\n"),
120
130
  ],
121
- Facwparser::Parser.parse1(source, {}))
131
+ Facwparser::Parser.parse_block(source, {}))
122
132
 
123
133
  end
124
134
 
125
- def test_parse1_toc_2
135
+ def test_parse_block_toc_2
126
136
  source =<<EOS
127
137
  1
128
138
  {toc:maxLevel=3}
@@ -133,12 +143,13 @@ EOS
133
143
  Facwparser::Element::P.new("1\n"),
134
144
  Facwparser::Element::TocMacro.new("{toc:maxLevel=3}\n", 'maxLevel=3'),
135
145
  Facwparser::Element::P.new("2\n"),
146
+ Facwparser::Element::Nop.new("\n"),
136
147
  ],
137
- Facwparser::Parser.parse1(source, {}))
148
+ Facwparser::Parser.parse_block(source, {}))
138
149
 
139
150
  end
140
151
 
141
- def test_parse1_noformat
152
+ def test_parse_block_noformat
142
153
  source =<<EOS
143
154
  1
144
155
  {noformat}
@@ -152,12 +163,13 @@ EOS
152
163
  Facwparser::Element::P.new("1\n"),
153
164
  Facwparser::Element::NoformatMacro.new("{noformat}\n2\n3\n{noformat}\n", "2\n3\n"),
154
165
  Facwparser::Element::P.new("4\n"),
166
+ Facwparser::Element::Nop.new("\n"),
155
167
  ],
156
- Facwparser::Parser.parse1(source, {}))
168
+ Facwparser::Parser.parse_block(source, {}))
157
169
 
158
170
  end
159
171
 
160
- def test_parse1_code
172
+ def test_parse_block_code
161
173
  source =<<EOS
162
174
  1
163
175
  {code:ruby}
@@ -171,12 +183,13 @@ EOS
171
183
  Facwparser::Element::P.new("1\n"),
172
184
  Facwparser::Element::CodeMacro.new("{code:ruby}\na = 1 + 2\n3\n{code}\n", 'ruby', "a = 1 + 2\n3\n"),
173
185
  Facwparser::Element::P.new("4\n"),
186
+ Facwparser::Element::Nop.new("\n"),
174
187
  ],
175
- Facwparser::Parser.parse1(source, {}))
188
+ Facwparser::Parser.parse_block(source, {}))
176
189
 
177
190
  end
178
191
 
179
- def test_parse1_quote
192
+ def test_parse_block_quote
180
193
  source =<<EOS
181
194
  1
182
195
  {quote}
@@ -190,8 +203,9 @@ EOS
190
203
  Facwparser::Element::P.new("1\n"),
191
204
  Facwparser::Element::QuoteMacro.new("{quote}\n2\n3\n{quote}\n", "2\n3\n"),
192
205
  Facwparser::Element::P.new("4\n"),
206
+ Facwparser::Element::Nop.new("\n"),
193
207
  ],
194
- Facwparser::Parser.parse1(source, {}))
208
+ Facwparser::Parser.parse_block(source, {}))
195
209
 
196
210
  end
197
211
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facwparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-26 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Fuxxing Atlassian Confluence Wiki Parser
15
15
  email:
@@ -39,10 +39,12 @@ files:
39
39
  - tests/units/element/test_emphasis.rb
40
40
  - tests/units/element/test_heading.rb
41
41
  - tests/units/element/test_horizontal_rule.rb
42
+ - tests/units/element/test_jira.rb
42
43
  - tests/units/element/test_list.rb
43
44
  - tests/units/element/test_list_item.rb
44
45
  - tests/units/element/test_monospace.rb
45
46
  - tests/units/element/test_noformat.rb
47
+ - tests/units/element/test_nop.rb
46
48
  - tests/units/element/test_p.rb
47
49
  - tests/units/element/test_q.rb
48
50
  - tests/units/element/test_quote.rb
@@ -56,8 +58,10 @@ files:
56
58
  - tests/units/element/test_text.rb
57
59
  - tests/units/element/test_toc.rb
58
60
  - tests/units/element/test_under.rb
61
+ - tests/units/parser/test_add_headings_to_toc.rb
59
62
  - tests/units/parser/test_add_list_elements.rb
60
- - tests/units/parser/test_parse1.rb
63
+ - tests/units/parser/test_add_table_elements.rb
64
+ - tests/units/parser/test_parse_block.rb
61
65
  - tests/units/parser/test_parse_value.rb
62
66
  homepage: https://github.com/haruyama/facwparser
63
67
  licenses: []