docgenerator 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/examples/creole_example_tabular.rb +95 -0
  2. data/examples/docgenerator_example.rb +5 -5
  3. data/lib/creole/creole2doc.rb +28 -18
  4. data/lib/creole/creole_inclusions.rb +4 -4
  5. data/lib/creole/creole_placeholder.rb +4 -1
  6. data/lib/creole/creole_tabular.rb +173 -155
  7. data/lib/creole/plugins/rail.rb +118 -119
  8. data/lib/creole/plugins/struktex.rb +35 -35
  9. data/lib/creole/plugins/todonotes.rb +8 -1
  10. data/lib/docgenerator/attribute.rb +160 -160
  11. data/lib/docgenerator/characters.rb +343 -311
  12. data/lib/docgenerator/css.rb +167 -167
  13. data/lib/docgenerator/document.rb +525 -511
  14. data/lib/docgenerator/element.rb +316 -316
  15. data/lib/docgenerator/element_meta.rb +114 -114
  16. data/lib/docgenerator/elements.rb +19 -9
  17. data/lib/docgenerator/environments.rb +3 -1
  18. data/lib/docgenerator/lists.rb +177 -174
  19. data/lib/docgenerator/packages/hyperref.rb +74 -70
  20. data/lib/docgenerator/packages/multicol.rb +33 -0
  21. data/lib/docgenerator/packages/scrlettr2.rb +152 -151
  22. data/lib/docgenerator/packages/todonotes.rb +1 -1
  23. data/lib/docgenerator/tabular.rb +463 -400
  24. data/lib/docgenerator/templates/docgenerator_template.rb +94 -84
  25. data/lib/docgenerator/templates/docgenerator_template.yaml +75 -15
  26. data/lib/docgenerator.rb +1 -1
  27. data/lib/wiki2doc/wiki2docgenerator.rb +1 -1
  28. data/meta_test_and_doc/build__meta.rb +125 -0
  29. data/meta_test_and_doc/build_doc.rb +333 -0
  30. data/meta_test_and_doc/build_test.rb +251 -0
  31. data/meta_test_and_doc/manpages/attachfile.rb +389 -0
  32. data/meta_test_and_doc/manpages/caption.rb +133 -0
  33. data/meta_test_and_doc/manpages/characters.rb +3738 -0
  34. data/meta_test_and_doc/manpages/elements.rb +6851 -0
  35. data/meta_test_and_doc/manpages/environments.rb +985 -0
  36. data/meta_test_and_doc/manpages/footnote.rb +439 -0
  37. data/meta_test_and_doc/manpages/hyperref.rb +605 -0
  38. data/meta_test_and_doc/manpages/listings.rb +988 -0
  39. data/meta_test_and_doc/manpages/lists.rb +1463 -0
  40. data/meta_test_and_doc/manpages/others.rb +129 -0
  41. data/meta_test_and_doc/manpages/packages.rb +13 -0
  42. data/meta_test_and_doc/manpages/pdfpages.rb +108 -0
  43. data/meta_test_and_doc/manpages/readme.rdoc +9 -0
  44. data/meta_test_and_doc/manpages/scrlettr2.rb +362 -0
  45. data/meta_test_and_doc/manpages/scrpage2.rb +2028 -0
  46. data/meta_test_and_doc/manpages/sectioning.rb +2467 -0
  47. data/meta_test_and_doc/manpages/tables.rb +2088 -0
  48. data/meta_test_and_doc/manpages/todonotes.rb +235 -0
  49. data/meta_test_and_doc/manpages/wiki2docgenerator.rb +64 -0
  50. data/{readme.rd → readme.rdoc} +18 -1
  51. data/unittest/expected/test_tabular.creole +33 -0
  52. data/unittest/expected_creole/test_creole_creole1.0test.html +3 -3
  53. data/unittest/expected_creole/test_creole_creole1.0test.latex +3 -3
  54. data/unittest/expected_creole/test_creole_creole1.0test.text +3 -3
  55. data/unittest/expected_creole/test_creole_inline_apostroph.html +6 -0
  56. data/unittest/expected_creole/test_creole_inline_apostroph.latex +8 -0
  57. data/unittest/expected_creole/test_creole_inline_apostroph.text +4 -0
  58. data/unittest/expected_creole/test_creole_input.normsource +12 -12
  59. data/unittest/expected_creole/test_creole_input.normsource_1.8 +23 -0
  60. data/unittest/expected_creole/test_creole_links_external_implicit.html +2 -2
  61. data/unittest/expected_creole/test_creole_links_external_implicit.latex +2 -2
  62. data/unittest/expected_creole/test_creole_links_external_implicit.text +2 -2
  63. data/unittest/expected_creole/test_creole_links_implicit_end.html +1 -1
  64. data/unittest/expected_creole/test_creole_links_implicit_end.latex +1 -1
  65. data/unittest/expected_creole/test_creole_list_ul.normsource +42 -42
  66. data/unittest/expected_creole/test_creole_list_ul.normsource_1.8 +83 -0
  67. data/unittest/expected_creole/test_creole_paragraphs.normsource +15 -15
  68. data/unittest/expected_creole/test_creole_paragraphs.normsource_1.8 +27 -0
  69. data/unittest/expected_creole/test_creole_tabular.creole +22 -0
  70. data/unittest/expected_creole/test_creole_tabular_creole.creole +19 -0
  71. data/unittest/expected_creole/test_creole_tabular_css.creole +24 -0
  72. data/unittest/expected_creole/test_creole_tabular_multicols.creole +16 -0
  73. data/unittest/expected_creole/test_creole_tabular_multicols.html +14 -0
  74. data/unittest/expected_creole/test_creole_tabular_multicols.latex +16 -0
  75. data/unittest/expected_creole/test_creole_tabular_with_cell_option.creole +21 -0
  76. data/unittest/expected_creole/test_creole_toc_level_text.html +2 -2
  77. data/unittest/expected_creole/test_creole_toc_level_text.latex +2 -2
  78. data/unittest/expected_packages/test_multicol_3.tex +2 -0
  79. data/unittest/expected_packages/test_multicol_3_titleline.tex +2 -0
  80. data/unittest/expected_templates/test_article.tex +23 -0
  81. data/unittest/expected_templates/test_article_utf8.tex +34 -0
  82. data/unittest/expected_templates/test_context.miv +18 -0
  83. data/unittest/expected_templates/test_creole.creole +8 -0
  84. data/unittest/expected_templates/test_html.html +12 -0
  85. data/unittest/expected_templates/test_html401_strict.html +14 -0
  86. data/unittest/expected_templates/test_html401_trans.html +14 -0
  87. data/unittest/expected_templates/test_html_utf8.html +14 -0
  88. data/unittest/expected_templates/test_include.tex +17 -0
  89. data/unittest/expected_templates/test_include_utf8.tex +17 -0
  90. data/unittest/expected_templates/test_text.txt +6 -0
  91. data/unittest/expected_templates/test_wiki.wiki +6 -0
  92. data/unittest/expected_templates/test_xhtml_strict.html +14 -0
  93. data/unittest/expected_templates/test_xhtml_trans.html +14 -0
  94. data/unittest/unittest_creole.rb +27 -6
  95. data/unittest/unittest_creole_placeholders.rb +1 -123
  96. data/unittest/unittest_creole_tabular.rb +174 -0
  97. data/unittest/unittest_docgenerator.rb +4 -3
  98. data/unittest/unittest_docgenerator_characters.rb +4769 -615
  99. data/unittest/unittest_packages_multicol.rb +84 -0
  100. data/unittest/unittest_rubycode4doc.rb +0 -1
  101. data/unittest/unittest_templates.rb +64 -0
  102. metadata +163 -77
  103. data/build_test_and_doc.rb +0 -505
  104. data/manpage_elements.rb +0 -10411
