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,106 @@
|
|
1
|
+
#
|
2
|
+
# Footnotes
|
3
|
+
#
|
4
|
+
class Footnote < Element
|
5
|
+
@@group = Hash.new()
|
6
|
+
Element.add( [:footnote ], Footnote)
|
7
|
+
add_attributes( {
|
8
|
+
:counter => Attribute.create(),
|
9
|
+
:groupid => Attribute.create()
|
10
|
+
}.update(HTML_ATTR_ALL)
|
11
|
+
)
|
12
|
+
def counter()
|
13
|
+
if ! @attr[:counter].filled?
|
14
|
+
groupid = @attr[:groupid].content[0]
|
15
|
+
if ! @@group[groupid]
|
16
|
+
@@group[groupid] = Footnotegroup.get( groupid )
|
17
|
+
end
|
18
|
+
@@group[groupid] << self
|
19
|
+
@attr[:counter] << @@group[groupid].size
|
20
|
+
end
|
21
|
+
return @attr[:counter]
|
22
|
+
end
|
23
|
+
def to_html( )
|
24
|
+
cmd = ''
|
25
|
+
cmd << "\n" if @crbefore
|
26
|
+
if Footnotegroup.get( @attr[:groupid].content[0] ).html_link
|
27
|
+
cmd << "<sup><a href=\"#foot#{counter}\">#{counter}</a></sup>"
|
28
|
+
else
|
29
|
+
cmd << "<sup>#{counter}</sup>"
|
30
|
+
end
|
31
|
+
cmd << "\n" if @crafter
|
32
|
+
return cmd
|
33
|
+
end
|
34
|
+
def to_latex( )
|
35
|
+
cmd = ''
|
36
|
+
cmd << "\n" if @crbefore
|
37
|
+
cmd << "\\footnote{#{@content}}"
|
38
|
+
cmd << "\n" if @crafter
|
39
|
+
return cmd
|
40
|
+
end
|
41
|
+
def to_text()
|
42
|
+
return '#{linebreak(@crbefore)}' + "- #{@content}" + ' #{linebreak(@crafter)}'
|
43
|
+
end
|
44
|
+
def get_content()
|
45
|
+
return @content
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Footnotegroup
|
50
|
+
@@all = { }
|
51
|
+
#Use
|
52
|
+
# Footnotegroup.get
|
53
|
+
#to get the collected footnotes.
|
54
|
+
#It is not a good idea to use this with LaTeX, because LaTeX makes it automatic.
|
55
|
+
#(But you can try it with tables.
|
56
|
+
def self.get( groupid = nil )
|
57
|
+
if ! @@all[groupid]
|
58
|
+
@@all[groupid] = self.new( groupid )
|
59
|
+
end
|
60
|
+
return @@all[groupid]
|
61
|
+
end
|
62
|
+
def initialize( groupid )
|
63
|
+
@groupid = groupid
|
64
|
+
@footnotes = []
|
65
|
+
@attr = {}
|
66
|
+
@html_link = true
|
67
|
+
end
|
68
|
+
#Flag, if the footnote and the footnote mark should be linked.
|
69
|
+
attr_accessor :html_link
|
70
|
+
def attr=( attr )
|
71
|
+
@attr = attr
|
72
|
+
end
|
73
|
+
def <<( footnote )
|
74
|
+
@footnotes << footnote
|
75
|
+
end
|
76
|
+
def size()
|
77
|
+
return @footnotes.size
|
78
|
+
end
|
79
|
+
def to_s()
|
80
|
+
return '' if @footnotes.size == 0
|
81
|
+
ul = element(:p, @attr ).cr
|
82
|
+
@footnotes.each{|f|
|
83
|
+
#~ ul << element(:sup, {}, f.counter )
|
84
|
+
ul << footnotemark = element(:sup )
|
85
|
+
if @html_link
|
86
|
+
footnotemark << element(:label, { :name => "foot#{f.counter}" }, f.counter )
|
87
|
+
else
|
88
|
+
footnotemark << f.counter
|
89
|
+
end
|
90
|
+
ul << f.get_content
|
91
|
+
ul << element(:br).cr
|
92
|
+
}
|
93
|
+
return ul.to_s
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
Element.create( [:footnotemark ], {}.update(HTML_ATTR_ALL),true,
|
99
|
+
{ :htmltag => 'sup',
|
100
|
+
:latex => '#{linebreak(@crbefore)}\footnotemark[#{@content}]#{linebreak(@crafter)}' #fixme
|
101
|
+
} )
|
102
|
+
|
103
|
+
|
104
|
+
__END__
|
105
|
+
txt << f = element(:footnote,{:groupid=>1}, 'eins/Gruppe 1')
|
106
|
+
txt << Footnotegroup.get()
|
@@ -0,0 +1,163 @@
|
|
1
|
+
|
2
|
+
#Generell class for list environments
|
3
|
+
class ListEnvironment < Environment
|
4
|
+
add_attributes( HTML_ATTR_ALL )
|
5
|
+
#Only items are allowed to be added.
|
6
|
+
#
|
7
|
+
#If an array is given, each item is added on it
|
8
|
+
def << ( item)
|
9
|
+
if item.is_a?(Array)
|
10
|
+
item.each{|it| self << it }
|
11
|
+
else
|
12
|
+
if self.class == Description
|
13
|
+
#fixme: Reihenfolge
|
14
|
+
if ! ( item.is_a?( Element.get(:dt) ) or item.is_a?( Element.get(:dd) ) )
|
15
|
+
puts "Add non-item to list (#{item.class} #{@called_by})"
|
16
|
+
end
|
17
|
+
elsif ! item.is_a?( Element.get(:item) )
|
18
|
+
puts "Add non-item to list (#{item.class} #{@called_by})"
|
19
|
+
end
|
20
|
+
@content << item
|
21
|
+
set_backlink( item )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def to_wiki( )
|
25
|
+
res = "#{@content}\n"
|
26
|
+
return res.gsub(/\n\n/, "\n")
|
27
|
+
end
|
28
|
+
alias :to_text :to_wiki
|
29
|
+
end
|
30
|
+
class Itemize < ListEnvironment
|
31
|
+
add_attributes( HTML_ATTR_ALL )
|
32
|
+
Element.add( [:ul, :itemize], Itemize)
|
33
|
+
def htmltag(); 'ul'; end
|
34
|
+
def to_latex( )
|
35
|
+
return to_latex_environment( 'itemize' )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
class Enumerate < ListEnvironment
|
39
|
+
add_attributes( HTML_ATTR_ALL )
|
40
|
+
Element.add( [:ol, :enumerate], Enumerate)
|
41
|
+
def htmltag(); 'ol'; end
|
42
|
+
def to_latex( )
|
43
|
+
return to_latex_environment( 'enumerate' )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
#
|
47
|
+
#
|
48
|
+
#HTML:
|
49
|
+
# <dl>
|
50
|
+
# <dt> <dd>
|
51
|
+
# </dl>
|
52
|
+
class Description < ListEnvironment
|
53
|
+
add_attributes( HTML_ATTR_ALL )
|
54
|
+
Element.add( [:description, :dl], Description)
|
55
|
+
def htmltag(); 'dl'; end
|
56
|
+
def to_latex( )
|
57
|
+
return to_latex_environment( 'description' )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
#Item line in a list.
|
63
|
+
#The look will be defined by the environment where it is in (itemize/ul, enumerate/ol)
|
64
|
+
#
|
65
|
+
#bug to_html
|
66
|
+
class Item < Element
|
67
|
+
Element.add( [:li, :item], Item)
|
68
|
+
add_attributes( {
|
69
|
+
:text => Attribute.create( [ :latex ] )
|
70
|
+
}.update(HTML_ATTR_ALL)
|
71
|
+
)
|
72
|
+
def htmltag(); 'li'; end
|
73
|
+
def to_latex( )
|
74
|
+
cmd = ''
|
75
|
+
cmd << "\n" if @crbefore
|
76
|
+
cmd << "\n\\item "
|
77
|
+
cmd << "[#{@attr[:text]}] " if @attr[:text].filled?
|
78
|
+
cmd << @content.to_s
|
79
|
+
cmd << "\n" if @crafter
|
80
|
+
return cmd
|
81
|
+
end
|
82
|
+
def to_text()
|
83
|
+
cmd = ''
|
84
|
+
cmd << "\n" if @crbefore
|
85
|
+
cmd << "- #{@content}"
|
86
|
+
cmd << "\n" if @crafter
|
87
|
+
return cmd
|
88
|
+
end
|
89
|
+
#fixme geschachtete
|
90
|
+
#- ** auf stufe 2
|
91
|
+
#- kein * wenn als n�chstes eine Liste kommt.
|
92
|
+
def to_wiki()
|
93
|
+
cmd = ''
|
94
|
+
#~ puts part_of.inspect
|
95
|
+
if part_of.size != 1
|
96
|
+
puts ":li/wiki: Unclear list type #{part_of.inspect}"
|
97
|
+
else
|
98
|
+
list = part_of[0]
|
99
|
+
end
|
100
|
+
#~ cmd << "\n" if @crbefore
|
101
|
+
case list.class.to_s.to_sym
|
102
|
+
when :Itemize
|
103
|
+
cmd << "\n* #{@content}"
|
104
|
+
when :Enumerate
|
105
|
+
cmd << "\n# #{@content}"
|
106
|
+
else
|
107
|
+
puts ":li/wiki: Unknown list type #{part_of.inspect}"
|
108
|
+
cmd << "\n* #{@content}"
|
109
|
+
end
|
110
|
+
#~ cmd << "\n" if cmd[-1,1] != "\n"
|
111
|
+
cmd << "\n" if @crafter and cmd[-1,1] != "\n"
|
112
|
+
return cmd
|
113
|
+
end
|
114
|
+
end #Item
|
115
|
+
|
116
|
+
#HTML:
|
117
|
+
# <dl>
|
118
|
+
# <dt> <dd>
|
119
|
+
# </dl>
|
120
|
+
class DT < Element
|
121
|
+
Element.add( [:dt], DT)
|
122
|
+
add_attributes( HTML_ATTR_ALL )
|
123
|
+
def htmltag(); 'dt'; end
|
124
|
+
def to_text(); "\n#{@content}: " end
|
125
|
+
def to_wiki()
|
126
|
+
cmd = ''
|
127
|
+
cmd << "\n" if @crbefore
|
128
|
+
cmd << "\n;#{@content}"
|
129
|
+
cmd << "\n"
|
130
|
+
return cmd
|
131
|
+
end
|
132
|
+
def to_latex( )
|
133
|
+
cmd = ''
|
134
|
+
cmd << "\n" if @crbefore
|
135
|
+
cmd << "\n\\item[#{@content}] "
|
136
|
+
cmd << "\n" if @crafter
|
137
|
+
return cmd
|
138
|
+
end
|
139
|
+
end
|
140
|
+
#HTML:
|
141
|
+
# <dl>
|
142
|
+
# <dt> <dd>
|
143
|
+
# </dl>
|
144
|
+
class DD < Element
|
145
|
+
Element.add( [:dd], DD)
|
146
|
+
add_attributes( HTML_ATTR_ALL )
|
147
|
+
def htmltag(); 'dd'; end
|
148
|
+
def to_text(); "\n\t#{@content}\n" end
|
149
|
+
def to_wiki()
|
150
|
+
cmd = ''
|
151
|
+
cmd << "\n" if @crbefore
|
152
|
+
cmd << "\n:#{@content}"
|
153
|
+
cmd << "\n"
|
154
|
+
return cmd
|
155
|
+
end
|
156
|
+
def to_latex( )
|
157
|
+
cmd = ''
|
158
|
+
cmd << "\n" if @crbefore
|
159
|
+
cmd << " #{@content} "
|
160
|
+
cmd << "\n" if @crafter
|
161
|
+
return cmd
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#
|
2
|
+
#Headings and sectioning
|
3
|
+
#
|
4
|
+
|
5
|
+
#Small helper to make TeX-Hyperlinks like in HTML (attribute id)
|
6
|
+
def hypertarget(id)
|
7
|
+
return "\\hypertarget{#{id}}{}" if id.is_a?(String)
|
8
|
+
return '' if ! id.content or id.content.to_s =~/\A\s*\Z/
|
9
|
+
return "\\hypertarget{#{id}}{}"
|
10
|
+
end
|
11
|
+
|
12
|
+
#Fixmes:
|
13
|
+
#- addsec
|
14
|
+
#- article/report
|
15
|
+
sect = Struct.new( 'Sections', :keys, :wiki, :html, :tex )
|
16
|
+
[
|
17
|
+
sect.new( [:part], 0, '', 'part'), #fixme: neue HTML-Datei?
|
18
|
+
sect.new( [:chapter], 1, '', 'chapter'), #fixme: neue HTML-Datei?
|
19
|
+
sect.new( [:h1, :section], 2, 'h1', 'section'),
|
20
|
+
sect.new( [:h2, :subsection], 3, 'h2', 'subsection'),
|
21
|
+
sect.new( [:h3, :subsubsection], 4, 'h3', 'subsubsection'),
|
22
|
+
sect.new( [:h4, :paragraph], 5, 'h4', 'paragraph'),
|
23
|
+
sect.new( [:h5, :subparagraph], 6, 'h5', 'subparagraph'),
|
24
|
+
sect.new( [:minisec], 7, 'h5', 'minisec'),
|
25
|
+
].each{ |s|
|
26
|
+
Element.create( s.keys, {
|
27
|
+
:short => Attribute.create( [ :latex ] ),
|
28
|
+
}.update( HTML_ATTR_ALL), true,
|
29
|
+
{ :htmltag => s.html,
|
30
|
+
#~ :latex => '#{linebreak(@crbefore)}' + "\\#{s.tex}" + '{#{@content}}#{linebreak(@crafter)}',
|
31
|
+
:latex => '#{linebreak(@crbefore)}' + "\\#{s.tex}" +
|
32
|
+
'#{texoptional(:short)}' +
|
33
|
+
'{#{@content}}' +
|
34
|
+
'#{hypertarget(@attr[:id])}' +
|
35
|
+
'#{linebreak(@crafter)}',
|
36
|
+
:text => "\n" + '#{linebreak(@before)}#{@content}' + "\n" +
|
37
|
+
' ' * s.wiki * 2 + '-' * 30 + "\n" + '#{linebreak(@crafter)}',
|
38
|
+
:wiki => '#{linebreak(@crbefore)}' + "\n" + '='* (s.wiki ) + '#{@content}' + '='* (s.wiki) + "\n" + '#{linebreak(@crafter)}',
|
39
|
+
} )
|
40
|
+
}
|
41
|
+
#~ Element.create( [:h1], HTML_ATTR_ALL, true,
|
42
|
+
#~ { :htmltag => 'h1',
|
43
|
+
#~ :latex => "\n" + '\section{#{@content}}' + "\n"
|
44
|
+
#~ } )
|
45
|
+
#~ Element.create( [:h2], HTML_ATTR_ALL, true,
|
46
|
+
#~ { :htmltag => 'h2',
|
47
|
+
#~ :latex => "\n" + '\subsection{#{@content}}' + "\n"
|
48
|
+
#~ } )
|
49
|
+
|
50
|
+
Element.create( [:addsec], HTML_ATTR_ALL, true,
|
51
|
+
{ :htmltag => 'h2',
|
52
|
+
:latex => '#{linebreak(@crbefore)}' + '\addsec{#{@content}}' + '#{linebreak(@crafter)}'
|
53
|
+
} )
|
54
|
+
|
55
|
+
|
56
|
+
class Caption < Element
|
57
|
+
#Make the key known to the complete key-list of elements.
|
58
|
+
Element.add( [:caption], Caption )
|
59
|
+
#
|
60
|
+
add_attributes( {
|
61
|
+
:optional => Attribute.create( [ :latex ] ),
|
62
|
+
} )
|
63
|
+
def to_latex()
|
64
|
+
cmd = ''
|
65
|
+
cmd << "\n" if @crbefore
|
66
|
+
cmd << "\\caption"
|
67
|
+
if @attr[:optional].content != []
|
68
|
+
cmd << "["
|
69
|
+
cmd << @attr[:optional].content.to_s
|
70
|
+
cmd << "]"
|
71
|
+
cmd << "\n\t" if @crmid
|
72
|
+
end
|
73
|
+
cmd << "{"
|
74
|
+
cmd << @content.to_s
|
75
|
+
cmd << "}"
|
76
|
+
cmd << "\n" if @crafter
|
77
|
+
return cmd
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Abstract < Environment
|
82
|
+
#~ add_attributes( HTML_ATTR_ALL )
|
83
|
+
Element.add( [:abstract], Abstract)
|
84
|
+
#~ def htmltag(); ''; end
|
85
|
+
def to_latex( )
|
86
|
+
return to_latex_environment( 'abstract' )
|
87
|
+
end
|
88
|
+
end
|