docgenerator 0.1.1
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/docgenerator.rb +137 -0
- data/docgenerator_attribute.rb +142 -0
- data/docgenerator_characters.rb +171 -0
- data/docgenerator_css.rb +207 -0
- data/docgenerator_document.rb +374 -0
- data/docgenerator_element.rb +570 -0
- data/docgenerator_elements.rb +554 -0
- data/docgenerator_environments.rb +73 -0
- data/docgenerator_footnote.rb +106 -0
- data/docgenerator_lists.rb +163 -0
- data/docgenerator_sections.rb +88 -0
- data/docgenerator_tabular.rb +376 -0
- data/docgenerator_template.rb +103 -0
- data/examples/docgenerator_example.rb +185 -0
- data/packages/docgenerator_attachfile.rb +71 -0
- data/packages/docgenerator_beamer.rb +250 -0
- data/packages/docgenerator_caption.rb +43 -0
- data/packages/docgenerator_hyperref.rb +109 -0
- data/packages/docgenerator_listings.rb +100 -0
- data/packages/docgenerator_pdfpages.rb +18 -0
- data/packages/docgenerator_scrlettr2.rb +128 -0
- data/packages/docgenerator_scrpage2.rb +172 -0
- data/packages/docgenerator_url.rb +84 -0
- metadata +68 -0
@@ -0,0 +1,376 @@
|
|
1
|
+
#
|
2
|
+
#Definition of elements for DocGenerator.rb
|
3
|
+
#
|
4
|
+
if __FILE__ == $0
|
5
|
+
require 'DocGenerator'
|
6
|
+
end
|
7
|
+
|
8
|
+
#Define some constants to include packages into document header.
|
9
|
+
TEX_PACKAGE_TABULARX = element(:usepackage,{},'tabularx').cr
|
10
|
+
TEX_PACKAGE_LONGTABLE= element(:usepackage,{},'longtable').cr
|
11
|
+
TEX_PACKAGE_BOOKTABS = element(:usepackage,{},'booktabs').cr
|
12
|
+
|
13
|
+
class Table < Environment
|
14
|
+
add_attributes( HTML_ATTR_ALL )
|
15
|
+
Element.add( [:table ], Table)
|
16
|
+
def htmltag(); 'div'; end
|
17
|
+
def to_latex( )
|
18
|
+
return to_latex_environment( 'table' )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#Tabulars
|
23
|
+
#fixme: check on attributes. columnsdescription
|
24
|
+
#~ :table=> {:border=>nil, :width=>nil, :cellpadding=>nil, :cellspacing=>nil},#complete it
|
25
|
+
#~ :colgroup => {}, #comlpete it
|
26
|
+
class Tabular < Element
|
27
|
+
#Make the key known to the complete key-list of elements.
|
28
|
+
Element.add( [:tabular], Tabular )
|
29
|
+
#~ add_attributes( HTML_ATTR_ALL )
|
30
|
+
#Problem: Nicht weitervererbt
|
31
|
+
add_attributes( {
|
32
|
+
:columndescription => Attribute.create( [:latex, :required ] ) ,
|
33
|
+
:columns => Attribute.create( [:required], [ Fixnum ] ) ,
|
34
|
+
:border => Attribute.create( [:html] ) ,
|
35
|
+
:bgcolor => Attribute.create( [ :html ] ),
|
36
|
+
:width => Attribute.create( [ :html ], [ Integer, String ] ), #String necessary for percentage
|
37
|
+
:frame => Attribute.create( [ :html ], [ 'box', 'above', 'below', 'hsides', 'vsides', 'lhs', 'rhs' ] ),
|
38
|
+
:rules => Attribute.create( [ :html ], [ 'none', 'rows', 'cols', 'groups', 'all' ] ),
|
39
|
+
:height => Attribute.create( [ :html ], [ Integer ] ),
|
40
|
+
:cellspacing => Attribute.create( [ :html ], [ Integer ] ),
|
41
|
+
:cellpadding => Attribute.create( [ :html ], [ Integer ] ),
|
42
|
+
:summary => Attribute.create( [:html] ) ,
|
43
|
+
:align => HTML_ATTR_ALIGN,
|
44
|
+
}.update( HTML_ATTR_ALL ) )
|
45
|
+
#Only rows are allowed to be added.
|
46
|
+
#The row get the number of columns.
|
47
|
+
#The row counting does not word, when the row-content is added immediate in element-initialization.
|
48
|
+
def << ( row )
|
49
|
+
#Check on allowed elements for a tabular
|
50
|
+
allowed = false
|
51
|
+
[ :row, :hline, :toprule, :midrule, :bottomrule, :endfirsthead , :endhead , :endfoot, :endlastfoot,
|
52
|
+
:caption ].each{|el|
|
53
|
+
if row.is_a?( Element.get(el) )
|
54
|
+
allowed = true
|
55
|
+
break
|
56
|
+
end
|
57
|
+
}
|
58
|
+
if ! allowed
|
59
|
+
puts "Add non-row to tabular (#{row.class})"
|
60
|
+
end
|
61
|
+
if row.is_a?( Row )
|
62
|
+
row.columns = @attr[:columns].to_s.to_i
|
63
|
+
end
|
64
|
+
@content << row
|
65
|
+
set_backlink( row )
|
66
|
+
end
|
67
|
+
def to_latex()
|
68
|
+
cmd = ''
|
69
|
+
cmd << "\n" if @crbefore
|
70
|
+
cmd << "\\begin{tabular}{"
|
71
|
+
cmd << @attr[:columndescription].content.to_s
|
72
|
+
cmd << "}"
|
73
|
+
cmd << "\n" if @crmid
|
74
|
+
cmd << @content.to_s
|
75
|
+
cmd << "\\end{tabular}"
|
76
|
+
cmd << "\n" if @crafter
|
77
|
+
return cmd
|
78
|
+
end
|
79
|
+
def htmltag()
|
80
|
+
return 'table'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
#Requires
|
84
|
+
# doc.head << element(:usepackage,{},'longtable')
|
85
|
+
class Longtable < Tabular
|
86
|
+
#Make the key known to the complete key-list of elements.
|
87
|
+
Element.add( [:longtable], Longtable )
|
88
|
+
#
|
89
|
+
add_attributes( Element.get_attribute_list( Tabular ) )
|
90
|
+
def to_latex()
|
91
|
+
cmd = ''
|
92
|
+
cmd << "\n" if @crbefore
|
93
|
+
cmd << "\\begin{longtable}{"
|
94
|
+
cmd << @attr[:columndescription].content.to_s
|
95
|
+
cmd << "}"
|
96
|
+
cmd << "\n" if @crmid
|
97
|
+
cmd << @content.to_s
|
98
|
+
cmd << "\\end{longtable}"
|
99
|
+
cmd << "\n" if @crafter
|
100
|
+
return cmd
|
101
|
+
end
|
102
|
+
end
|
103
|
+
#Requires
|
104
|
+
# doc.head << element(:usepackage,{},'longtable')
|
105
|
+
#fixme :width is obligatory
|
106
|
+
class Tabularx < Tabular
|
107
|
+
#Make the key known to the complete key-list of elements.
|
108
|
+
Element.add( [:tabularx], Tabularx )
|
109
|
+
#
|
110
|
+
add_attributes( Element.get_attribute_list( Tabular ) )
|
111
|
+
def to_latex()
|
112
|
+
if @attr[:width].content.to_s == ''
|
113
|
+
puts "Tabularx: Empty width, set it to \\textwidth"
|
114
|
+
@attr[:width] << '\\textwidth'
|
115
|
+
end
|
116
|
+
cmd = ''
|
117
|
+
cmd << "\n" if @crbefore
|
118
|
+
cmd << "\\begin{tabularx}{"
|
119
|
+
cmd << @attr[:width].content.to_s
|
120
|
+
cmd << "}{"
|
121
|
+
cmd << @attr[:columndescription].content.to_s
|
122
|
+
cmd << "}"
|
123
|
+
cmd << "\n" if @crmid
|
124
|
+
cmd << @content.to_s
|
125
|
+
cmd << "\\end{tabularx}"
|
126
|
+
cmd << "\n" if @crafter
|
127
|
+
return cmd
|
128
|
+
end
|
129
|
+
end
|
130
|
+
#May only be used insode a tabular. Tabular must set the columns-value.
|
131
|
+
#If not, zero columns is expected and an error is thrown.
|
132
|
+
class Row < Element
|
133
|
+
|
134
|
+
#Make the key known to the complete key-list of elements.
|
135
|
+
Element.add( [:row, :tr], Row )
|
136
|
+
#~ :tr => {:align=>align},#complete it
|
137
|
+
add_attributes( {
|
138
|
+
:add_vspace => Attribute.create( [:latex] ) ,
|
139
|
+
:bgcolor => Attribute.create( [ :html ] ),
|
140
|
+
:width => Attribute.create( [ :html ] ),
|
141
|
+
:height => Attribute.create( [ :html ] ),
|
142
|
+
#fixme
|
143
|
+
#~ :hline => Attribute.create( [:latex], [true, false] ) ,
|
144
|
+
}.update(HTML_ATTR_ALL) )
|
145
|
+
def initialize( attr={}, content = nil)
|
146
|
+
super
|
147
|
+
#For Ruby 1.9: Initialize instance variable
|
148
|
+
@toprule = false
|
149
|
+
@midrule = false
|
150
|
+
@bottomrule = false
|
151
|
+
@endfirsthead = false
|
152
|
+
@endhead = false
|
153
|
+
@endfoot = false
|
154
|
+
@endlastfoot = false
|
155
|
+
@cline = false
|
156
|
+
@cmidrule = false
|
157
|
+
@hline = false
|
158
|
+
end
|
159
|
+
#Set from tabular
|
160
|
+
attr_accessor :columns
|
161
|
+
#Set a line after the row.
|
162
|
+
def hline(); @hline = element(:hline); self; end
|
163
|
+
#Set line sequences under the fields
|
164
|
+
def cline( val )
|
165
|
+
@cline = [] if ! defined?( @cline )
|
166
|
+
if ! ( /\A\d+-\d+\z/ =~ val )
|
167
|
+
puts "\\cline with wrong parameter: #{val.inspect}"
|
168
|
+
end
|
169
|
+
@cline << val
|
170
|
+
return self
|
171
|
+
end
|
172
|
+
#Toprule requires booktabs.sty
|
173
|
+
def toprule(); @toprule = element(:toprule); self; end
|
174
|
+
#Midrule requires booktabs.sty
|
175
|
+
def midrule(); @midrule = element(:midrule); self; end
|
176
|
+
def cmidrule( val )
|
177
|
+
@cmidrule = [] if ! defined?( @cmidrule )
|
178
|
+
if ! ( /\A\d+-\d+\z/ =~ val )
|
179
|
+
puts "\\cmidrule with wrong parameter: #{val.inspect}"
|
180
|
+
end
|
181
|
+
@cmidrule << val
|
182
|
+
return self
|
183
|
+
end
|
184
|
+
|
185
|
+
#Bottomrule requires booktabs.sty
|
186
|
+
def bottomrule(); @bottomrule = element(:bottomrule); self; end
|
187
|
+
#Only inside a longtable
|
188
|
+
def endhead(); @endhead = element(:endhead); self; end
|
189
|
+
#Only inside a longtable
|
190
|
+
def endfoot(); @endfoot = element(:endfoot); self; end
|
191
|
+
#Only inside a longtable
|
192
|
+
def endfirsthead(); @endfirsthead = element(:endfirsthead); self; end
|
193
|
+
#Only inside a longtable
|
194
|
+
def endlastfoot(); @endlastfoot = element(:endlastfoot); self; end
|
195
|
+
#Only Colums are allowed to be added.
|
196
|
+
#In combination with longtable, captions are also allowed.
|
197
|
+
def << ( row )
|
198
|
+
#Check on allowed elements inside a row
|
199
|
+
allowed = false
|
200
|
+
[ :col, :multicolumn, :caption].each{|el|
|
201
|
+
if row.is_a?( Element.get(el) )
|
202
|
+
allowed = true
|
203
|
+
break
|
204
|
+
end
|
205
|
+
}
|
206
|
+
if ! allowed
|
207
|
+
puts "Add non-column to tabular (#{row.class})"
|
208
|
+
end
|
209
|
+
@content << row
|
210
|
+
#Does not work with multicolumns.
|
211
|
+
if !@columns
|
212
|
+
puts "Add row to tabular with undefined columns number (#{row.inspect})"
|
213
|
+
elsif @content.size > @columns
|
214
|
+
puts "Tabular with #{@columns} columns get #{@content.size} columns"
|
215
|
+
end
|
216
|
+
set_backlink( row )
|
217
|
+
end
|
218
|
+
def inspect()
|
219
|
+
return "<Class Row:#{object_id}> @content={@content.inspect}"
|
220
|
+
end
|
221
|
+
#Each cell is separated by '&'.
|
222
|
+
def to_latex()
|
223
|
+
cmd = ''
|
224
|
+
cmd << "\n" if @crbefore
|
225
|
+
cmd << @content.join(' & ') + Regexp.escape('\\' + '\\')
|
226
|
+
cmd << "[#{@attr[:add_vspace].content.to_s}]" if @attr[:add_vspace].content.size > 0
|
227
|
+
cmd << @hline.to_s if @hline
|
228
|
+
cmd << @toprule.to_s if @toprule
|
229
|
+
cmd << @midrule.to_s if @midrule
|
230
|
+
cmd << @bottomrule.to_s if @bottomrule
|
231
|
+
cmd << @endfirsthead.to_s if @endfirsthead
|
232
|
+
cmd << @endhead.to_s if @endhead
|
233
|
+
cmd << @endfoot.to_s if @endfoot
|
234
|
+
cmd << @endlastfoot.to_s if @endlastfoot
|
235
|
+
@cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
|
236
|
+
@cmidrule.each{|cmidrule| cmd << "\\cmidrule{#{cmidrule}}" } if @cmidrule
|
237
|
+
cmd << "\n" if @crafter
|
238
|
+
return cmd
|
239
|
+
end
|
240
|
+
def htmltag()
|
241
|
+
return 'tr'
|
242
|
+
end
|
243
|
+
def to_html()
|
244
|
+
cmd = ''
|
245
|
+
cmd << "\n" if @crbefore
|
246
|
+
cmd << '<tr '
|
247
|
+
css = @attr[:style].content[0]
|
248
|
+
puts "docgenerator_tabular: style is no CSS #{css.inspect}" if css and ! css.is_a?(CSS)
|
249
|
+
@attr[:style] << css = CSS.new if ! css
|
250
|
+
#Doesn't work. Style sheet setting in tr doesn't go to td
|
251
|
+
if @hline
|
252
|
+
css[:border_bottom_style] = 'solid'
|
253
|
+
css[:border_bottom_width] = 'thick'
|
254
|
+
end
|
255
|
+
# cmd << @toprule.to_s if @toprule
|
256
|
+
# cmd << @midrule.to_s if @midrule
|
257
|
+
# cmd << @bottomrule.to_s if @bottomrule
|
258
|
+
# @cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
|
259
|
+
# cmd << "[#{@attr[:add_vspace].content.to_s}]" if @attr[:add_vspace].content.size > 0
|
260
|
+
|
261
|
+
# cmd << @endfirsthead.to_s if @endfirsthead
|
262
|
+
# cmd << @endhead.to_s if @endhead
|
263
|
+
# cmd << @endfoot.to_s if @endfoot
|
264
|
+
# cmd << @endlastfoot.to_s if @endlastfoot
|
265
|
+
@attr.sort_by{|k,v| v.sortkey }.each{|k,v|
|
266
|
+
cmd << "#{k} = \"#{v}\" " if v.to_s != '' and v.html?
|
267
|
+
}
|
268
|
+
cmd << '>'
|
269
|
+
cmd << "#{@content}"
|
270
|
+
cmd << "\n" if @crmid
|
271
|
+
cmd << '</tr>'
|
272
|
+
cmd << "\n" if @crafter
|
273
|
+
return cmd
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
Element.create( [:hline ], {},false,
|
278
|
+
{ :htmltag => nil,
|
279
|
+
:latex => '\hline '
|
280
|
+
} )
|
281
|
+
Element.create( [:toprule ], {},false,
|
282
|
+
{ :htmltag => nil,
|
283
|
+
:latex => '\toprule'
|
284
|
+
} )
|
285
|
+
Element.create( [:midrule ], {},false,
|
286
|
+
{ :htmltag => nil,
|
287
|
+
:latex => '\midrule'
|
288
|
+
} )
|
289
|
+
Element.create( [:bottomrule ], {},false,
|
290
|
+
{ :htmltag => nil,
|
291
|
+
:latex => '\bottomrule'
|
292
|
+
} )
|
293
|
+
Element.create( [:endfirsthead ], {},false,
|
294
|
+
{ :htmltag => nil,
|
295
|
+
:latex => '\endfirsthead '
|
296
|
+
} )
|
297
|
+
Element.create( [:endhead ], {},false,
|
298
|
+
{ :htmltag => nil,
|
299
|
+
:latex => '\endhead '
|
300
|
+
} )
|
301
|
+
Element.create( [:endfoot ], {},false,
|
302
|
+
{ :htmltag => nil,
|
303
|
+
:latex => '\endfoot'
|
304
|
+
} )
|
305
|
+
Element.create( [:endlastfoot ], {},false,
|
306
|
+
{ :htmltag => nil,
|
307
|
+
:latex => '\endlastfoot'
|
308
|
+
} )
|
309
|
+
#~ @cline.each{|cline| cmd << "\\cline{#{cline}}" } if @cline
|
310
|
+
|
311
|
+
|
312
|
+
#One column in a tabular.
|
313
|
+
class Column < Element
|
314
|
+
#Make the key known to the complete key-list of elements.
|
315
|
+
#~ :th => {:colspan => nil, :rowspan => nil, :align=>align, :valign=>valign, :border=>nil, :width=>nil},#complete it
|
316
|
+
#~ :td => nil, #like :th
|
317
|
+
Element.add( [:col, :column, :td, :th], Column )
|
318
|
+
add_attributes( HTML_ATTR_ALL )
|
319
|
+
add_attributes( {
|
320
|
+
:width => Attribute.create( [ :html ] ),
|
321
|
+
:height => Attribute.create( [ :html ] ),
|
322
|
+
:align => HTML_ATTR_ALIGN,
|
323
|
+
:bgcolor => Attribute.create( [ :html ] ),
|
324
|
+
} )
|
325
|
+
def to_latex()
|
326
|
+
cmd = ''
|
327
|
+
cmd << "\n" if @crbefore
|
328
|
+
cmd << "#{@content}"
|
329
|
+
cmd << "\n" if @crafter
|
330
|
+
return cmd
|
331
|
+
end
|
332
|
+
def content?; :empty_ok; end
|
333
|
+
def htmltag()
|
334
|
+
# fixme th for head
|
335
|
+
return 'td'
|
336
|
+
end
|
337
|
+
def inspect()
|
338
|
+
return "<Class Column @content=#{@content.inspect}>"
|
339
|
+
end
|
340
|
+
end
|
341
|
+
class Multicolumn < Column
|
342
|
+
#Make the key known to the complete key-list of elements.
|
343
|
+
Element.add( [:multicolumn], Multicolumn )
|
344
|
+
#~ add_attributes( HTML_ATTR_ALL )
|
345
|
+
add_attributes( {
|
346
|
+
#~ :columns => Attribute.create( [:required], [ Fixnum ] ) , #colspan
|
347
|
+
:columns => Attribute.create( [:required, :html, :latex], [ Fixnum ], 2 ) , #colspan
|
348
|
+
:colspan => :columns,
|
349
|
+
:rowspan => Attribute.create( [:html ], [ Fixnum ], 2 ),
|
350
|
+
:pos => Attribute.create( [:latex] ) ,
|
351
|
+
:align => HTML_ATTR_ALIGN,
|
352
|
+
:width => Attribute.create( [ :html ] ),
|
353
|
+
:height => Attribute.create( [ :html ] ),
|
354
|
+
}.update( HTML_ATTR_ALL ) )
|
355
|
+
def to_latex()
|
356
|
+
cmd = ''
|
357
|
+
cmd << "\n" if @crbefore
|
358
|
+
cmd << "\\multicolumn{#{@attr[:columns]}}{#{@attr[:pos]}}{#{@content}}"
|
359
|
+
cmd << "\n" if @crafter
|
360
|
+
return cmd
|
361
|
+
end
|
362
|
+
#~ def htmltag()
|
363
|
+
#~ return 'td'
|
364
|
+
#~ end
|
365
|
+
#~ def to_html()
|
366
|
+
#~ cmd = ''
|
367
|
+
#~ cmd += "\n" if @crbefore
|
368
|
+
#~ cmd += "<td colspan=\"#{@attr[:columns]}\">"
|
369
|
+
#~ cmd += "#{@content}</td>"
|
370
|
+
#~ cmd += "\n" if @crafter
|
371
|
+
#~ return cmd
|
372
|
+
#~ end
|
373
|
+
def inspect()
|
374
|
+
return "<Class Multicolumn @content=#{@content.inspect}>"
|
375
|
+
end
|
376
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
require 'DocGenerator'
|
3
|
+
end
|
4
|
+
|
5
|
+
class DocumentTemplate
|
6
|
+
@@templates = {}
|
7
|
+
def DocumentTemplate.add_template( key, target, template)
|
8
|
+
@@templates[key] = template.gsub(/^\t*/, '') #fixme check uniqi
|
9
|
+
case target
|
10
|
+
when nil
|
11
|
+
when :latex
|
12
|
+
SUPPORTED_LaTeX_TEMPLATES << key
|
13
|
+
when :html
|
14
|
+
SUPPORTED_HTML_TEMPLATES << key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def DocumentTemplate.[]( key )
|
18
|
+
if @@templates[key]
|
19
|
+
return @@templates[key].dup
|
20
|
+
else
|
21
|
+
puts "Template unknown: #{key}"
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def DocumentTemplate.keys()
|
26
|
+
return @@templates.keys
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
DocumentTemplate.add_template(
|
32
|
+
:include, :latex, %q|<<prefix>>
|
33
|
+
% ----------------------------------------------------------------
|
34
|
+
<<head>>
|
35
|
+
% ----------------------------------------------------------------
|
36
|
+
<<body>>
|
37
|
+
% ----------------------------------------------------------------
|
38
|
+
|)
|
39
|
+
|
40
|
+
DocumentTemplate.add_template(
|
41
|
+
:article, :latex, %q|<<prefix>>
|
42
|
+
\documentclass[<<classoptions>>]{scrartcl}
|
43
|
+
\usepackage{babel}
|
44
|
+
\usepackage[ansinew]{inputenc}
|
45
|
+
\usepackage{hyperref}
|
46
|
+
% ----------------------------------------------------------------
|
47
|
+
<<head>>
|
48
|
+
% ----------------------------------------------------------------
|
49
|
+
\begin{document}
|
50
|
+
<<body>>
|
51
|
+
\end{document}
|
52
|
+
% ----------------------------------------------------------------
|
53
|
+
|)
|
54
|
+
#~ DocumentTemplate.add_template(
|
55
|
+
#~ :report, '',
|
56
|
+
#~ |)
|
57
|
+
#~ DocumentTemplate.add_template(
|
58
|
+
#~ :book, '',
|
59
|
+
#~ |)
|
60
|
+
|
61
|
+
#~ <!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
62
|
+
|
63
|
+
DocumentTemplate.add_template(
|
64
|
+
:html, :html, %q|<!--
|
65
|
+
<<prefix>>
|
66
|
+
-->
|
67
|
+
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
|
68
|
+
<html>
|
69
|
+
<<head>>
|
70
|
+
<<body>>
|
71
|
+
</html>
|
72
|
+
|)
|
73
|
+
|
74
|
+
{
|
75
|
+
:xhtml_strict => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
76
|
+
:xhtml_trans => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
77
|
+
:html401_strict => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
78
|
+
:html401_trans => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
79
|
+
}.each{ |key, doctype|
|
80
|
+
DocumentTemplate.add_template(
|
81
|
+
key, :html, %Q|<!--
|
82
|
+
<<prefix>>
|
83
|
+
-->
|
84
|
+
#{doctype}
|
85
|
+
<html>
|
86
|
+
|
87
|
+
<<head>>
|
88
|
+
|
89
|
+
<<body>>
|
90
|
+
</html>
|
91
|
+
|)
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
DocumentTemplate.add_template(
|
97
|
+
:text, :text, %q|
|
98
|
+
<<body>>
|
99
|
+
|)
|
100
|
+
DocumentTemplate.add_template(
|
101
|
+
:wiki, :wiki, %q|
|
102
|
+
<<body>>
|
103
|
+
|)
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#Create a test-document with docgenerator.rb.
|
2
|
+
#
|
3
|
+
#This program loads docgenerator.rb and
|
4
|
+
#use most of the features of the tool.
|
5
|
+
#
|
6
|
+
#Start the tool and two documents
|
7
|
+
#- test.html and
|
8
|
+
#- test.tex
|
9
|
+
#are created.
|
10
|
+
|
11
|
+
#~ require 'rubygems'
|
12
|
+
$: << ".." #for local tests with uninstalled gem
|
13
|
+
require 'docgenerator'
|
14
|
+
with_error = false
|
15
|
+
#~ with_error = true #Include some "wrong" statements. You will get a message from docgenerator
|
16
|
+
|
17
|
+
##############
|
18
|
+
## Test
|
19
|
+
##############
|
20
|
+
puts '='*40
|
21
|
+
#~ puts Element.overview( [Element.get(:h1)] )
|
22
|
+
#~ puts Element.overview( [Title] )
|
23
|
+
#~ puts Element.overview( )
|
24
|
+
#~ puts '='*40
|
25
|
+
|
26
|
+
puts ">Create a test-document"
|
27
|
+
doc = Document.new()
|
28
|
+
doc.add_option('ngerman')
|
29
|
+
|
30
|
+
doc.head << element( :usepackage, { }, 'longtable' )
|
31
|
+
#~ doc.head << element( :usepackage, { :option => [] }, 'longtable' )
|
32
|
+
doc.head << element( :sepline ) #Separator line
|
33
|
+
|
34
|
+
|
35
|
+
#~ doc.head << element(:title, {}, 'Titel')
|
36
|
+
#~ doc.head << element(:author, {}, 'Authorname')
|
37
|
+
doc.title ='Titel'
|
38
|
+
doc.author = 'Authorname'
|
39
|
+
doc.date = 'Datum'
|
40
|
+
doc.keywords = 'Test, DocGenerator.rb'
|
41
|
+
doc.description = 'Testdokument f�r DocGenerator.rb'
|
42
|
+
|
43
|
+
doc.head << element(:meta, {:name => 'xxx', :content => 'inhalt' } )
|
44
|
+
if with_error
|
45
|
+
puts '!And at <save> an error: Meta-Tag without required attributes'
|
46
|
+
doc.head << element(:meta, {} )
|
47
|
+
end
|
48
|
+
|
49
|
+
doc.body << element(:maketitle)
|
50
|
+
doc.body[:lang] << 'de'
|
51
|
+
|
52
|
+
# ###############################
|
53
|
+
def listen()
|
54
|
+
listen = []
|
55
|
+
listen << element(:h1, {}, 'Listen')
|
56
|
+
|
57
|
+
listen << element(:h2, {}, 'Unnummerierte Liste')
|
58
|
+
listen << ul = element(:ul)
|
59
|
+
ul << element( :li, {}, 'Listitem 1' )
|
60
|
+
ul << element( :li, {}, 'Listitem 2' )
|
61
|
+
ul << element( :li, {}, 'Listitem 3' )
|
62
|
+
|
63
|
+
listen << element(:h2, {}, 'Nummerierte Liste')
|
64
|
+
listen << ol = element(:ol)
|
65
|
+
ol << element( :li, {}, 'Listitem 1' )
|
66
|
+
ol << element( :li, {}, 'Listitem 2' )
|
67
|
+
ol << element( :li, {}, 'Listitem 3' )
|
68
|
+
return listen
|
69
|
+
end
|
70
|
+
doc.body << listen
|
71
|
+
|
72
|
+
# ###############################
|
73
|
+
doc.body << element(:h1, {}, 'Absatzsteuerung').cr
|
74
|
+
doc.body << 'Text'
|
75
|
+
doc.body << element( :br ).cr
|
76
|
+
doc.body << 'Text'
|
77
|
+
if with_error
|
78
|
+
puts '!And now an error: Content added to makro without content'
|
79
|
+
doc.body << element( :br, {}, 'Text in br' ).cr
|
80
|
+
end
|
81
|
+
|
82
|
+
# ###############################
|
83
|
+
doc.body << element(:h1, {}, 'Links und Verweise').cr
|
84
|
+
doc.body << element(:a, { :href => 'http://ruby.lickert.net/' }, 'Link zu meinen Skripten').cr
|
85
|
+
doc.body << element(:url,{}, 'http://ruby.lickert.net/')
|
86
|
+
|
87
|
+
|
88
|
+
# ###############################
|
89
|
+
doc.body << element(:h1, {}, 'Relatives einf�gen').cr
|
90
|
+
doc.body << par = element(:par, {}, 'Absatz')
|
91
|
+
|
92
|
+
doc.body.insertbefore( par, 'Einschub vor dem Absatz' )
|
93
|
+
doc.body.insertafter( par, 'Einschub nach dem Absatz' )
|
94
|
+
|
95
|
+
if with_error
|
96
|
+
puts "!And now an error: insertbefore with a non-existing target"
|
97
|
+
doc.body.insertbefore( 'a', 'Before List' )
|
98
|
+
end
|
99
|
+
|
100
|
+
# ###############################
|
101
|
+
doc.body << element(:h1, {}, 'Tabellen').cr
|
102
|
+
columnnumber = 5
|
103
|
+
doc.body << tab = element(:tabular, {
|
104
|
+
:columns => columnnumber,
|
105
|
+
:columndescription => 'c' * columnnumber
|
106
|
+
} ).CR
|
107
|
+
|
108
|
+
tab << row = element( :row, {:add_vspace=>'1ex'} ).cr
|
109
|
+
row << element(:multicolumn, {
|
110
|
+
:columns => columnnumber,
|
111
|
+
:pos => 'c',
|
112
|
+
}, 'Titel' )
|
113
|
+
row.hline
|
114
|
+
|
115
|
+
'a'.upto('f'){|num|
|
116
|
+
tab << row = element( :row ).cr
|
117
|
+
1.upto(columnnumber){|letter|
|
118
|
+
row << element(:column, {}, "#{num}#{letter}" )
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
def footnote( )
|
124
|
+
txt = []
|
125
|
+
|
126
|
+
txt << element(:h1, {}, 'Fu�noten').cr
|
127
|
+
txt << element(:h2, {}, 'Standardfu�noten').cr
|
128
|
+
txt << 'a'
|
129
|
+
txt << f = element(:footnote,{}, 'eins')
|
130
|
+
txt << 'b'
|
131
|
+
txt << element(:footnote,{}, 'zwei')
|
132
|
+
txt << ' nochmal erste Fu�note'
|
133
|
+
txt << f
|
134
|
+
txt << 'z'
|
135
|
+
|
136
|
+
txt << element(:h2, {}, 'Fu�noten in eigener Gruppe 1').cr
|
137
|
+
txt << 'a'
|
138
|
+
txt << f = element(:footnote,{:groupid=>1}, 'Fu�note eins/Gruppe 1')
|
139
|
+
txt << 'b'
|
140
|
+
txt << element(:footnote,{:groupid=>1}, 'Fu�note zwei/Gruppe 1')
|
141
|
+
txt << 'c'
|
142
|
+
txt << f
|
143
|
+
txt << 'z'
|
144
|
+
|
145
|
+
txt << element(:h2, {}, 'Fortsetzung').cr
|
146
|
+
txt << 'a'
|
147
|
+
txt << f = element(:footnote,{}, 'drei')
|
148
|
+
txt << 'b'
|
149
|
+
txt << element(:footnote,{}, 'vier')
|
150
|
+
txt << 'c'
|
151
|
+
txt << f
|
152
|
+
txt << 'z'
|
153
|
+
|
154
|
+
txt << element(:hr).cr
|
155
|
+
Footnotegroup.get.attr={:style=>'font-size: smaller'}
|
156
|
+
txt << Footnotegroup.get()
|
157
|
+
txt << element(:hr)
|
158
|
+
Footnotegroup.get( 1 ).html_link = false #Footnote are not linked
|
159
|
+
txt << Footnotegroup.get(1)
|
160
|
+
return txt
|
161
|
+
end
|
162
|
+
doc.body << footnote
|
163
|
+
|
164
|
+
# ##############
|
165
|
+
#~ Element.log = true #Write Errors to stdout
|
166
|
+
#~ doc.save( 'test.html', true )
|
167
|
+
|
168
|
+
doc.body << element(:h1, {}, 'Restrict to different Output formats').cr
|
169
|
+
doc.body << element(:p, {}, 'When you create simultanous output to LaTeX and HTML, perhaps you need some parts only in one output document.')
|
170
|
+
doc.body << element(:p, {}, 'Only in HTML').restrict_to(:html)
|
171
|
+
doc.body << element(:htmlonly, {}, 'Only in HTML')
|
172
|
+
doc.body << element(:p, {}, 'Only in LaTeX').restrict_to(:latex)
|
173
|
+
doc.body << element(:latexonly, {}, 'Only in LaTeX')
|
174
|
+
|
175
|
+
|
176
|
+
# ###############################
|
177
|
+
doc.body << element(:h1, {}, 'Ende').cr
|
178
|
+
|
179
|
+
# ###############################
|
180
|
+
puts ">Save the files"
|
181
|
+
|
182
|
+
#~ Element.log = true #Write Errors to stdout
|
183
|
+
doc.save( 'test_docgenerator.html', true )
|
184
|
+
doc.runtex = true
|
185
|
+
doc.save( 'test_docgenerator.tex', true )
|