@@ -1,33 +1,29 @@
1
1
  #encoding: utf-8
2
2
  =begin rdoc
3
- Definition of tabular elements for DocGenerator.rb
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 DocGenerator.rb
9
+ Definition of tabular elements for docgenerator-gem.
10
10
  =end
11
- module Tables
12
- #~ if __FILE__ == $0
13
- #~ require 'DocGenerator'
14
- #~ end
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
- add_attributes HTML_ATTR_ALL
26
- add_html_tag 'div'
27
- def to_latex( options={} )
28
- return to_latex_environment( 'table', nil, options )
29
- end
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
- add_attributes HTML_ATTR_ALL
40
- #Problem: Nicht weitervererbt
41
- add_attribute :columndescription , Attribute.create( [:latex, :required ] )
42
- add_attribute :columns , Attribute.create( [:required], [ Fixnum ] )
43
- add_attribute :border , Attribute.create( [:html] )
44
- add_attribute :bgcolor , Attribute.create( [ :html ] )
45
- add_attribute :width , Attribute.create( [ :html ], [ Integer, String ] ) #String necessary for percentage
46
- add_attribute :frame , Attribute.create( [ :html ], [ 'box', 'above', 'below', 'hsides', 'vsides', 'lhs', 'rhs' ] )
47
- add_attribute :rules , Attribute.create( [ :html ], [ 'none', 'rows', 'cols', 'groups', 'all' ] )
48
- add_attribute :height , Attribute.create( [ :html ], [ Integer ] )
49
- add_attribute :cellspacing , Attribute.create( [ :html ], [ Integer ] )
50
- add_attribute :cellpadding , Attribute.create( [ :html ], [ Integer ] )
51
- add_attribute :summary , Attribute.create( [:html] )
52
- add_attribute :align , HTML_ATTR_ALIGN
53
- #Only rows are allowed to be added.
54
- #The row get the number of columns.
55
- #The row counting does not word, when the row-content is added immediate in element-initialization.
56
- def << ( row )
57
- #Check on allowed elements for a tabular
58
- allowed = false
59
- [ :row, :hline, :toprule, :midrule, :bottomrule, :endfirsthead , :endhead , :endfoot, :endlastfoot,
60
- :caption ].each{|el|
61
- if row.is_a?( Element.get(el) )
62
- allowed = true
63
- break
64
- end
65
- }
66
- if ! allowed
67
- @log.warn("Add non-row to tabular (#{row.class})") if @log.warn?
68
- end
69
- if row.is_a?( Row )
70
- row.columns = @attr[:columns].to_s.to_i
71
- end
72
- @content << row
73
- end
74
- def to_latex(options={})
75
- o = set_option_defaults(options)
76
- o[:log].debug("enter to_latex for tabular") if o[:log].debug?
77
- cmd = ''
78
- cmd << "\n" if @crbefore
79
- cmd << "\\begin{tabular}{"
80
- cmd << @attr[:columndescription].content.to_doc(:latex, o)
81
- cmd << "}"
82
- cmd << "\n" if @crmid
83
- cmd << @content.to_doc(:latex, o )
84
- cmd << "\\end{tabular}"
85
- cmd << "\n" if @crafter
86
- return cmd
87
- end
88
- def to_text(options={}); return @content.to_text(options); end
89
- def to_wiki(options={}); return "{|\n#{@content.to_wiki(options).strip}\n|}\n"; end
90
- def htmltag()
91
- return 'table'
92
- end
93
- def inspect()
94
- return "<Class Element(tabular) columns=#{@attr[:columns]}>"
95
- end
96
- end
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
- add_attributes Tabular.get_attribute_list( )
105
- def to_latex(options={})
106
- o = set_option_defaults(options)
107
- o[:log].debug("enter to_latex for longtable") if o[:log].debug?
108
- cmd = ''
109
- cmd << "\n" if @crbefore
110
- cmd << "\\begin{longtable}{"
111
- cmd << @attr[:columndescription].content.to_doc(:latex, o)
112
- cmd << "}"
113
- cmd << "\n" if @crmid
114
- cmd << @content.to_latex(o)
115
- cmd << "\\end{longtable}"
116
- cmd << "\n" if @crafter
117
- return cmd
118
- end
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
- add_attributes Tabular.get_attribute_list( )
131
- def to_latex(options={})
132
- o = set_option_defaults(options)
133
- o[:log].debug("enter to_latex for tabularx") if o[:log].debug?
134
- if @attr[:width].content.to_s == ''
135
- o[:log].error( "Tabularx: Empty width, set it to \\textwidth" ) if o[:log].error?
136
- @attr[:width] << '\\textwidth'
137
- end
138
- cmd = ''
139
- cmd << "\n" if @crbefore
140
- cmd << "\\begin{tabularx}{"
141
- cmd << @attr[:width].content.to_s
142
- cmd << "}{"
143
- cmd << @attr[:columndescription].content.to_s
144
- cmd << "}"
145
- cmd << "\n" if @crmid
146
- cmd << @content.to_doc(:latex, o )
147
- cmd << "\\end{tabularx}"
148
- cmd << "\n" if @crafter
149
- return cmd
150
- end
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
- add_id :tr
159
- #~ :tr => {:align=>align},#complete it
160
- add_attributes( {
161
- :add_vspace => Attribute.create( [:latex] ) ,
162
- :bgcolor => Attribute.create( [ :html ] ),
163
- :width => Attribute.create( [ :html ] ),
164
- :height => Attribute.create( [ :html ] ),
165
- #fixme
166
- #~ :hline => Attribute.create( [:latex], [true, false] ) ,
167
- }.update(HTML_ATTR_ALL) )
168
- def initialize( attr={}, content = nil)
169
- super
170
- #For Ruby 1.9: Initialize instance variable
171
- @toprule = false
172
- @midrule = false
173
- @bottomrule = false
174
- @endfirsthead = false
175
- @endhead = false
176
- @endfoot = false
177
- @endlastfoot = false
178
- @cline = false
179
- @cmidrule = false
180
- @hline = false
181
- end
182
- #Set from tabular
183
- attr_accessor :columns
184
- #Set a line after the row.
185
- def hline(); @hline = element(:hline); self; end
186
- #Set line sequences under the fields
187
- def cline( val )
188
- @cline = [] if ! defined?( @cline )
189
- if ! ( /\A\d+-\d+\z/ =~ val )
190
- @log.warn("\\cline with wrong parameter: #{val.inspect}") if @log.warn?
191
- end
192
- @cline << val
193
- return self
194
- end
195
- #Toprule requires booktabs.sty
196
- def toprule(); @toprule = element(:toprule); self; end
197
- #Midrule requires booktabs.sty
198
- def midrule(); @midrule = element(:midrule); self; end
199
- def cmidrule( val )
200
- @cmidrule = [] if ! defined?( @cmidrule )
201
- if ! ( /\A\d+-\d+\z/ =~ val )
202
- @log.warn("\\cmidrule with wrong parameter: #{val.inspect}") if @log.warn?
203
- end
204
- @cmidrule << val
205
- return self
206
- end
207
-
208
- #Bottomrule requires booktabs.sty
209
- def bottomrule(); @bottomrule = element(:bottomrule); self; end
210
- #Only inside a longtable
211
- def endhead(); @endhead = element(:endhead); self; end
212
- #Only inside a longtable
213
- def endfoot(); @endfoot = element(:endfoot); self; end
214
- #Only inside a longtable
215
- def endfirsthead(); @endfirsthead = element(:endfirsthead); self; end
216
- #Only inside a longtable
217
- def endlastfoot(); @endlastfoot = element(:endlastfoot); self; end
218
- #Only Colums are allowed to be added.
219
- #In combination with longtable, captions are also allowed.
220
- def << ( row )
221
- #Check on allowed elements inside a row
222
- allowed = false
223
- [ :col, :multicolumn, :caption].each{|el|
224
- if row.is_a?( Element.get(el) )
225
- allowed = true
226
- break
227
- end
228
- }
229
- if ! allowed
230
- @log.warn("Add non-column to tabular (#{row.class})") if @log.warn?
231
- end
232
- @content << row
233
- #Does not work with multicolumns.
234
- if !@columns
235
- @log.warn("Add row to tabular with undefined columns number (#{row.inspect})" ) if @log.warn?
236
- elsif @content.size > @columns
237
- @log.warn("Tabular with #{@columns} columns get #{@content.size} columns" ) if @log.warn?
238
- end
239
- end
240
-
241
- def inspect()
242
- return "<Class Row columns=#{@content.size}#{inspect_creation_caller}>"
243
- end
244
- #Each cell is separated by '&'.
245
- def to_latex(options={})
246
- o = set_option_defaults(options)
247
- o[:log].debug("enter to_latex for row") if o[:log].debug?
248
- cmd = ''
249
- cmd << "\n" if @crbefore
250
- cmd << @content.map{|cell| cell.to_latex(o)}.join(' & ')
251
- #In direct use, one \\ is ok.
252
- #In usage in documents, two \\ are needed (-> see unittest )
253
- if o[:filename]
254
- o[:log].debug("table/row with corresponding file #{o[:filename].inspect}") if o[:log].debug?
255
- cmd << Regexp.escape('\\' + '\\')
256
- else
257
- o[:log].debug("table/row without corresponding file") if o[:log].debug?
258
- cmd << Regexp.escape('\\')
259
- end
260
- cmd << "[#{@attr[:add_vspace].content.join}]" if @attr[:add_vspace].content.size > 0
261
- cmd << @hline.to_latex(o) if @hline
262
- cmd << @toprule.to_latex(o) if @toprule
263
- cmd << @midrule.to_latex(o) if @midrule
264
- cmd << @bottomrule.to_latex(o) if @bottomrule
265
- cmd << @endfirsthead.to_latex(o) if @endfirsthead
266
- cmd << @endhead.to_latex(o) if @endhead
267
- cmd << @endfoot.to_latex(o) if @endfoot
268
- cmd << @endlastfoot.to_latex(o) if @endlastfoot
269
- @cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
270
- @cmidrule.each{|cmidrule| cmd << "\\cmidrule{#{cmidrule}}" } if @cmidrule
271
- cmd << "\n" if @crafter
272
- return cmd
273
- end
274
- def htmltag()
275
- return 'tr'
276
- end
277
- def to_html(options={})
278
- o = set_option_defaults(options)
279
- o[:log].debug("enter to_html for row") if o[:log].debug?
280
- cmd = ''
281
- cmd << "\n" if @crbefore
282
- cmd << '<tr '
283
- css = @attr[:style].content[0]
284
- o[:log].error( "docgenerator_tabular: style is no CSS #{css.inspect}" ) if css and ! css.is_a?(CSS) and o[:log].error?
285
- @attr[:style] << css = CSS.new if ! css
286
-
287
- #Doesn't work. Style sheet setting in tr doesn't go to td
288
- if @hline
289
- css[:border_bottom_style] = 'solid'
290
- css[:border_bottom_width] = 'medium'
291
- end
292
-
293
- # cmd << @toprule.to_s if @toprule
294
- # cmd << @midrule.to_s if @midrule
295
- # cmd << @bottomrule.to_s if @bottomrule
296
- # @cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
297
- # cmd << "[#{@attr[:add_vspace].content.to_s}]" if @attr[:add_vspace].content.size > 0
298
-
299
- # cmd << @endfirsthead.to_s if @endfirsthead
300
- # cmd << @endhead.to_s if @endhead
301
- # cmd << @endfoot.to_s if @endfoot
302
- # cmd << @endlastfoot.to_s if @endlastfoot
303
- @attr.sort_by{|k,v| v.sortkey }.each{|k,v|
304
- cmd << "#{k} = \"#{v}\" " if v.to_s != '' and v.html?
305
- }
306
- cmd << '>'
307
- cmd << "#{@content.to_html(o)}"
308
- cmd << "\n" if @crmid
309
- cmd << '</tr>'
310
- cmd << "\n" if @crafter
311
- return cmd
312
- end
313
- def to_text(options={}); return "#{@content.to_text(options).strip}\n"; end
314
- def to_wiki(options={}); return "\n|-\n#{@content.to_wiki(options).strip}"; end
315
- end #Row
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
- has_no_content false
328
- add_latex_output '\hline '
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
- has_no_content false
342
- add_latex_output '\toprule'
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
- has_no_content false
356
- add_latex_output '\midrule '
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
- has_no_content false
370
- add_latex_output '\bottomrule '
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
- has_no_content false
384
- add_latex_output '\endfirsthead '
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
- has_no_content false
398
- add_latex_output '\endhead '
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
- has_no_content false
412
- add_html_tag nil
413
- add_latex_output '\endfoot '
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
- has_no_content false
428
- add_html_tag nil
429
- add_latex_output '\endlastfoot '
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
- has_no_content :empty_ok
454
+ class Column < Element
455
+ has_no_content :empty_ok
437
456
 
