docgenerator 1.0.4 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/creole/creole2doc.rb +777 -0
- data/lib/creole/creole_inclusion_and_plugins.rb +236 -0
- data/lib/creole/creole_placeholder.rb +74 -0
- data/lib/creole/creole_tabular.rb +170 -0
- data/lib/docgenerator.rb +15 -6
- data/lib/docgenerator_attribute.rb +2 -2
- data/lib/docgenerator_characters.rb +20 -4
- data/lib/docgenerator_document.rb +132 -42
- data/lib/docgenerator_element.rb +531 -524
- data/lib/docgenerator_elements.rb +408 -399
- data/lib/docgenerator_environments.rb +28 -2
- data/lib/docgenerator_footnote.rb +72 -79
- data/lib/docgenerator_sections.rb +1 -1
- data/lib/docgenerator_tabular.rb +8 -3
- data/lib/packages/docgenerator_beamer.rb +253 -0
- data/lib/packages/docgenerator_scrlettr2.rb +53 -9
- data/lib/templates/docgenerator_template_css.rb +4 -0
- data/lib/wiki2doc/wiki2docgenerator.rb +1087 -970
- data/lib/yaml2presentation/yaml2presentation.rb +1091 -0
- data/self_docgenerator.rb +8 -6
- data/unittest/Red_Flower.jpg +0 -0
- data/unittest/creole1.0test.txt +128 -0
- data/unittest/expected/beamer_01_doc.html +1 -1
- data/unittest/expected/beamer_02_doc.html +1 -1
- data/unittest/expected/beamer_doc_html_overview_with_detailpic_and_text_doc.html +34 -0
- data/unittest/expected/beamer_doc_html_overview_with_detailpic_doc.html +34 -0
- data/unittest/expected/beamer_doc_key_doc.html +1 -1
- data/unittest/expected/beamer_doc_note_doc.html +1 -1
- data/unittest/expected/beamer_doc_pic_bottom_doc.html +1 -1
- data/unittest/expected/beamer_doc_pic_doc.html +1 -1
- data/unittest/expected/beamer_doc_pic_left_doc.html +1 -1
- data/unittest/expected/beamer_doc_pic_right_doc.html +1 -1
- data/unittest/expected/beamer_doc_pic_top_doc.html +1 -1
- data/unittest/expected/test_footnote.html +2 -2
- data/unittest/expected/test_footnote.latex +1 -1
- data/unittest/expected/test_footnote_group.html +3 -3
- data/unittest/expected/test_footnote_group.latex +2 -2
- data/unittest/expected_creole/test_creole.html +3 -0
- data/unittest/expected_creole/test_creole_characters_all.html +10 -0
- data/unittest/expected_creole/test_creole_characters_all.latex +20 -0
- data/unittest/expected_creole/test_creole_characters_special.html +10 -0
- data/unittest/expected_creole/test_creole_characters_special.latex +18 -0
- data/unittest/expected_creole/test_creole_countdown.html +3 -0
- data/unittest/expected_creole/test_creole_countdown.latex +4 -0
- data/unittest/expected_creole/test_creole_creole1.0test.html +182 -0
- data/unittest/expected_creole/test_creole_creole1.0test.latex +253 -0
- data/unittest/expected_creole/test_creole_creole1.0test.text +160 -0
- data/unittest/expected_creole/test_creole_footnotes.html +9 -0
- data/unittest/expected_creole/test_creole_footnotes.latex +14 -0
- data/unittest/expected_creole/test_creole_footnotes_label.html +9 -0
- data/unittest/expected_creole/test_creole_headings.html +17 -0
- data/unittest/expected_creole/test_creole_headings.latex +19 -0
- data/unittest/expected_creole/test_creole_headings.text +48 -0
- data/unittest/expected_creole/test_creole_headings.wiki +37 -0
- data/unittest/expected_creole/test_creole_hr.html +7 -0
- data/unittest/expected_creole/test_creole_hr.latex +9 -0
- data/unittest/expected_creole/test_creole_hr.text +4 -0
- data/unittest/expected_creole/test_creole_inline.html +3 -0
- data/unittest/expected_creole/test_creole_inline.latex +4 -0
- data/unittest/expected_creole/test_creole_inline.text +2 -0
- data/unittest/expected_creole/test_creole_inline_ruby.html +12 -0
- data/unittest/expected_creole/test_creole_inline_ruby.latex +20 -0
- data/unittest/expected_creole/test_creole_inline_ruby_raw.html +6 -0
- data/unittest/expected_creole/test_creole_inline_ruby_raw.latex +8 -0
- data/unittest/expected_creole/test_creole_input.normsource +23 -0
- data/unittest/expected_creole/test_creole_label.html +12 -0
- data/unittest/expected_creole/test_creole_label.latex +15 -0
- data/unittest/expected_creole/test_creole_line_break.html +6 -0
- data/unittest/expected_creole/test_creole_line_break.latex +8 -0
- data/unittest/expected_creole/test_creole_links_explicit_internal.html +6 -0
- data/unittest/expected_creole/test_creole_links_explicit_internal.text +4 -0
- data/unittest/expected_creole/test_creole_links_explicit_with_em.html +3 -0
- data/unittest/expected_creole/test_creole_links_explicit_with_em.latex +4 -0
- data/unittest/expected_creole/test_creole_links_explicit_with_em.text +2 -0
- data/unittest/expected_creole/test_creole_links_external.html +6 -0
- data/unittest/expected_creole/test_creole_links_external.latex +8 -0
- data/unittest/expected_creole/test_creole_links_external.text +4 -0
- data/unittest/expected_creole/test_creole_links_external_implicit.html +9 -0
- data/unittest/expected_creole/test_creole_links_external_implicit.latex +12 -0
- data/unittest/expected_creole/test_creole_links_external_implicit.text +6 -0
- data/unittest/expected_creole/test_creole_links_file.html +6 -0
- data/unittest/expected_creole/test_creole_links_file.latex +8 -0
- data/unittest/expected_creole/test_creole_links_file.text +4 -0
- data/unittest/expected_creole/test_creole_list_ol.html +12 -0
- data/unittest/expected_creole/test_creole_list_ol.latex +22 -0
- data/unittest/expected_creole/test_creole_list_ol_after_ul.html +12 -0
- data/unittest/expected_creole/test_creole_list_ol_after_ul.latex +20 -0
- data/unittest/expected_creole/test_creole_list_ol_after_ul.text +6 -0
- data/unittest/expected_creole/test_creole_list_ol_ul.html +15 -0
- data/unittest/expected_creole/test_creole_list_ol_ul.latex +26 -0
- data/unittest/expected_creole/test_creole_list_ul.html +22 -0
- data/unittest/expected_creole/test_creole_list_ul.latex +40 -0
- data/unittest/expected_creole/test_creole_list_ul.normsource +83 -0
- data/unittest/expected_creole/test_creole_list_ul_too_much.html +24 -0
- data/unittest/expected_creole/test_creole_list_ul_too_much.latex +44 -0
- data/unittest/expected_creole/test_creole_newline.html +9 -0
- data/unittest/expected_creole/test_creole_newline.latex +11 -0
- data/unittest/expected_creole/test_creole_newline.text +7 -0
- data/unittest/expected_creole/test_creole_paragraphs.html +6 -0
- data/unittest/expected_creole/test_creole_paragraphs.latex +8 -0
- data/unittest/expected_creole/test_creole_paragraphs.normsource +27 -0
- data/unittest/expected_creole/test_creole_paragraphs.text +4 -0
- data/unittest/expected_creole/test_creole_paragraphs.wiki +4 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap.html +5 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap.latex +6 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap.text +4 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap.wiki +4 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap0.html +9 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap0.latex +11 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap0.text +7 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap0.wiki +7 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap60.html +5 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap60.latex +6 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap60.text +4 -0
- data/unittest/expected_creole/test_creole_paragraphs_wrap60.wiki +4 -0
- data/unittest/expected_creole/test_creole_picture_link.html +6 -0
- data/unittest/expected_creole/test_creole_pictures.html +10 -0
- data/unittest/expected_creole/test_creole_pictures.latex +13 -0
- data/unittest/expected_creole/test_creole_pictures_css.html +3 -0
- data/unittest/expected_creole/test_creole_pictures_css.latex +4 -0
- data/unittest/expected_creole/test_creole_pictures_imgclass.html +6 -0
- data/unittest/expected_creole/test_creole_pictures_imgclass.latex +8 -0
- data/unittest/expected_creole/test_creole_placeholders_html.html +7 -0
- data/unittest/expected_creole/test_creole_placeholders_html.latex +8 -0
- data/unittest/expected_creole/test_creole_placeholders_html.text +4 -0
- data/unittest/expected_creole/test_creole_placeholders_latex.html +6 -0
- data/unittest/expected_creole/test_creole_placeholders_latex.latex +9 -0
- data/unittest/expected_creole/test_creole_placeholders_latex.text +4 -0
- data/unittest/expected_creole/test_creole_tabular.html +20 -0
- data/unittest/expected_creole/test_creole_tabular.latex +22 -0
- data/unittest/expected_creole/test_creole_tabular_creole.html +18 -0
- data/unittest/expected_creole/test_creole_tabular_creole.latex +19 -0
- data/unittest/expected_creole/test_creole_tabular_css.html +20 -0
- data/unittest/expected_creole/test_creole_tabular_css.latex +22 -0
- data/unittest/expected_creole/test_creole_toc.html +11 -0
- data/unittest/expected_creole/test_creole_toc.latex +22 -0
- data/unittest/expected_creole/test_creole_toc.text +4 -0
- data/unittest/expected_creole/test_creole_toc_text.html +5 -0
- data/unittest/expected_creole/test_creole_toc_text.latex +5 -0
- data/unittest/expected_creole/test_creole_ul_multiple_line.html +7 -0
- data/unittest/expected_creole/test_creole_ul_multiple_line.latex +14 -0
- data/unittest/expected_creole/test_creole_ul_with_blank.html +11 -0
- data/unittest/expected_creole/test_creole_ul_with_blank.latex +20 -0
- data/unittest/expected_creole/test_creole_ul_with_bold.creole +0 -0
- data/unittest/expected_creole/test_creole_ul_with_bold.html +11 -0
- data/unittest/expected_creole/test_creole_ul_with_bold.latex +18 -0
- data/unittest/expected_creole/test_creole_ul_with_bold.text +7 -0
- data/unittest/expected_creole/test_creole_verbatim.html +25 -0
- data/unittest/expected_creole/test_creole_verbatim.latex +33 -0
- data/unittest/expected_creole/test_creole_verbatim.text +17 -0
- data/unittest/expected_creole/test_creole_verbatim_inline.html +6 -0
- data/unittest/expected_creole/test_creole_verbatim_inline.latex +8 -0
- data/unittest/expected_creole/test_creole_verbatim_inline_at_start.html +6 -0
- data/unittest/expected_creole/test_creole_verbatim_inline_at_start.latex +8 -0
- data/unittest/expected_privat/test_creole_test_document.html +6 -0
- data/unittest/{expected → expected_wiki}/test_wiki.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_amazon.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_description.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_description.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_description.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_description.wiki +0 -0
- data/unittest/expected_wiki/test_wiki_footnote.html +8 -0
- data/unittest/expected_wiki/test_wiki_footnote.latex +17 -0
- data/unittest/{expected → expected_wiki}/test_wiki_footnote.text +2 -4
- data/unittest/expected_wiki/test_wiki_footnote.wiki +10 -0
- data/unittest/expected_wiki/test_wiki_footnote_2.html +8 -0
- data/unittest/expected_wiki/test_wiki_footnote_groupid.html +21 -0
- data/unittest/{expected → expected_wiki}/test_wiki_html_code.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_html_code.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_html_code.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_html_code.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_inline.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_inline.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_inline.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_inline.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_label.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_link.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_link.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_link.log +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_link.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_picture.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_picture.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_picture_thumb.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_tab1.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_tab1.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_tab1.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_textformatting.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_textformatting.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_textformatting.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_textformatting.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_toc.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_toc.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_toc.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_toc.wiki +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.html +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.latex +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.text +0 -0
- data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.wiki +0 -0
- data/unittest/test_docgenerator.rb +1 -2
- data/unittest/unittest_creole2doc.rb +1024 -0
- data/unittest/unittest_docgenerator.rb +17 -8
- data/unittest/unittest_wiki2doc.rb +92 -88
- data/unittest/unittest_yaml2pres.rb +336 -0
- metadata +202 -70
- data/unittest/expected/test_wiki_footnote.html +0 -8
- data/unittest/expected/test_wiki_footnote.latex +0 -15
- data/unittest/expected/test_wiki_footnote.wiki +0 -12
- data/unittest/expected/test_wiki_footnote_groupid.html +0 -21
data/lib/docgenerator_element.rb
CHANGED
@@ -7,20 +7,20 @@
|
|
7
7
|
#Redefine is_a?:
|
8
8
|
#Return true, when you test with a symbol.
|
9
9
|
class Object
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
10
|
+
alias :old_is_a? :is_a?
|
11
|
+
#Redefine the standard is_a?
|
12
|
+
#Returns also true, if one of the ids is in testvalue
|
13
|
+
def is_a?( testvalue)
|
14
|
+
if testvalue.old_is_a?(Symbol)
|
15
|
+
if old_is_a?(Element)
|
16
|
+
return ids.include?(testvalue)
|
17
|
+
else
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
else
|
21
|
+
return old_is_a?(testvalue)
|
22
|
+
end
|
23
|
+
end
|
24
24
|
#
|
25
25
|
# to_doc returns the object as a string.
|
26
26
|
# will be redefined for Element
|
@@ -77,552 +77,559 @@ end
|
|
77
77
|
#But the error is done, when the element is created.
|
78
78
|
#When you redefine ELEMENTS_TRACE, some tracing information are stored during creation.
|
79
79
|
class Element
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
80
|
+
#Hash with all ids and their corresponding classes.
|
81
|
+
@@ids = Hash.new( )
|
82
|
+
#All attributes are stored in this hash.
|
83
|
+
#The key is the corresponding class.
|
84
|
+
@@attr = { Element => {} }
|
85
|
+
#All output routines are stored in this hash.
|
86
|
+
#The key is the corresponding class.
|
87
|
+
@@log = false
|
88
|
+
def Element.log=( log )
|
89
|
+
@@log = log
|
90
|
+
end
|
91
|
+
#Flag, if the calling stack should be analysed for each Element
|
92
|
+
#Only for document debbuging
|
93
|
+
@@trace = nil
|
94
|
+
#Set Element tracing on/off
|
95
|
+
def Element.trace=( val )
|
96
|
+
@@trace = val
|
97
|
+
end
|
98
98
|
|
99
|
-
|
99
|
+
SUPPORTED_TARGETS = [ :latex, :html, :wiki, :text, :debug ]
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
101
|
+
#Return a element class.
|
102
|
+
def Element.get( name )
|
103
|
+
return @@ids[name]
|
104
|
+
end
|
105
|
+
#This method is called, when a subclass of this class is defined.
|
106
|
+
#This can happen via Element.create or in another programm.
|
107
|
+
#
|
108
|
+
#Add subclasses to the list of all element classes and initialize some internal hashes.
|
109
|
+
def Element.inherited( subclass )
|
110
|
+
puts "New subclass for 'Element' created: '#{subclass}'" if @@log
|
111
|
+
#All attributes of a class are collected in a hash.
|
112
|
+
@@attr[subclass] = {}
|
113
|
+
#Fill @@ids
|
114
|
+
#There is no possibility to give a list of id's or names to a 'inherit'-method.
|
115
|
+
#So a special method Element.add is used.
|
116
|
+
Element.add( [subclass], subclass )
|
117
|
+
end
|
118
|
+
#Add a new element class or assign another name (synonym) for a class.
|
119
|
+
#The initial call is made by Element.inherited.
|
120
120
|
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
121
|
+
#Element.add( [:element], Element )
|
122
|
+
def Element.add( idlist, elementClass )
|
123
|
+
if ! elementClass.new.kind_of?( Element )
|
124
|
+
raise "Element.add get no Element-class #{elementClass}"
|
125
|
+
end
|
126
126
|
idlist = [ idlist ] if ! idlist.kind_of?( Array )
|
127
127
|
raise "Empty idlist for #{elementClass}" if idlist.empty?
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
129
|
+
idlist.each{|id|
|
130
|
+
if @@ids[ id ] == nil
|
131
|
+
puts "Element class '#{id}' is new: #{elementClass}" if @@log
|
132
|
+
#All new ids are collected
|
133
|
+
@@ids[ id ] = elementClass
|
134
|
+
elsif @@ids[ id ] == elementClass
|
135
|
+
puts "Element class '#{id}' is defined double: #{elementClass}" if @@log
|
136
|
+
else
|
137
|
+
puts "Error: ID '#{id}' is redefined #{@@ids[id]} -> #{elementClass}"
|
138
|
+
@@ids[id] = elementClass
|
139
|
+
end
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
#Generic creation of a new class to define a new element.
|
144
|
+
#- name must be defined.
|
145
|
+
#- attr is a hash with all attributes.
|
146
|
+
# For details see Element.add_attributes
|
147
|
+
#- content is a flag, which defines if the element contains "content".
|
148
|
+
# Valid values are:
|
149
|
+
# - true: content available and necessary (e.g. <p>)
|
150
|
+
# - :empty_ok: content available, but not necessary (e.g. <td> or iframe)
|
151
|
+
# - false: no content, no endtag, but tag closed with / (example: <br />)
|
152
|
+
# - nil: no content, no endtag, no closing (example: <br>)
|
153
|
+
#- output contains a hash with logic, how to handle the output.
|
154
|
+
# -:htmltag Tag for html-output.
|
155
|
+
# -:latex Template for LaTeX-output
|
156
|
+
# -:html Template for HTML-output
|
157
|
+
def Element.create( name, attr = {}, content = false, output = {} )
|
158
|
+
#First some checks
|
159
|
+
if ! attr.kind_of?( Hash )
|
160
|
+
raise "Type error Element.create: Expected Hash, get #{attr.class}"
|
161
|
+
end
|
162
|
+
#Generic class creation
|
163
|
+
elementclass = Class.new( Element )
|
164
|
+
#Add the id of the new class to central collection.
|
165
|
+
Element.add( name, elementclass )
|
166
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
|
-
|
167
|
+
#Set a flag, if the class can contain 'content'.
|
168
|
+
#-true: content available and necessary (e.g. <p>)
|
169
|
+
#-:empty_ok: content available, but not necessary (e.g. <td>)
|
170
|
+
#-false: no content, no endtag, but tag closed with / (example: <br />)
|
171
|
+
#-nil: no content, no endtag, no closing (example: <br>)
|
172
|
+
elementclass.class_eval( %Q|
|
173
|
+
def content?()
|
174
|
+
return #{content.inspect}
|
175
|
+
end|)
|
176
|
+
|
177
|
+
output.each{ |k,v|
|
178
|
+
case k
|
179
|
+
when :latex
|
180
|
+
elementclass.add_output( :latex, v )
|
181
|
+
when :html
|
182
|
+
elementclass.add_output( :html, v )
|
183
|
+
when :text
|
184
|
+
elementclass.add_output( :text, v )
|
185
|
+
when :wiki
|
186
|
+
elementclass.add_output( :wiki, v )
|
187
|
+
when :htmltag
|
188
|
+
if v
|
189
|
+
elementclass.class_eval( "def htmltag()\n'#{v}'\nend" )
|
190
|
+
else
|
191
|
+
elementclass.class_eval( "def htmltag()\nnil\nend" )
|
192
|
+
end
|
193
|
+
else
|
194
|
+
puts "Unknown format #{k} for #{name}"
|
195
|
+
end
|
196
|
+
}
|
197
|
+
elementclass.add_attributes( attr )
|
198
|
+
#Return the class.
|
199
|
+
return elementclass
|
200
|
+
end
|
201
|
+
#Return all id's of the class.
|
202
|
+
#@@ids is expanded in Element.add.
|
203
|
+
def ids( )
|
204
204
|
myids = []
|
205
205
|
@@ids.each{|k,v| myids << k if v == self.class and k.class != Class }
|
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
|
-
|
206
|
+
return myids
|
207
|
+
end
|
208
|
+
#Prepares an overview on all Elements.
|
209
|
+
#Can be used for some debugging.
|
210
|
+
def Element.overview( list = @@ids.values.uniq )
|
211
|
+
if ! list.kind_of?(Array)
|
212
|
+
list = [ list ]
|
213
|
+
end
|
214
|
+
result = '=' * 10 + "\nElement overview:"
|
215
|
+
list.each{ |k|
|
216
|
+
result += "\n#{k}\n"
|
217
|
+
result += "\tId's:\t\t"
|
218
|
+
result += k.new.ids.join("\n\t\t\t")
|
219
|
+
result += "\n\tAttributes:\t"
|
220
|
+
result += "can contain "
|
221
|
+
result += "no " if ! k.new.content?
|
222
|
+
result += "content\n\t\t\t"
|
223
|
+
@@attr[k].each{ |k2,v|
|
224
|
+
result += "#{k2}:\t#{v.inspect}\n\t\t\t"
|
225
|
+
}
|
226
|
+
}
|
227
|
+
return result
|
228
|
+
end
|
229
|
+
#Add possible attributes to an element class.
|
230
|
+
#Attributes are defined in a hash, each key get a array with values.
|
231
|
+
#The values can be:
|
232
|
+
#- OBLIGATORY/OPTIONAL
|
233
|
+
#- Alias (this allows the usage of a position and a name for a parameter).
|
234
|
+
#- allowed elements ( e.g. list content only list items)
|
235
|
+
#Problem: Attributes are not inherited. See Element.get_attribute_list
|
236
|
+
#
|
237
|
+
#This method is called from a subclass.
|
238
|
+
#Fixme: add_attributes overwrites everything.
|
239
|
+
def Element.add_attributes( attr )
|
240
|
+
elattr = @@attr[self] #self is the class
|
241
|
+
attr.each{ |k,a |
|
242
|
+
elattr[k] = a
|
243
|
+
}
|
244
|
+
end
|
245
|
+
#Returns list of attributes.
|
246
|
+
#Can be used for copying attributes from one class to another class.
|
247
|
+
def Element.get_attribute_list( elementclass )
|
248
|
+
return @@attr[elementclass]
|
249
|
+
end
|
250
|
+
#Add an output routine.
|
251
|
+
def Element.add_output( target, string )
|
252
|
+
case target
|
253
|
+
when :latex
|
254
|
+
cmd = "def to_latex(options = {})\n"
|
255
|
+
when :html
|
256
|
+
cmd = "def to_html(options = {})\n"
|
257
|
+
when :text
|
258
|
+
cmd = "def to_text(options = {})\n"
|
259
|
+
when :wiki
|
260
|
+
cmd = "def to_wiki(options = {})\n"
|
261
|
+
else
|
262
|
+
puts "#{self}: Undefined target format #{target}"
|
263
|
+
end
|
264
|
+
if ! string.kind_of?( String )
|
265
|
+
puts "Error element <#{self.new.ids}>: #{string.inspect} is no String"
|
266
|
+
end
|
267
267
|
cmd << <<code
|
268
268
|
o = Docgenerator_logger.set_option_defaults(options)
|
269
269
|
o[:log].debug("enter to_doc(#{target}) for #{self.inspect}, options: \#{options.keys.inspect}") if o[:log].debug?
|
270
270
|
code
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
271
|
+
template = string.gsub(/\\/, '\\\\\\')
|
272
|
+
template.gsub!(/"/, '\"')
|
273
|
+
template.gsub!(/@content\}/, "@content.to_doc(#{target.inspect}, o)}")
|
274
|
+
cmd << " \"#{template}\"\n"
|
275
|
+
cmd << "end\n"
|
276
|
+
class_eval( cmd )
|
277
277
|
cmd #return cmd for unit test
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
278
|
+
end
|
279
|
+
#Defines an element.
|
280
|
+
#
|
281
|
+
#There are two ways to add values:
|
282
|
+
#- "named" values in an hash.
|
283
|
+
# This named values can be attributes of a HTML-Tag or Parameters of a TeX-Makro.
|
284
|
+
# There is a check, if the attribute exist.
|
285
|
+
#- Content. Values "inside" the element.
|
286
|
+
# The content can be the content of a HTML-Tag or the content of a TeX-Environment.
|
287
|
+
# There is a check, if this class allows content.
|
288
|
+
#:log is the default attribute for the logger.
|
289
|
+
#In Element#to_doc you can give another logger!
|
290
|
+
def initialize( attr={}, content = nil)
|
291
|
+
#@attr is a hash containing the values for each attribute.
|
292
|
+
@attr = Hash.new( )
|
293
|
+
#~ @log = DOCGENERATOR_LOGGER
|
294
|
+
#Attention! in to_doc another logger may be given.
|
295
|
+
@log = attr[:log] ? attr[:log] : DOCGENERATOR_LOGGER
|
296
|
+
attr.delete(:log) #remove from attr-interface
|
292
297
|
#attr alias
|
293
|
-
|
298
|
+
@attr_alias = Hash.new( )
|
294
299
|
if self.content?()
|
295
|
-
@content
|
300
|
+
@content = []
|
296
301
|
else
|
297
|
-
@content
|
302
|
+
@content = nil
|
298
303
|
end
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
304
|
+
@crbefore = false #make \n before element
|
305
|
+
@crmid = false #make \n before and after opening/closing html-tag
|
306
|
+
@crafter = false #make \n after element
|
307
|
+
#List of targets, where the element can be used.
|
308
|
+
#Details see method restrict_to()
|
309
|
+
#Default: allsupported targets
|
310
|
+
@targets = SUPPORTED_TARGETS.dup
|
306
311
|
@suppressed_targets = []
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
@targets
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
312
|
+
|
313
|
+
#Initialize the attribute hash.
|
314
|
+
@@attr[self.class].each{ |k,a|
|
315
|
+
#type check on Attribute does not work .
|
316
|
+
if a.kind_of?( Symbol )
|
317
|
+
#Filled in the second run
|
318
|
+
#~ @attr[k] = @attr[a]
|
319
|
+
elsif a #.kind_of?( Attribute )
|
320
|
+
@attr[k] = a.new( k, self )
|
321
|
+
else
|
322
|
+
@attr[k] = Attribute.create().new( k, self )
|
323
|
+
end
|
324
|
+
}
|
325
|
+
#Assign Alias-Attributes
|
326
|
+
@@attr[self.class].each{ |k,a|
|
327
|
+
next if !a.kind_of?( Symbol )
|
328
|
+
if @attr[a]
|
329
|
+
@attr_alias[k] = @attr[a]
|
330
|
+
else
|
331
|
+
@log.warn("Undefined Alias-Attribute #{k}") if @log.warn?
|
332
|
+
@attr[k] = Attribute.create().new( k, self )
|
333
|
+
end
|
334
|
+
}
|
335
|
+
attr.each{ |k,v|
|
336
|
+
if @attr[k]
|
337
|
+
@attr[k] << v
|
338
|
+
elsif @attr_alias[k]
|
339
|
+
@attr_alias[k] << v
|
340
|
+
else
|
341
|
+
@log.warn("Usage of unknown attribute '#{k}' in '#{self.ids.join(',')}'") if @log.warn?
|
342
|
+
end
|
343
|
+
}
|
344
|
+
@called_by = prepare_tracing_info( @@trace )
|
345
|
+
self << content if content
|
346
|
+
end
|
347
|
+
#List (array) of targets, where the element can be used.
|
348
|
+
#Default are all supported targets.
|
349
|
+
#
|
350
|
+
#With restrictions of this attribute, elements can be restricted on special documents.
|
351
|
+
def restrict_to( *argv )
|
352
|
+
@targets = []
|
353
|
+
@suppressed_targets = SUPPORTED_TARGETS.dup
|
354
|
+
@log.warn("Element#restrict_to: #{self.inspect} restrict to #{argv.inspect}") if @log.warn?
|
355
|
+
argv.each{ |arg|
|
356
|
+
#~ if ! SUPPORTED_TARGETS.include?( arg )
|
357
|
+
if ! @suppressed_targets.delete( arg )
|
358
|
+
@log.warn("Restriction for unsupported target #{arg}") if @log.warn?
|
359
|
+
end
|
360
|
+
@targets << arg
|
361
|
+
}
|
362
|
+
self
|
363
|
+
end
|
364
|
+
#Only for debbuging reasons.
|
365
|
+
#Should contain the first "no docgenerator.rb-place, where part is called
|
366
|
+
#if @@trace is on, some tracing information is stored during creation.
|
367
|
+
def prepare_tracing_info( doit = @@trace )
|
368
|
+
return nil if ! doit
|
369
|
+
caller().each{|c|
|
370
|
+
next if ( /DocumentGenerator/ =~ c )
|
371
|
+
return c
|
372
|
+
}
|
373
|
+
#--> No calling stack found --> Error
|
374
|
+
puts '----'*10
|
375
|
+
puts 'Element#prepare_tracing_info: Found no starting place in caller stack'
|
376
|
+
caller().each{|c| puts c }
|
377
|
+
puts '----'*10
|
378
|
+
return caller()
|
379
|
+
end
|
380
|
+
def inspect()
|
381
|
+
if @@trace
|
382
|
+
called_by = ", Created in #{@called_by}"
|
383
|
+
else
|
384
|
+
called_by = nil #'unknown. Please set Elements.trace if needed'
|
385
|
+
end
|
386
|
+
return "<Class Element(#{self.ids.join(',')})#{called_by}>"
|
387
|
+
#~ if @content
|
388
|
+
#~ return "<Class Element(#{self.ids.join(',')}) @content=#{@content.inspect}>"
|
389
|
+
#~ else
|
390
|
+
#~ return "<Class Element(#{self.ids.join(',')}) @attr=#{@attr.inspect}>"
|
391
|
+
#~ end
|
392
|
+
end
|
393
|
+
#Accessor on content
|
394
|
+
attr_reader :content
|
395
|
+
#Add something to the content.
|
396
|
+
#Only possible on elements, which supports "content".
|
397
|
+
def << ( content )
|
398
|
+
if @content
|
399
|
+
@content << content
|
400
|
+
else
|
401
|
+
@log.warn("Add content to an element without this feature #{self.ids.inspect}, #{content.inspect}") if @log.warn?
|
402
|
+
end
|
403
|
+
end
|
399
404
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
405
|
+
#Add content after a target (other content)
|
406
|
+
# insertafter(target,*obj)
|
407
|
+
#Requires the ability of "content".
|
408
|
+
def insertafter(target,*obj)
|
409
|
+
self.insert(target, 1, obj)
|
410
|
+
end
|
411
|
+
#Add content before a target (other content)
|
412
|
+
# insertbefore(target,*obj)
|
413
|
+
#Requires the ability of "content".
|
414
|
+
def insertbefore(target,*obj)
|
415
|
+
self.insert(target, 0, obj)
|
416
|
+
end
|
417
|
+
#Insert content relative to a given target.
|
418
|
+
#The target must exist, pos defines the relative position (0=before, 1=one after the element).
|
419
|
+
#Method called by Element#insertbefore and Element#insertafter.
|
420
|
+
def insert(target,pos,*obj )
|
421
|
+
if @content
|
422
|
+
if @content.include?( target )
|
423
|
+
@content[@content.index(target)+pos ,0] = obj
|
424
|
+
else
|
425
|
+
@log.warn("Insert content not possible. Reference object does not exist (#{target.inspect})") if @log.warn?
|
426
|
+
end
|
427
|
+
else
|
428
|
+
@log.warn("Add content to an element without this feature") if @log.warn?
|
429
|
+
end
|
430
|
+
self
|
431
|
+
end
|
432
|
+
#Delete the given object.
|
433
|
+
def delete(target )
|
434
|
+
if @content
|
435
|
+
@content.delete( target )
|
436
|
+
else
|
437
|
+
@log.warn("Delete content of an element without this feature") if @log.warn?
|
438
|
+
end
|
439
|
+
self
|
440
|
+
end
|
441
|
+
#Insert an empty line after the last entry
|
442
|
+
def cr()
|
443
|
+
@crafter = true
|
444
|
+
self
|
445
|
+
end
|
446
|
+
#Insert an empty line before and after the last entry
|
447
|
+
def Cr()
|
448
|
+
@crbefore = true
|
449
|
+
@crafter = true
|
450
|
+
self
|
451
|
+
end
|
452
|
+
#Insert an empty line after the last entry and after the opening of the tag.
|
453
|
+
#This feature has it reason for lists, when each :li-tag gets a cr.
|
454
|
+
#The first item gets also a cr.
|
455
|
+
def cR()
|
456
|
+
@crbefore = false
|
457
|
+
@crmid = true
|
458
|
+
@crafter = true
|
459
|
+
self
|
460
|
+
end
|
461
|
+
#Insert an empty line before and after the last entry and after the opening of the tag.
|
462
|
+
def CR()
|
463
|
+
@crbefore = true
|
464
|
+
@crmid = true
|
465
|
+
@crafter = true
|
466
|
+
self
|
467
|
+
end
|
468
|
+
#Accessor on attribute list
|
469
|
+
attr_reader :attr
|
470
|
+
#Return an attribute to add content.
|
471
|
+
def [] (key)
|
472
|
+
attr = @attr[key]
|
468
473
|
#If Attribute does not exist, take a look, if it is an alias-name.
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
474
|
+
attr = @attr_alias[key] if !attr
|
475
|
+
if !attr
|
476
|
+
puts "Request unknown attribute '#{key}', return a dummy"
|
477
|
+
attr = Attribute.create( ).new(key, self)
|
478
|
+
end
|
479
|
+
return attr
|
480
|
+
end
|
481
|
+
#Default setting, each element class may contain contents.
|
482
|
+
#Can be redefined by Elements.create.
|
483
|
+
#-true: content available and necessary (e.g. <p>)
|
484
|
+
#-:empty_ok: content available, but not necessary (e.g. <td>)
|
485
|
+
#-false: no content, no endtag, but tag closed with / (example: <br />)
|
486
|
+
#-nil: no content, no endtag, no closing (example: <br>)
|
487
|
+
def content?()
|
488
|
+
return true
|
489
|
+
end
|
490
|
+
#check if there is content assigned.
|
491
|
+
def empty?()
|
492
|
+
return @content.empty?
|
493
|
+
end
|
494
|
+
@@level = 0
|
495
|
+
#Build a String to be used for the target document.
|
496
|
+
#Calls Element#to_latex (target :latex)
|
497
|
+
#and Element#to_html (target :html).
|
498
|
+
#
|
499
|
+
#Via the options-hash, you can transport additional information.
|
500
|
+
def to_doc( target, options = {} )
|
494
501
|
o = Docgenerator_logger.set_option_defaults(options)
|
495
502
|
o[:log].debug("enter to_doc(#{target}) for #{self.inspect}, options: #{options.keys.inspect}") if o[:log].debug?
|
496
|
-
|
497
|
-
|
503
|
+
#Return empty string, if target is not requested.
|
504
|
+
if ! @targets.include?( target )
|
498
505
|
if @suppressed_targets.include?(target)
|
499
|
-
|
506
|
+
o[:log].info("Element#to_doc: Content of #{self.inspect} suppressed for Target #{target.inspect}.") if o[:log].info?
|
500
507
|
else
|
501
|
-
|
508
|
+
o[:log].warn("Element#to_doc: Target #{target.inspect} not supported for #{self.inspect}.") if o[:log].warn?
|
509
|
+
end
|
510
|
+
return ''
|
511
|
+
end
|
512
|
+
#Some checks
|
513
|
+
@attr.each{|k,v|
|
514
|
+
if v.required? and v.to_s == '' and v.settings.include?(target)
|
515
|
+
o[:log].error "#{self.ids}: Attribut '#{k}' without required value" if o[:log].error?
|
502
516
|
end
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
when :wiki
|
519
|
-
result = to_wiki(o)
|
520
|
-
when :text
|
521
|
-
result = to_text(o)
|
522
|
-
else
|
523
|
-
o[:log].fatal("Undefined target format '#{target}'") if o[:log].fatal?
|
524
|
-
end
|
517
|
+
}
|
518
|
+
#Build the string.
|
519
|
+
result = ''
|
520
|
+
case target
|
521
|
+
when :latex
|
522
|
+
result = to_latex(o)
|
523
|
+
when :html
|
524
|
+
result = to_html(o)
|
525
|
+
when :wiki
|
526
|
+
result = to_wiki(o)
|
527
|
+
when :text
|
528
|
+
result = to_text(o)
|
529
|
+
else
|
530
|
+
o[:log].fatal("Undefined target format '#{target}'") if o[:log].fatal?
|
531
|
+
end
|
525
532
|
#Already added in submethods
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
533
|
+
#~ result = "\n#{result}" if @crbefore
|
534
|
+
#~ result << "\n" if @crafter
|
535
|
+
return result
|
536
|
+
end
|
537
|
+
#This is a dummy method, called from Element#to_s for the target format LaTeX.
|
538
|
+
#This method must be overwritten from the element class.
|
539
|
+
#
|
540
|
+
#By default, the concatenation of all ids and the content is taken.
|
541
|
+
def to_latex(options = {})
|
535
542
|
o = Docgenerator_logger.set_option_defaults(options)
|
536
|
-
|
543
|
+
o[:log].error("Missing output routine for LaTeX (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
|
537
544
|
makroname = 'dummy'
|
538
545
|
self.ids.each{|id|
|
539
546
|
makroname = id if id.is_a?(Symbol) or id.is_a?(String)
|
540
547
|
}
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
548
|
+
cmd = ''
|
549
|
+
cmd << "\n" if @crbefore
|
550
|
+
cmd << "\\#{makroname}{#{@content}}"
|
551
|
+
cmd << "\n" if @crafter
|
552
|
+
return cmd
|
553
|
+
end
|
554
|
+
#Method for definition inside Element.create.
|
555
|
+
def linebreak( flag = true )
|
556
|
+
flag ? "\n" : ''
|
557
|
+
end
|
558
|
+
#Prints the optional attribut key inside []. If empty, nil is returned
|
559
|
+
def texoptional(key)
|
560
|
+
return nil if ! @attr[key].filled?
|
561
|
+
return "[#{@attr[key]}]"
|
562
|
+
end
|
563
|
+
#Build key-val options from attributs.
|
564
|
+
#Used e.g. by includegraphics.
|
565
|
+
def texkeyval()
|
566
|
+
keyval = []
|
567
|
+
@attr.sort_by{|k,v| v.sortkey }.each{|k,v|
|
568
|
+
keyval << "#{k}={#{v}}" if v.to_s != '' and v.texkeyval?
|
569
|
+
}
|
570
|
+
return keyval.join(', ')
|
571
|
+
end
|
572
|
+
#Method for html-output.
|
573
|
+
#If the method is redefined, the result is taken as a tag.
|
574
|
+
def htmltag()
|
575
|
+
''
|
576
|
+
end
|
577
|
+
#This is a dummy method, called from Element#to_doc for the target format HTML.
|
578
|
+
#The tag from Element.htmltag is taken and all attributes and the content are used.
|
579
|
+
#
|
580
|
+
#This method can be overwritten from the element class.
|
581
|
+
def to_html(options = {})
|
575
582
|
o = Docgenerator_logger.set_option_defaults(options)
|
576
|
-
|
577
|
-
|
583
|
+
tag = htmltag()
|
584
|
+
if ! tag
|
578
585
|
o[:log].error("No HTML element available (#{self.ids.join(',')})") if o[:log].error?
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
586
|
+
return ''
|
587
|
+
elsif tag == ''
|
588
|
+
tag = 'span'
|
589
|
+
o[:log].error("Missing output routine for HTML (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
|
590
|
+
end
|
591
|
+
#Test if the HTML-Tag should contain something, but there is nothing.
|
592
|
+
#If :empty_ok it is ok, that there is no content (e.g <td>)
|
593
|
+
#May make problems, if an empty tag is used to set a id-mark.
|
594
|
+
if content?() and content? != :empty_ok and
|
595
|
+
( ! @content or @content == [] or @content == [nil] )
|
596
|
+
o[:log].warn("HTML-Tag #{tag} without content -> ignored #{self.inspect if @@trace}") if o[:log].warn?
|
597
|
+
return ''
|
598
|
+
end
|
599
|
+
html = String.new()
|
600
|
+
html << "\n" if @crbefore
|
601
|
+
html << "<#{tag} "
|
602
|
+
@attr.sort_by{|k,v| v.sortkey }.each{|k,v|
|
603
|
+
html << "#{k} = \"#{v}\" " if v.to_s != '' and v.html?
|
604
|
+
}
|
605
|
+
if @content
|
606
|
+
html << ">"
|
607
|
+
html <<"\n" if @crmid
|
608
|
+
html << "#{@content.to_html(options)}"
|
609
|
+
html << "\n" if @crmid and @content.size > 0 and html[-1,1] != "\n"
|
610
|
+
html << "</#{tag}>"
|
611
|
+
elsif content?() == nil
|
612
|
+
html << '>'
|
613
|
+
else
|
614
|
+
html << '/>'
|
615
|
+
end
|
616
|
+
html << "\n" if @crafter
|
617
|
+
return html
|
618
|
+
end #to_html
|
619
|
+
def to_wiki(options = {})
|
613
620
|
o = Docgenerator_logger.set_option_defaults(options)
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
621
|
+
o[:log].error("Missing output routine for Wiki (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
|
622
|
+
return "#{@content.to_wiki(options)}\n"
|
623
|
+
end
|
624
|
+
def to_text(options = {})
|
618
625
|
o = Docgenerator_logger.set_option_defaults(options)
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
+
o[:log].error("Missing output routine for Text (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
|
627
|
+
text = String.new()
|
628
|
+
text << "\n" if @crbefore
|
629
|
+
text = "#{@content.to_text(options)}".strip
|
630
|
+
text << "\n" if @crafter
|
631
|
+
return text
|
632
|
+
end
|
626
633
|
def to_s()
|
627
634
|
return self.inspect
|
628
635
|
end
|