docgenerator 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/creole_example_tabular.rb +95 -0
- data/examples/docgenerator_example.rb +5 -5
- data/lib/creole/creole2doc.rb +28 -18
- data/lib/creole/creole_inclusions.rb +4 -4
- data/lib/creole/creole_placeholder.rb +4 -1
- data/lib/creole/creole_tabular.rb +173 -155
- data/lib/creole/plugins/rail.rb +118 -119
- data/lib/creole/plugins/struktex.rb +35 -35
- data/lib/creole/plugins/todonotes.rb +8 -1
- data/lib/docgenerator/attribute.rb +160 -160
- data/lib/docgenerator/characters.rb +343 -311
- data/lib/docgenerator/css.rb +167 -167
- data/lib/docgenerator/document.rb +525 -511
- data/lib/docgenerator/element.rb +316 -316
- data/lib/docgenerator/element_meta.rb +114 -114
- data/lib/docgenerator/elements.rb +19 -9
- data/lib/docgenerator/environments.rb +3 -1
- data/lib/docgenerator/lists.rb +177 -174
- data/lib/docgenerator/packages/hyperref.rb +74 -70
- data/lib/docgenerator/packages/multicol.rb +33 -0
- data/lib/docgenerator/packages/scrlettr2.rb +152 -151
- data/lib/docgenerator/packages/todonotes.rb +1 -1
- data/lib/docgenerator/tabular.rb +463 -400
- data/lib/docgenerator/templates/docgenerator_template.rb +94 -84
- data/lib/docgenerator/templates/docgenerator_template.yaml +75 -15
- data/lib/docgenerator.rb +1 -1
- data/lib/wiki2doc/wiki2docgenerator.rb +1 -1
- data/meta_test_and_doc/build__meta.rb +125 -0
- data/meta_test_and_doc/build_doc.rb +333 -0
- data/meta_test_and_doc/build_test.rb +251 -0
- data/meta_test_and_doc/manpages/attachfile.rb +389 -0
- data/meta_test_and_doc/manpages/caption.rb +133 -0
- data/meta_test_and_doc/manpages/characters.rb +3738 -0
- data/meta_test_and_doc/manpages/elements.rb +6851 -0
- data/meta_test_and_doc/manpages/environments.rb +985 -0
- data/meta_test_and_doc/manpages/footnote.rb +439 -0
- data/meta_test_and_doc/manpages/hyperref.rb +605 -0
- data/meta_test_and_doc/manpages/listings.rb +988 -0
- data/meta_test_and_doc/manpages/lists.rb +1463 -0
- data/meta_test_and_doc/manpages/others.rb +129 -0
- data/meta_test_and_doc/manpages/packages.rb +13 -0
- data/meta_test_and_doc/manpages/pdfpages.rb +108 -0
- data/meta_test_and_doc/manpages/readme.rdoc +9 -0
- data/meta_test_and_doc/manpages/scrlettr2.rb +362 -0
- data/meta_test_and_doc/manpages/scrpage2.rb +2028 -0
- data/meta_test_and_doc/manpages/sectioning.rb +2467 -0
- data/meta_test_and_doc/manpages/tables.rb +2088 -0
- data/meta_test_and_doc/manpages/todonotes.rb +235 -0
- data/meta_test_and_doc/manpages/wiki2docgenerator.rb +64 -0
- data/{readme.rd → readme.rdoc} +18 -1
- data/unittest/expected/test_tabular.creole +33 -0
- data/unittest/expected_creole/test_creole_creole1.0test.html +3 -3
- data/unittest/expected_creole/test_creole_creole1.0test.latex +3 -3
- data/unittest/expected_creole/test_creole_creole1.0test.text +3 -3
- data/unittest/expected_creole/test_creole_inline_apostroph.html +6 -0
- data/unittest/expected_creole/test_creole_inline_apostroph.latex +8 -0
- data/unittest/expected_creole/test_creole_inline_apostroph.text +4 -0
- data/unittest/expected_creole/test_creole_input.normsource +12 -12
- data/unittest/expected_creole/test_creole_input.normsource_1.8 +23 -0
- data/unittest/expected_creole/test_creole_links_external_implicit.html +2 -2
- data/unittest/expected_creole/test_creole_links_external_implicit.latex +2 -2
- data/unittest/expected_creole/test_creole_links_external_implicit.text +2 -2
- data/unittest/expected_creole/test_creole_links_implicit_end.html +1 -1
- data/unittest/expected_creole/test_creole_links_implicit_end.latex +1 -1
- data/unittest/expected_creole/test_creole_list_ul.normsource +42 -42
- data/unittest/expected_creole/test_creole_list_ul.normsource_1.8 +83 -0
- data/unittest/expected_creole/test_creole_paragraphs.normsource +15 -15
- data/unittest/expected_creole/test_creole_paragraphs.normsource_1.8 +27 -0
- data/unittest/expected_creole/test_creole_tabular.creole +22 -0
- data/unittest/expected_creole/test_creole_tabular_creole.creole +19 -0
- data/unittest/expected_creole/test_creole_tabular_css.creole +24 -0
- data/unittest/expected_creole/test_creole_tabular_multicols.creole +16 -0
- data/unittest/expected_creole/test_creole_tabular_multicols.html +14 -0
- data/unittest/expected_creole/test_creole_tabular_multicols.latex +16 -0
- data/unittest/expected_creole/test_creole_tabular_with_cell_option.creole +21 -0
- data/unittest/expected_creole/test_creole_toc_level_text.html +2 -2
- data/unittest/expected_creole/test_creole_toc_level_text.latex +2 -2
- data/unittest/expected_packages/test_multicol_3.tex +2 -0
- data/unittest/expected_packages/test_multicol_3_titleline.tex +2 -0
- data/unittest/expected_templates/test_article.tex +23 -0
- data/unittest/expected_templates/test_article_utf8.tex +34 -0
- data/unittest/expected_templates/test_context.miv +18 -0
- data/unittest/expected_templates/test_creole.creole +8 -0
- data/unittest/expected_templates/test_html.html +12 -0
- data/unittest/expected_templates/test_html401_strict.html +14 -0
- data/unittest/expected_templates/test_html401_trans.html +14 -0
- data/unittest/expected_templates/test_html_utf8.html +14 -0
- data/unittest/expected_templates/test_include.tex +17 -0
- data/unittest/expected_templates/test_include_utf8.tex +17 -0
- data/unittest/expected_templates/test_text.txt +6 -0
- data/unittest/expected_templates/test_wiki.wiki +6 -0
- data/unittest/expected_templates/test_xhtml_strict.html +14 -0
- data/unittest/expected_templates/test_xhtml_trans.html +14 -0
- data/unittest/unittest_creole.rb +27 -6
- data/unittest/unittest_creole_placeholders.rb +1 -123
- data/unittest/unittest_creole_tabular.rb +174 -0
- data/unittest/unittest_docgenerator.rb +4 -3
- data/unittest/unittest_docgenerator_characters.rb +4769 -615
- data/unittest/unittest_packages_multicol.rb +84 -0
- data/unittest/unittest_rubycode4doc.rb +0 -1
- data/unittest/unittest_templates.rb +64 -0
- metadata +163 -77
- data/build_test_and_doc.rb +0 -505
- data/manpage_elements.rb +0 -10411
data/lib/docgenerator/tabular.rb
CHANGED
@@ -1,33 +1,29 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
=begin rdoc
|
3
|
-
Definition of tabular elements for
|
3
|
+
Definition of tabular elements for docgenerator-gem.
|
4
4
|
=end
|
5
5
|
|
6
6
|
#
|
7
7
|
module Docgenerator
|
8
8
|
=begin rdoc
|
9
|
-
Definition of tabular elements for
|
9
|
+
Definition of tabular elements for docgenerator-gem.
|
10
10
|
=end
|
11
|
-
module Tables
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#Define some constants to include packages into document header.
|
17
|
-
TEX_PACKAGE_TABULARX = element(:usepackage,{},'tabularx').cr
|
18
|
-
TEX_PACKAGE_LONGTABLE= element(:usepackage,{},'longtable').cr
|
19
|
-
TEX_PACKAGE_BOOKTABS = element(:usepackage,{},'booktabs').cr
|
11
|
+
module Tables
|
12
|
+
#Define some constants to include packages into document header.
|
13
|
+
TEX_PACKAGE_TABULARX = element(:usepackage,{},'tabularx').cr
|
14
|
+
TEX_PACKAGE_LONGTABLE= element(:usepackage,{},'longtable').cr
|
15
|
+
TEX_PACKAGE_BOOKTABS = element(:usepackage,{},'booktabs').cr
|
20
16
|
|
21
17
|
=begin rdoc
|
22
18
|
Environment Table
|
23
19
|
=end
|
24
|
-
class Table < Environments::Environment
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
20
|
+
class Table < Environments::Environment
|
21
|
+
add_attributes HTML_ATTR_ALL
|
22
|
+
add_html_tag 'div'
|
23
|
+
def to_latex( options={} )
|
24
|
+
return to_latex_environment( 'table', nil, options )
|
25
|
+
end
|
26
|
+
end
|
31
27
|
=begin rdoc
|
32
28
|
Tabulars
|
33
29
|
|
@@ -35,88 +31,108 @@ fixme: check on attributes. columnsdescription
|
|
35
31
|
~ :table=> {:border=>nil, :width=>nil, :cellpadding=>nil, :cellspacing=>nil},#complete it
|
36
32
|
~ :colgroup => {}, #comlpete it
|
37
33
|
=end
|
38
|
-
class Tabular < Element
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
34
|
+
class Tabular < Element
|
35
|
+
add_attributes HTML_ATTR_ALL
|
36
|
+
#Problem: Nicht weitervererbt
|
37
|
+
add_attribute :columndescription , Attribute.create( [:latex, :required ] )
|
38
|
+
add_attribute :columns , Attribute.create( [:required], [ Fixnum ] )
|
39
|
+
add_attribute :border , Attribute.create( [:html] )
|
40
|
+
add_attribute :bgcolor , Attribute.create( [ :html ] )
|
41
|
+
add_attribute :width , Attribute.create( [ :html ], [ Integer, String ] ) #String necessary for percentage
|
42
|
+
add_attribute :frame , Attribute.create( [ :html ], [ 'box', 'above', 'below', 'hsides', 'vsides', 'lhs', 'rhs' ] )
|
43
|
+
add_attribute :rules , Attribute.create( [ :html ], [ 'none', 'rows', 'cols', 'groups', 'all' ] )
|
44
|
+
add_attribute :height , Attribute.create( [ :html ], [ Integer ] )
|
45
|
+
add_attribute :cellspacing , Attribute.create( [ :html ], [ Integer ] )
|
46
|
+
add_attribute :cellpadding , Attribute.create( [ :html ], [ Integer ] )
|
47
|
+
add_attribute :summary , Attribute.create( [:html] )
|
48
|
+
add_attribute :align , HTML_ATTR_ALIGN
|
49
|
+
=begin rdoc
|
50
|
+
* Only rows are allowed to be added.
|
51
|
+
* The row gets the number of columns (attr[:columns])
|
52
|
+
* The row counting does not work, when the row-content is added immediate during element-initialization.
|
53
|
+
=end
|
54
|
+
def << ( row )
|
55
|
+
#Check on allowed elements for a tabular
|
56
|
+
allowed = false
|
57
|
+
[ :row, :hline, :toprule, :midrule, :bottomrule, :endfirsthead , :endhead , :endfoot, :endlastfoot,
|
58
|
+
:caption ].each{|el|
|
59
|
+
if row.is_a?( Element.get(el) )
|
60
|
+
allowed = true
|
61
|
+
break
|
62
|
+
end
|
63
|
+
}
|
64
|
+
if ! allowed
|
65
|
+
@log.warn("Add non-row to tabular (#{row.class})") if @log.warn?
|
66
|
+
end
|
67
|
+
#Add number of expected columns
|
68
|
+
if row.is_a?( Row )
|
69
|
+
row.columns = @attr[:columns].to_s.to_i
|
70
|
+
end
|
71
|
+
@content << row
|
72
|
+
end
|
73
|
+
def to_latex(options={})
|
74
|
+
o = set_option_defaults(options)
|
75
|
+
o[:log].debug("enter to_latex for tabular") if o[:log].debug?
|
76
|
+
cmd = ''
|
77
|
+
cmd << "\n" if @crbefore
|
78
|
+
cmd << "\\begin{tabular}{"
|
79
|
+
cmd << @attr[:columndescription].content.to_doc(:latex, o)
|
80
|
+
cmd << "}"
|
81
|
+
cmd << "\n" if @crmid
|
82
|
+
cmd << @content.to_doc(:latex, o )
|
83
|
+
cmd << "\\end{tabular}"
|
84
|
+
cmd << "\n" if @crafter
|
85
|
+
return cmd
|
86
|
+
end
|
87
|
+
def to_text(options={}); return @content.to_text(options); end
|
88
|
+
def to_wiki(options={}); return "{|\n#{@content.to_wiki(options).strip}\n|}\n"; end
|
89
|
+
=begin rdoc
|
90
|
+
Output a complete tabular in wikimedia-like tabular extension for creole.
|
91
|
+
=end
|
92
|
+
def to_creole(options={});
|
93
|
+
creole = ''
|
94
|
+
creole << "<<<tabular\n"
|
95
|
+
creole << "|!columns=#{@attr[:columns].content.first}\n" if @attr[:columns].filled?
|
96
|
+
creole << "|!columndescription=%s\n" % @attr[:columndescription].content if @attr[:columndescription].filled?
|
97
|
+
#Add css-components
|
98
|
+
@attr[:style].content.first.to_tab.each{|css| #loop on Docgenerator::CSS
|
99
|
+
creole << "|!css=%s\n" % css
|
100
|
+
} if @attr[:style].filled?
|
101
|
+
creole << "#{@content.to_creole(options).strip}\n"
|
102
|
+
creole << ">>>\n"
|
103
|
+
return creole
|
104
|
+
end
|
105
|
+
def htmltag()
|
106
|
+
return 'table'
|
107
|
+
end
|
108
|
+
def inspect()
|
109
|
+
return "<Class Element(tabular) columns=#{@attr[:columns]}>"
|
110
|
+
end
|
111
|
+
end #class Tabular
|
112
|
+
|
97
113
|
=begin rdoc
|
98
114
|
Use longtable-package.
|
99
115
|
|
100
116
|
Requires
|
101
117
|
doc.head << element(:usepackage,{},'longtable')
|
102
118
|
=end
|
103
|
-
class Longtable < Tabular
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
119
|
+
class Longtable < Tabular
|
120
|
+
add_attributes Tabular.get_attribute_list( )
|
121
|
+
def to_latex(options={})
|
122
|
+
o = set_option_defaults(options)
|
123
|
+
o[:log].debug("enter to_latex for longtable") if o[:log].debug?
|
124
|
+
cmd = ''
|
125
|
+
cmd << "\n" if @crbefore
|
126
|
+
cmd << "\\begin{longtable}{"
|
127
|
+
cmd << @attr[:columndescription].content.to_doc(:latex, o)
|
128
|
+
cmd << "}"
|
129
|
+
cmd << "\n" if @crmid
|
130
|
+
cmd << @content.to_latex(o)
|
131
|
+
cmd << "\\end{longtable}"
|
132
|
+
cmd << "\n" if @crafter
|
133
|
+
return cmd
|
134
|
+
end
|
135
|
+
end #class Longtable
|
120
136
|
=begin rdoc
|
121
137
|
Use Tabularx-package.
|
122
138
|
|
@@ -125,194 +141,195 @@ Requires
|
|
125
141
|
|
126
142
|
fixme :width is obligatory
|
127
143
|
=end
|
128
|
-
class Tabularx < Tabular
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
144
|
+
class Tabularx < Tabular
|
145
|
+
#
|
146
|
+
add_attributes Tabular.get_attribute_list( )
|
147
|
+
def to_latex(options={})
|
148
|
+
o = set_option_defaults(options)
|
149
|
+
o[:log].debug("enter to_latex for tabularx") if o[:log].debug?
|
150
|
+
if @attr[:width].content.to_s == ''
|
151
|
+
o[:log].error( "Tabularx: Empty width, set it to \\textwidth" ) if o[:log].error?
|
152
|
+
@attr[:width] << '\\textwidth'
|
153
|
+
end
|
154
|
+
cmd = ''
|
155
|
+
cmd << "\n" if @crbefore
|
156
|
+
cmd << "\\begin{tabularx}{"
|
157
|
+
cmd << @attr[:width].content.to_s
|
158
|
+
cmd << "}{"
|
159
|
+
cmd << @attr[:columndescription].content.to_s
|
160
|
+
cmd << "}"
|
161
|
+
cmd << "\n" if @crmid
|
162
|
+
cmd << @content.to_doc(:latex, o )
|
163
|
+
cmd << "\\end{tabularx}"
|
164
|
+
cmd << "\n" if @crafter
|
165
|
+
return cmd
|
166
|
+
end
|
167
|
+
end #class Tabularx
|
152
168
|
=begin rdoc
|
153
169
|
May only be used insode a tabular. Tabular must set the columns-value.
|
154
170
|
|
155
171
|
If not, zero columns is expected and an error is thrown.
|
156
172
|
=end
|
157
|
-
class Row < Element
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
173
|
+
class Row < Element
|
174
|
+
add_id :tr
|
175
|
+
#~ :tr => {:align=>align},#complete it
|
176
|
+
add_attributes( {
|
177
|
+
:add_vspace => Attribute.create( [:latex] ) ,
|
178
|
+
:bgcolor => Attribute.create( [ :html ] ),
|
179
|
+
:width => Attribute.create( [ :html ] ),
|
180
|
+
:height => Attribute.create( [ :html ] ),
|
181
|
+
#fixme
|
182
|
+
#~ :hline => Attribute.create( [:latex], [true, false] ) ,
|
183
|
+
}.update(HTML_ATTR_ALL) )
|
184
|
+
def initialize( attr={}, content = nil)
|
185
|
+
super
|
186
|
+
#For Ruby 1.9: Initialize instance variable
|
187
|
+
@toprule = false
|
188
|
+
@midrule = false
|
189
|
+
@bottomrule = false
|
190
|
+
@endfirsthead = false
|
191
|
+
@endhead = false
|
192
|
+
@endfoot = false
|
193
|
+
@endlastfoot = false
|
194
|
+
@cline = false
|
195
|
+
@cmidrule = false
|
196
|
+
@hline = false
|
197
|
+
end
|
198
|
+
#Set from tabular
|
199
|
+
attr_accessor :columns
|
200
|
+
#Set a line after the row.
|
201
|
+
def hline(); @hline = element(:hline); self; end
|
202
|
+
#Set line sequences under the fields
|
203
|
+
def cline( val )
|
204
|
+
@cline = [] if ! defined?( @cline )
|
205
|
+
if ! ( /\A\d+-\d+\z/ =~ val )
|
206
|
+
@log.warn("\\cline with wrong parameter: #{val.inspect}") if @log.warn?
|
207
|
+
end
|
208
|
+
@cline << val
|
209
|
+
return self
|
210
|
+
end
|
211
|
+
#Toprule requires booktabs.sty
|
212
|
+
def toprule(); @toprule = element(:toprule); self; end
|
213
|
+
#Midrule requires booktabs.sty
|
214
|
+
def midrule(); @midrule = element(:midrule); self; end
|
215
|
+
def cmidrule( val )
|
216
|
+
@cmidrule = [] if ! defined?( @cmidrule )
|
217
|
+
if ! ( /\A\d+-\d+\z/ =~ val )
|
218
|
+
@log.warn("\\cmidrule with wrong parameter: #{val.inspect}") if @log.warn?
|
219
|
+
end
|
220
|
+
@cmidrule << val
|
221
|
+
return self
|
222
|
+
end
|
223
|
+
|
224
|
+
#Bottomrule requires booktabs.sty
|
225
|
+
def bottomrule(); @bottomrule = element(:bottomrule); self; end
|
226
|
+
#Only inside a longtable
|
227
|
+
def endhead(); @endhead = element(:endhead); self; end
|
228
|
+
#Only inside a longtable
|
229
|
+
def endfoot(); @endfoot = element(:endfoot); self; end
|
230
|
+
#Only inside a longtable
|
231
|
+
def endfirsthead(); @endfirsthead = element(:endfirsthead); self; end
|
232
|
+
#Only inside a longtable
|
233
|
+
def endlastfoot(); @endlastfoot = element(:endlastfoot); self; end
|
234
|
+
#Only Colums are allowed to be added.
|
235
|
+
#In combination with longtable, captions are also allowed.
|
236
|
+
def << ( row )
|
237
|
+
#Check on allowed elements inside a row
|
238
|
+
allowed = false
|
239
|
+
[ :col, :multicolumn, :caption].each{|el|
|
240
|
+
if row.is_a?( Element.get(el) )
|
241
|
+
allowed = true
|
242
|
+
break
|
243
|
+
end
|
244
|
+
}
|
245
|
+
if ! allowed
|
246
|
+
@log.warn("Add non-column to tabular (#{row.class})") if @log.warn?
|
247
|
+
end
|
248
|
+
@content << row
|
249
|
+
#Does not work with multicolumns.
|
250
|
+
if !@columns
|
251
|
+
@log.warn("Add row to tabular with undefined columns number (#{row.inspect})" ) if @log.warn?
|
252
|
+
elsif @content.size > @columns
|
253
|
+
@log.warn("Tabular with #{@columns} columns get #{@content.size} columns" ) if @log.warn?
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def inspect()
|
258
|
+
return "<Class Row columns=#{@content.size}#{inspect_creation_caller}>"
|
259
|
+
end
|
260
|
+
#Each cell is separated by '&'.
|
261
|
+
def to_latex(options={})
|
262
|
+
o = set_option_defaults(options)
|
263
|
+
o[:log].debug("enter to_latex for row") if o[:log].debug?
|
264
|
+
cmd = ''
|
265
|
+
cmd << "\n" if @crbefore
|
266
|
+
cmd << @content.map{|cell| cell.to_latex(o)}.join(' & ')
|
267
|
+
#In direct use, one \\ is ok.
|
268
|
+
#In usage in documents, two \\ are needed (-> see unittest )
|
269
|
+
if o[:filename]
|
270
|
+
o[:log].debug("table/row with corresponding file #{o[:filename].inspect}") if o[:log].debug?
|
271
|
+
cmd << Regexp.escape('\\' + '\\')
|
272
|
+
else
|
273
|
+
o[:log].debug("table/row without corresponding file") if o[:log].debug?
|
274
|
+
cmd << Regexp.escape('\\')
|
275
|
+
end
|
276
|
+
cmd << "[#{@attr[:add_vspace].content.join}]" if @attr[:add_vspace].content.size > 0
|
277
|
+
cmd << @hline.to_latex(o) if @hline
|
278
|
+
cmd << @toprule.to_latex(o) if @toprule
|
279
|
+
cmd << @midrule.to_latex(o) if @midrule
|
280
|
+
cmd << @bottomrule.to_latex(o) if @bottomrule
|
281
|
+
cmd << @endfirsthead.to_latex(o) if @endfirsthead
|
282
|
+
cmd << @endhead.to_latex(o) if @endhead
|
283
|
+
cmd << @endfoot.to_latex(o) if @endfoot
|
284
|
+
cmd << @endlastfoot.to_latex(o) if @endlastfoot
|
285
|
+
@cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
|
286
|
+
@cmidrule.each{|cmidrule| cmd << "\\cmidrule{#{cmidrule}}" } if @cmidrule
|
287
|
+
cmd << "\n" if @crafter
|
288
|
+
return cmd
|
289
|
+
end
|
290
|
+
def htmltag()
|
291
|
+
return 'tr'
|
292
|
+
end
|
293
|
+
def to_html(options={})
|
294
|
+
o = set_option_defaults(options)
|
295
|
+
o[:log].debug("enter to_html for row") if o[:log].debug?
|
296
|
+
cmd = ''
|
297
|
+
cmd << "\n" if @crbefore
|
298
|
+
cmd << '<tr '
|
299
|
+
css = @attr[:style].content[0]
|
300
|
+
o[:log].error( "docgenerator_tabular: style is no CSS #{css.inspect}" ) if css and ! css.is_a?(CSS) and o[:log].error?
|
301
|
+
@attr[:style] << css = CSS.new if ! css
|
302
|
+
|
303
|
+
#Doesn't work. Style sheet setting in tr doesn't go to td
|
304
|
+
if @hline
|
305
|
+
css[:border_bottom_style] = 'solid'
|
306
|
+
css[:border_bottom_width] = 'medium'
|
307
|
+
end
|
308
|
+
|
309
|
+
# cmd << @toprule.to_s if @toprule
|
310
|
+
# cmd << @midrule.to_s if @midrule
|
311
|
+
# cmd << @bottomrule.to_s if @bottomrule
|
312
|
+
# @cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
|
313
|
+
# cmd << "[#{@attr[:add_vspace].content.to_s}]" if @attr[:add_vspace].content.size > 0
|
314
|
+
|
315
|
+
# cmd << @endfirsthead.to_s if @endfirsthead
|
316
|
+
# cmd << @endhead.to_s if @endhead
|
317
|
+
# cmd << @endfoot.to_s if @endfoot
|
318
|
+
# cmd << @endlastfoot.to_s if @endlastfoot
|
319
|
+
@attr.sort_by{|k,v| v.sortkey }.each{|k,v|
|
320
|
+
cmd << "#{k} = \"#{v}\" " if v.to_s != '' and v.html?
|
321
|
+
}
|
322
|
+
cmd << '>'
|
323
|
+
cmd << "#{@content.to_html(o)}"
|
324
|
+
cmd << "\n" if @crmid
|
325
|
+
cmd << '</tr>'
|
326
|
+
cmd << "\n" if @crafter
|
327
|
+
return cmd
|
328
|
+
end
|
329
|
+
def to_text(options={}); return "#{@content.to_text(options).strip}\n"; end
|
330
|
+
def to_wiki(options={}); return "\n|-\n#{@content.to_wiki(options).strip}"; end
|
331
|
+
def to_creole(options={}); return "\n|-\n#{@content.to_creole(options).strip}"; end
|
332
|
+
end #Row
|
316
333
|
|
317
334
|
=begin rdoc
|
318
335
|
Define Element :hline
|
@@ -323,10 +340,10 @@ or
|
|
323
340
|
Hline.new( [ attributes, [content]] )
|
324
341
|
Attributes are not defined for this element.
|
325
342
|
=end
|
326
|
-
class Hline < Element
|
327
|
-
|
328
|
-
|
329
|
-
end #Hline
|
343
|
+
class Hline < Element
|
344
|
+
has_no_content false
|
345
|
+
add_latex_output '\hline '
|
346
|
+
end #Hline
|
330
347
|
|
331
348
|
=begin rdoc
|
332
349
|
Define Element :toprule
|
@@ -337,10 +354,10 @@ or
|
|
337
354
|
Toprule.new( [ attributes, [content]] )
|
338
355
|
Attributes are not defined for this element.
|
339
356
|
=end
|
340
|
-
class Toprule < Element
|
341
|
-
|
342
|
-
|
343
|
-
end #Toprule
|
357
|
+
class Toprule < Element
|
358
|
+
has_no_content false
|
359
|
+
add_latex_output '\toprule'
|
360
|
+
end #Toprule
|
344
361
|
|
345
362
|
=begin rdoc
|
346
363
|
Define Element :midrule
|
@@ -351,10 +368,10 @@ or
|
|
351
368
|
Midrule.new( [ attributes, [content]] )
|
352
369
|
Attributes are not defined for this element.
|
353
370
|
=end
|
354
|
-
class Midrule < Element
|
355
|
-
|
356
|
-
|
357
|
-
end #Midrule
|
371
|
+
class Midrule < Element
|
372
|
+
has_no_content false
|
373
|
+
add_latex_output '\midrule '
|
374
|
+
end #Midrule
|
358
375
|
|
359
376
|
=begin rdoc
|
360
377
|
Define Element :bottomrule
|
@@ -365,10 +382,10 @@ or
|
|
365
382
|
Bottomrule.new( [ attributes, [content]] )
|
366
383
|
Attributes are not defined for this element.
|
367
384
|
=end
|
368
|
-
class Bottomrule < Element
|
369
|
-
|
370
|
-
|
371
|
-
end #Bottomrule
|
385
|
+
class Bottomrule < Element
|
386
|
+
has_no_content false
|
387
|
+
add_latex_output '\bottomrule '
|
388
|
+
end #Bottomrule
|
372
389
|
|
373
390
|
=begin rdoc
|
374
391
|
Define Element :endfirsthead
|
@@ -379,10 +396,10 @@ or
|
|
379
396
|
Endfirsthead.new( [ attributes, [content]] )
|
380
397
|
Attributes are not defined for this element.
|
381
398
|
=end
|
382
|
-
class Endfirsthead < Element
|
383
|
-
|
384
|
-
|
385
|
-
end #Endfirsthead
|
399
|
+
class Endfirsthead < Element
|
400
|
+
has_no_content false
|
401
|
+
add_latex_output '\endfirsthead '
|
402
|
+
end #Endfirsthead
|
386
403
|
|
387
404
|
=begin rdoc
|
388
405
|
Define Element :endhead
|
@@ -393,10 +410,10 @@ or
|
|
393
410
|
Endhead.new( [ attributes, [content]] )
|
394
411
|
Attributes are not defined for this element.
|
395
412
|
=end
|
396
|
-
class Endhead < Element
|
397
|
-
|
398
|
-
|
399
|
-
end #Endhead
|
413
|
+
class Endhead < Element
|
414
|
+
has_no_content false
|
415
|
+
add_latex_output '\endhead '
|
416
|
+
end #Endhead
|
400
417
|
|
401
418
|
=begin rdoc
|
402
419
|
Define Element :endfoot
|
@@ -407,12 +424,12 @@ or
|
|
407
424
|
Endfoot.new( [ attributes, [content]] )
|
408
425
|
Attributes are not defined for this element.
|
409
426
|
=end
|
410
|
-
class Endfoot < Element
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
end #Endfoot
|
427
|
+
class Endfoot < Element
|
428
|
+
has_no_content false
|
429
|
+
add_html_tag nil
|
430
|
+
add_latex_output '\endfoot '
|
431
|
+
|
432
|
+
end #Endfoot
|
416
433
|
|
417
434
|
=begin rdoc
|
418
435
|
Define Element :endlastfoot
|
@@ -423,111 +440,157 @@ or
|
|
423
440
|
Endlastfoot.new( [ attributes, [content]] )
|
424
441
|
Attributes are not defined for this element.
|
425
442
|
=end
|
426
|
-
class Endlastfoot < Element
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
end #Endlastfoot
|
443
|
+
class Endlastfoot < Element
|
444
|
+
has_no_content false
|
445
|
+
add_html_tag nil
|
446
|
+
add_latex_output '\endlastfoot '
|
447
|
+
end #Endlastfoot
|
431
448
|
|
432
449
|
=begin rdoc
|
433
450
|
A column in a tabular.
|
451
|
+
|
452
|
+
|
434
453
|
=end
|
435
|
-
class Column < Element
|
436
|
-
|
454
|
+
class Column < Element
|
455
|
+
has_no_content :empty_ok
|
437
456
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
#~ :th => {:colspan => nil, :rowspan => nil, :align=>align, :valign=>valign, :border=>nil, :width=>nil},#complete it
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
457
|
+
add_id :col
|
458
|
+
add_id :td
|
459
|
+
add_attributes HTML_ATTR_ALL
|
460
|
+
|
461
|
+
#~ :th => {:colspan => nil, :rowspan => nil, :align=>align, :valign=>valign, :border=>nil, :width=>nil},#complete it
|
462
|
+
add_attribute :width , Attribute.create( [ :html ] )
|
463
|
+
add_attribute :height , Attribute.create( [ :html ] )
|
464
|
+
add_attribute :align , HTML_ATTR_ALIGN
|
465
|
+
add_attribute :bgcolor , Attribute.create( [ :html ] )
|
466
|
+
|
467
|
+
def to_latex(options={})
|
468
|
+
o = set_option_defaults(options)
|
469
|
+
o[:log].debug("enter to_latex for column") if o[:log].debug?
|
470
|
+
cmd = ''
|
471
|
+
cmd << "\n" if @crbefore
|
472
|
+
cmd << "#{@content.to_latex(o)}"
|
473
|
+
cmd << "\n" if @crafter
|
474
|
+
return cmd
|
475
|
+
end
|
476
|
+
def content?; :empty_ok; end
|
477
|
+
def htmltag()
|
478
|
+
return 'td'
|
479
|
+
end
|
480
|
+
def to_text(options={}); return "#{@content.to_text(options).strip}\n"; end
|
481
|
+
def to_wiki(options={}); return "|#{@content.to_wiki(options).strip}\n"; end
|
482
|
+
=begin rdoc
|
483
|
+
Create a tabular-cell in creole.
|
484
|
+
|
485
|
+
This implements the docgenerator specific tabular version similar to wikimedia-syntax.
|
486
|
+
=end
|
487
|
+
def to_creole(options={})
|
488
|
+
o = set_option_defaults(options)
|
489
|
+
o[:log].debug("enter to_creole for column") if o[:log].debug?
|
490
|
+
result = "|"
|
491
|
+
result << "#{@content.to_creole(options).strip}"
|
492
|
+
if result.gsub!("\n", ' ')
|
493
|
+
o[:log].warn("Tabular cell contained newline") if o[:log].warn?
|
494
|
+
end
|
495
|
+
|
496
|
+
result << "||" #separator between content and options
|
497
|
+
#Attach options
|
498
|
+
@attr.each{|attr_key, attr|
|
499
|
+
next unless attr.filled? #ignore empty attributes
|
500
|
+
case attr_key
|
501
|
+
when :style
|
502
|
+
result << "css=#{attr.content.join}|"
|
503
|
+
when :class
|
504
|
+
result << "class=#{attr.content.join}|"
|
505
|
+
when :title
|
506
|
+
result << "title=#{attr.content.join}|"
|
507
|
+
when :columns ##from multicolumns
|
508
|
+
else
|
509
|
+
#~ p attr_key
|
510
|
+
o[:log].debug("unsupported attribute #{attr_key} in to_creole for column") if o[:log].debug?
|
511
|
+
end
|
512
|
+
}
|
513
|
+
result << "\n"
|
514
|
+
result.sub!(/\|\|\n/, "\n") #remove options separator, if no options available
|
515
|
+
return result
|
516
|
+
end
|
517
|
+
def inspect()
|
518
|
+
return "<Class Column @content=#{@content.inspect}>"
|
519
|
+
end
|
520
|
+
end #Columns
|
467
521
|
=begin rdoc
|
468
522
|
Header cell (only for HTML)
|
469
523
|
=end
|
470
|
-
class Column_th < Column
|
471
|
-
|
472
|
-
|
473
|
-
end
|
524
|
+
class Column_th < Column
|
525
|
+
add_id :th
|
526
|
+
add_html_tag 'th'
|
527
|
+
end
|
474
528
|
=begin rdoc
|
475
529
|
Multicolumn
|
476
530
|
=end
|
477
|
-
class Multicolumn < Column
|
478
|
-
|
531
|
+
class Multicolumn < Column
|
532
|
+
has_no_content :empty_ok
|
479
533
|
|
480
|
-
#~ add_attributes( HTML_ATTR_ALL )
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
534
|
+
#~ add_attributes( HTML_ATTR_ALL )
|
535
|
+
add_attributes( {
|
536
|
+
#~ :columns => Attribute.create( [:required], [ Fixnum ] ) , #colspan
|
537
|
+
:colspan => Attribute.create( [:required, :html, :latex], [ Fixnum ], 2 ) ,
|
538
|
+
:columns => :colspan,
|
539
|
+
:rowspan => Attribute.create( [:html ], [ Fixnum ], 2 ),
|
540
|
+
:pos => Attribute.create( [:latex] ) ,
|
541
|
+
:align => HTML_ATTR_ALIGN,
|
542
|
+
:width => Attribute.create( [ :html ] ),
|
543
|
+
:height => Attribute.create( [ :html ] ),
|
544
|
+
}.update( HTML_ATTR_ALL ) )
|
545
|
+
def to_latex(options={})
|
546
|
+
o = set_option_defaults(options)
|
547
|
+
o[:log].debug("enter to_latex for multicolumn") if o[:log].debug?
|
548
|
+
o[:log].warn("multicolumn without latex-position") unless @attr[:pos].filled?
|
549
|
+
cmd = ''
|
550
|
+
cmd << "\n" if @crbefore
|
551
|
+
cmd << "\\multicolumn{#{@attr[:colspan]}}{#{@attr[:pos]}}{#{@content.to_latex(o)}}"
|
552
|
+
cmd << "\n" if @crafter
|
553
|
+
return cmd
|
554
|
+
end
|
555
|
+
#add_html_output -> like Column, :colspan is obligatory
|
556
|
+
def to_text(options={}); return "#{@content.to_text(options).strip}\n"; end
|
557
|
+
def to_wiki(options={}); return "|columns=#{@attr[:colspan]}|pos=#{@attr[:pos]}||#{@content.to_wiki(options).strip}\n"; end
|
558
|
+
def to_creole(options={});
|
559
|
+
#~ o = set_option_defaults(options)
|
560
|
+
col = super.strip
|
561
|
+
col << "||columns=#{@attr[:colspan]}"
|
562
|
+
col << "|pos=#{@attr[:pos]}" if @attr[:pos].filled?
|
563
|
+
col << "\n"
|
564
|
+
return col
|
565
|
+
end
|
566
|
+
|
567
|
+
#
|
568
|
+
def inspect()
|
569
|
+
return "<Class Multicolumn @content=#{@content.inspect}>"
|
570
|
+
end
|
571
|
+
end
|
509
572
|
|
510
|
-
class Caption < Element
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
end
|
573
|
+
class Caption < Element
|
574
|
+
#
|
575
|
+
add_attribute :optional, Attribute.create( [ :latex ] )
|
576
|
+
|
577
|
+
def to_latex(options= {})
|
578
|
+
cmd = ''
|
579
|
+
cmd << "\n" if @crbefore
|
580
|
+
cmd << "\\caption"
|
581
|
+
if @attr[:optional].content != []
|
582
|
+
cmd << "["
|
583
|
+
cmd << @attr[:optional].content.to_s
|
584
|
+
cmd << "]"
|
585
|
+
cmd << "\n\t" if @crmid
|
586
|
+
end
|
587
|
+
cmd << "{"
|
588
|
+
cmd << @content.to_latex(options)
|
589
|
+
cmd << "}"
|
590
|
+
cmd << "\n" if @crafter
|
591
|
+
return cmd
|
592
|
+
end
|
593
|
+
end #class Caption
|
531
594
|
|
532
|
-
end #module Tab
|
595
|
+
end #module Tab
|
533
596
|
end #module Docgenerator
|