438
- add_id :col
439
- add_id :td
440
- add_attributes HTML_ATTR_ALL
441
-
442
- #~ :th => {:colspan => nil, :rowspan => nil, :align=>align, :valign=>valign, :border=>nil, :width=>nil},#complete it
443
- add_attribute :width , Attribute.create( [ :html ] )
444
- add_attribute :height , Attribute.create( [ :html ] )
445
- add_attribute :align , HTML_ATTR_ALIGN
446
- add_attribute :bgcolor , Attribute.create( [ :html ] )
447
-
448
- def to_latex(options={})
449
- o = set_option_defaults(options)
450
- o[:log].debug("enter to_latex for column") if o[:log].debug?
451
- cmd = ''
452
- cmd << "\n" if @crbefore
453
- cmd << "#{@content.to_latex(o)}"
454
- cmd << "\n" if @crafter
455
- return cmd
456
- end
457
- def content?; :empty_ok; end
458
- def htmltag()
459
- return 'td'
460
- end
461
- def to_text(options={}); return "#{@content.to_text(options).strip}\n"; end
462
- def to_wiki(options={}); return "|#{@content.to_wiki(options).strip}\n"; end
463
- def inspect()
464
- return "<Class Column @content=#{@content.inspect}>"
465
- end
466
- end #Columns
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
- add_id :th
472
- add_html_tag 'th'
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
- has_no_content :empty_ok
531
+ class Multicolumn < Column
532
+ has_no_content :empty_ok
479
533
 
480
- #~ add_attributes( HTML_ATTR_ALL )
481
- add_attributes( {
482
- #~ :columns => Attribute.create( [:required], [ Fixnum ] ) , #colspan
483
- :colspan => Attribute.create( [:required, :html, :latex], [ Fixnum ], 2 ) ,
484
- :columns => :colspan,
485
- :rowspan => Attribute.create( [:html ], [ Fixnum ], 2 ),
486
- :pos => Attribute.create( [:latex] ) ,
487
- :align => HTML_ATTR_ALIGN,
488
- :width => Attribute.create( [ :html ] ),
489
- :height => Attribute.create( [ :html ] ),
490
- }.update( HTML_ATTR_ALL ) )
491
- def to_latex(options={})
492
- o = set_option_defaults(options)
493
- o[:log].debug("enter to_latex for multicolumn") if o[:log].debug?
494
- cmd = ''
495
- cmd << "\n" if @crbefore
496
- cmd << "\\multicolumn{#{@attr[:colspan]}}{#{@attr[:pos]}}{#{@content.to_latex(o)}}"
497
- cmd << "\n" if @crafter
498
- return cmd
499
- end
500
- #add_html_output -> like Column, :colspan is obligatory
501
- def to_text(options={}); return "#{@content.to_text(options).strip}\n"; end
502
- def to_wiki(options={}); return "|columns=#{@attr[:colspan]}|pos=#{@attr[:pos]}||#{@content.to_wiki(options).strip}\n"; end
503
-
504
- #
505
- def inspect()
506
- return "<Class Multicolumn @content=#{@content.inspect}>"
507
- end
508
- end
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
- add_attribute :optional, Attribute.create( [ :latex ] )
513
-
514
- def to_latex(options= {})
515
- cmd = ''
516
- cmd << "\n" if @crbefore
517
- cmd << "\\caption"
518
- if @attr[:optional].content != []
519
- cmd << "["
520
- cmd << @attr[:optional].content.to_s
521
- cmd << "]"
522
- cmd << "\n\t" if @crmid
523
- end
524
- cmd << "{"
525
- cmd << @content.to_s
526
- cmd << "}"
527
- cmd << "\n" if @crafter
528
- return cmd
529
- end
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