docgenerator 1.0.4 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/lib/creole/creole2doc.rb +777 -0
  2. data/lib/creole/creole_inclusion_and_plugins.rb +236 -0
  3. data/lib/creole/creole_placeholder.rb +74 -0
  4. data/lib/creole/creole_tabular.rb +170 -0
  5. data/lib/docgenerator.rb +15 -6
  6. data/lib/docgenerator_attribute.rb +2 -2
  7. data/lib/docgenerator_characters.rb +20 -4
  8. data/lib/docgenerator_document.rb +132 -42
  9. data/lib/docgenerator_element.rb +531 -524
  10. data/lib/docgenerator_elements.rb +408 -399
  11. data/lib/docgenerator_environments.rb +28 -2
  12. data/lib/docgenerator_footnote.rb +72 -79
  13. data/lib/docgenerator_sections.rb +1 -1
  14. data/lib/docgenerator_tabular.rb +8 -3
  15. data/lib/packages/docgenerator_beamer.rb +253 -0
  16. data/lib/packages/docgenerator_scrlettr2.rb +53 -9
  17. data/lib/templates/docgenerator_template_css.rb +4 -0
  18. data/lib/wiki2doc/wiki2docgenerator.rb +1087 -970
  19. data/lib/yaml2presentation/yaml2presentation.rb +1091 -0
  20. data/self_docgenerator.rb +8 -6
  21. data/unittest/Red_Flower.jpg +0 -0
  22. data/unittest/creole1.0test.txt +128 -0
  23. data/unittest/expected/beamer_01_doc.html +1 -1
  24. data/unittest/expected/beamer_02_doc.html +1 -1
  25. data/unittest/expected/beamer_doc_html_overview_with_detailpic_and_text_doc.html +34 -0
  26. data/unittest/expected/beamer_doc_html_overview_with_detailpic_doc.html +34 -0
  27. data/unittest/expected/beamer_doc_key_doc.html +1 -1
  28. data/unittest/expected/beamer_doc_note_doc.html +1 -1
  29. data/unittest/expected/beamer_doc_pic_bottom_doc.html +1 -1
  30. data/unittest/expected/beamer_doc_pic_doc.html +1 -1
  31. data/unittest/expected/beamer_doc_pic_left_doc.html +1 -1
  32. data/unittest/expected/beamer_doc_pic_right_doc.html +1 -1
  33. data/unittest/expected/beamer_doc_pic_top_doc.html +1 -1
  34. data/unittest/expected/test_footnote.html +2 -2
  35. data/unittest/expected/test_footnote.latex +1 -1
  36. data/unittest/expected/test_footnote_group.html +3 -3
  37. data/unittest/expected/test_footnote_group.latex +2 -2
  38. data/unittest/expected_creole/test_creole.html +3 -0
  39. data/unittest/expected_creole/test_creole_characters_all.html +10 -0
  40. data/unittest/expected_creole/test_creole_characters_all.latex +20 -0
  41. data/unittest/expected_creole/test_creole_characters_special.html +10 -0
  42. data/unittest/expected_creole/test_creole_characters_special.latex +18 -0
  43. data/unittest/expected_creole/test_creole_countdown.html +3 -0
  44. data/unittest/expected_creole/test_creole_countdown.latex +4 -0
  45. data/unittest/expected_creole/test_creole_creole1.0test.html +182 -0
  46. data/unittest/expected_creole/test_creole_creole1.0test.latex +253 -0
  47. data/unittest/expected_creole/test_creole_creole1.0test.text +160 -0
  48. data/unittest/expected_creole/test_creole_footnotes.html +9 -0
  49. data/unittest/expected_creole/test_creole_footnotes.latex +14 -0
  50. data/unittest/expected_creole/test_creole_footnotes_label.html +9 -0
  51. data/unittest/expected_creole/test_creole_headings.html +17 -0
  52. data/unittest/expected_creole/test_creole_headings.latex +19 -0
  53. data/unittest/expected_creole/test_creole_headings.text +48 -0
  54. data/unittest/expected_creole/test_creole_headings.wiki +37 -0
  55. data/unittest/expected_creole/test_creole_hr.html +7 -0
  56. data/unittest/expected_creole/test_creole_hr.latex +9 -0
  57. data/unittest/expected_creole/test_creole_hr.text +4 -0
  58. data/unittest/expected_creole/test_creole_inline.html +3 -0
  59. data/unittest/expected_creole/test_creole_inline.latex +4 -0
  60. data/unittest/expected_creole/test_creole_inline.text +2 -0
  61. data/unittest/expected_creole/test_creole_inline_ruby.html +12 -0
  62. data/unittest/expected_creole/test_creole_inline_ruby.latex +20 -0
  63. data/unittest/expected_creole/test_creole_inline_ruby_raw.html +6 -0
  64. data/unittest/expected_creole/test_creole_inline_ruby_raw.latex +8 -0
  65. data/unittest/expected_creole/test_creole_input.normsource +23 -0
  66. data/unittest/expected_creole/test_creole_label.html +12 -0
  67. data/unittest/expected_creole/test_creole_label.latex +15 -0
  68. data/unittest/expected_creole/test_creole_line_break.html +6 -0
  69. data/unittest/expected_creole/test_creole_line_break.latex +8 -0
  70. data/unittest/expected_creole/test_creole_links_explicit_internal.html +6 -0
  71. data/unittest/expected_creole/test_creole_links_explicit_internal.text +4 -0
  72. data/unittest/expected_creole/test_creole_links_explicit_with_em.html +3 -0
  73. data/unittest/expected_creole/test_creole_links_explicit_with_em.latex +4 -0
  74. data/unittest/expected_creole/test_creole_links_explicit_with_em.text +2 -0
  75. data/unittest/expected_creole/test_creole_links_external.html +6 -0
  76. data/unittest/expected_creole/test_creole_links_external.latex +8 -0
  77. data/unittest/expected_creole/test_creole_links_external.text +4 -0
  78. data/unittest/expected_creole/test_creole_links_external_implicit.html +9 -0
  79. data/unittest/expected_creole/test_creole_links_external_implicit.latex +12 -0
  80. data/unittest/expected_creole/test_creole_links_external_implicit.text +6 -0
  81. data/unittest/expected_creole/test_creole_links_file.html +6 -0
  82. data/unittest/expected_creole/test_creole_links_file.latex +8 -0
  83. data/unittest/expected_creole/test_creole_links_file.text +4 -0
  84. data/unittest/expected_creole/test_creole_list_ol.html +12 -0
  85. data/unittest/expected_creole/test_creole_list_ol.latex +22 -0
  86. data/unittest/expected_creole/test_creole_list_ol_after_ul.html +12 -0
  87. data/unittest/expected_creole/test_creole_list_ol_after_ul.latex +20 -0
  88. data/unittest/expected_creole/test_creole_list_ol_after_ul.text +6 -0
  89. data/unittest/expected_creole/test_creole_list_ol_ul.html +15 -0
  90. data/unittest/expected_creole/test_creole_list_ol_ul.latex +26 -0
  91. data/unittest/expected_creole/test_creole_list_ul.html +22 -0
  92. data/unittest/expected_creole/test_creole_list_ul.latex +40 -0
  93. data/unittest/expected_creole/test_creole_list_ul.normsource +83 -0
  94. data/unittest/expected_creole/test_creole_list_ul_too_much.html +24 -0
  95. data/unittest/expected_creole/test_creole_list_ul_too_much.latex +44 -0
  96. data/unittest/expected_creole/test_creole_newline.html +9 -0
  97. data/unittest/expected_creole/test_creole_newline.latex +11 -0
  98. data/unittest/expected_creole/test_creole_newline.text +7 -0
  99. data/unittest/expected_creole/test_creole_paragraphs.html +6 -0
  100. data/unittest/expected_creole/test_creole_paragraphs.latex +8 -0
  101. data/unittest/expected_creole/test_creole_paragraphs.normsource +27 -0
  102. data/unittest/expected_creole/test_creole_paragraphs.text +4 -0
  103. data/unittest/expected_creole/test_creole_paragraphs.wiki +4 -0
  104. data/unittest/expected_creole/test_creole_paragraphs_wrap.html +5 -0
  105. data/unittest/expected_creole/test_creole_paragraphs_wrap.latex +6 -0
  106. data/unittest/expected_creole/test_creole_paragraphs_wrap.text +4 -0
  107. data/unittest/expected_creole/test_creole_paragraphs_wrap.wiki +4 -0
  108. data/unittest/expected_creole/test_creole_paragraphs_wrap0.html +9 -0
  109. data/unittest/expected_creole/test_creole_paragraphs_wrap0.latex +11 -0
  110. data/unittest/expected_creole/test_creole_paragraphs_wrap0.text +7 -0
  111. data/unittest/expected_creole/test_creole_paragraphs_wrap0.wiki +7 -0
  112. data/unittest/expected_creole/test_creole_paragraphs_wrap60.html +5 -0
  113. data/unittest/expected_creole/test_creole_paragraphs_wrap60.latex +6 -0
  114. data/unittest/expected_creole/test_creole_paragraphs_wrap60.text +4 -0
  115. data/unittest/expected_creole/test_creole_paragraphs_wrap60.wiki +4 -0
  116. data/unittest/expected_creole/test_creole_picture_link.html +6 -0
  117. data/unittest/expected_creole/test_creole_pictures.html +10 -0
  118. data/unittest/expected_creole/test_creole_pictures.latex +13 -0
  119. data/unittest/expected_creole/test_creole_pictures_css.html +3 -0
  120. data/unittest/expected_creole/test_creole_pictures_css.latex +4 -0
  121. data/unittest/expected_creole/test_creole_pictures_imgclass.html +6 -0
  122. data/unittest/expected_creole/test_creole_pictures_imgclass.latex +8 -0
  123. data/unittest/expected_creole/test_creole_placeholders_html.html +7 -0
  124. data/unittest/expected_creole/test_creole_placeholders_html.latex +8 -0
  125. data/unittest/expected_creole/test_creole_placeholders_html.text +4 -0
  126. data/unittest/expected_creole/test_creole_placeholders_latex.html +6 -0
  127. data/unittest/expected_creole/test_creole_placeholders_latex.latex +9 -0
  128. data/unittest/expected_creole/test_creole_placeholders_latex.text +4 -0
  129. data/unittest/expected_creole/test_creole_tabular.html +20 -0
  130. data/unittest/expected_creole/test_creole_tabular.latex +22 -0
  131. data/unittest/expected_creole/test_creole_tabular_creole.html +18 -0
  132. data/unittest/expected_creole/test_creole_tabular_creole.latex +19 -0
  133. data/unittest/expected_creole/test_creole_tabular_css.html +20 -0
  134. data/unittest/expected_creole/test_creole_tabular_css.latex +22 -0
  135. data/unittest/expected_creole/test_creole_toc.html +11 -0
  136. data/unittest/expected_creole/test_creole_toc.latex +22 -0
  137. data/unittest/expected_creole/test_creole_toc.text +4 -0
  138. data/unittest/expected_creole/test_creole_toc_text.html +5 -0
  139. data/unittest/expected_creole/test_creole_toc_text.latex +5 -0
  140. data/unittest/expected_creole/test_creole_ul_multiple_line.html +7 -0
  141. data/unittest/expected_creole/test_creole_ul_multiple_line.latex +14 -0
  142. data/unittest/expected_creole/test_creole_ul_with_blank.html +11 -0
  143. data/unittest/expected_creole/test_creole_ul_with_blank.latex +20 -0
  144. data/unittest/expected_creole/test_creole_ul_with_bold.creole +0 -0
  145. data/unittest/expected_creole/test_creole_ul_with_bold.html +11 -0
  146. data/unittest/expected_creole/test_creole_ul_with_bold.latex +18 -0
  147. data/unittest/expected_creole/test_creole_ul_with_bold.text +7 -0
  148. data/unittest/expected_creole/test_creole_verbatim.html +25 -0
  149. data/unittest/expected_creole/test_creole_verbatim.latex +33 -0
  150. data/unittest/expected_creole/test_creole_verbatim.text +17 -0
  151. data/unittest/expected_creole/test_creole_verbatim_inline.html +6 -0
  152. data/unittest/expected_creole/test_creole_verbatim_inline.latex +8 -0
  153. data/unittest/expected_creole/test_creole_verbatim_inline_at_start.html +6 -0
  154. data/unittest/expected_creole/test_creole_verbatim_inline_at_start.latex +8 -0
  155. data/unittest/expected_privat/test_creole_test_document.html +6 -0
  156. data/unittest/{expected → expected_wiki}/test_wiki.html +0 -0
  157. data/unittest/{expected → expected_wiki}/test_wiki.latex +0 -0
  158. data/unittest/{expected → expected_wiki}/test_wiki.text +0 -0
  159. data/unittest/{expected → expected_wiki}/test_wiki.wiki +0 -0
  160. data/unittest/{expected → expected_wiki}/test_wiki_amazon.html +0 -0
  161. data/unittest/{expected → expected_wiki}/test_wiki_description.html +0 -0
  162. data/unittest/{expected → expected_wiki}/test_wiki_description.latex +0 -0
  163. data/unittest/{expected → expected_wiki}/test_wiki_description.text +0 -0
  164. data/unittest/{expected → expected_wiki}/test_wiki_description.wiki +0 -0
  165. data/unittest/expected_wiki/test_wiki_footnote.html +8 -0
  166. data/unittest/expected_wiki/test_wiki_footnote.latex +17 -0
  167. data/unittest/{expected → expected_wiki}/test_wiki_footnote.text +2 -4
  168. data/unittest/expected_wiki/test_wiki_footnote.wiki +10 -0
  169. data/unittest/expected_wiki/test_wiki_footnote_2.html +8 -0
  170. data/unittest/expected_wiki/test_wiki_footnote_groupid.html +21 -0
  171. data/unittest/{expected → expected_wiki}/test_wiki_html_code.html +0 -0
  172. data/unittest/{expected → expected_wiki}/test_wiki_html_code.latex +0 -0
  173. data/unittest/{expected → expected_wiki}/test_wiki_html_code.text +0 -0
  174. data/unittest/{expected → expected_wiki}/test_wiki_html_code.wiki +0 -0
  175. data/unittest/{expected → expected_wiki}/test_wiki_inline.html +0 -0
  176. data/unittest/{expected → expected_wiki}/test_wiki_inline.latex +0 -0
  177. data/unittest/{expected → expected_wiki}/test_wiki_inline.text +0 -0
  178. data/unittest/{expected → expected_wiki}/test_wiki_inline.wiki +0 -0
  179. data/unittest/{expected → expected_wiki}/test_wiki_label.html +0 -0
  180. data/unittest/{expected → expected_wiki}/test_wiki_link.html +0 -0
  181. data/unittest/{expected → expected_wiki}/test_wiki_link.latex +0 -0
  182. data/unittest/{expected → expected_wiki}/test_wiki_link.log +0 -0
  183. data/unittest/{expected → expected_wiki}/test_wiki_link.wiki +0 -0
  184. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.html +0 -0
  185. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.latex +0 -0
  186. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.text +0 -0
  187. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.wiki +0 -0
  188. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.html +0 -0
  189. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.latex +0 -0
  190. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.text +0 -0
  191. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.wiki +0 -0
  192. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.html +0 -0
  193. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.latex +0 -0
  194. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.text +0 -0
  195. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.wiki +0 -0
  196. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.html +0 -0
  197. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.latex +0 -0
  198. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.text +0 -0
  199. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.wiki +0 -0
  200. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.html +0 -0
  201. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.latex +0 -0
  202. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.text +0 -0
  203. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.wiki +0 -0
  204. data/unittest/{expected → expected_wiki}/test_wiki_picture.html +0 -0
  205. data/unittest/{expected → expected_wiki}/test_wiki_picture.latex +0 -0
  206. data/unittest/{expected → expected_wiki}/test_wiki_picture_thumb.html +0 -0
  207. data/unittest/{expected → expected_wiki}/test_wiki_tab1.html +0 -0
  208. data/unittest/{expected → expected_wiki}/test_wiki_tab1.latex +0 -0
  209. data/unittest/{expected → expected_wiki}/test_wiki_tab1.wiki +0 -0
  210. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.html +0 -0
  211. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.latex +0 -0
  212. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.text +0 -0
  213. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.wiki +0 -0
  214. data/unittest/{expected → expected_wiki}/test_wiki_toc.html +0 -0
  215. data/unittest/{expected → expected_wiki}/test_wiki_toc.latex +0 -0
  216. data/unittest/{expected → expected_wiki}/test_wiki_toc.text +0 -0
  217. data/unittest/{expected → expected_wiki}/test_wiki_toc.wiki +0 -0
  218. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.html +0 -0
  219. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.latex +0 -0
  220. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.text +0 -0
  221. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.wiki +0 -0
  222. data/unittest/test_docgenerator.rb +1 -2
  223. data/unittest/unittest_creole2doc.rb +1024 -0
  224. data/unittest/unittest_docgenerator.rb +17 -8
  225. data/unittest/unittest_wiki2doc.rb +92 -88
  226. data/unittest/unittest_yaml2pres.rb +336 -0
  227. metadata +202 -70
  228. data/unittest/expected/test_wiki_footnote.html +0 -8
  229. data/unittest/expected/test_wiki_footnote.latex +0 -15
  230. data/unittest/expected/test_wiki_footnote.wiki +0 -12
  231. data/unittest/expected/test_wiki_footnote_groupid.html +0 -21
@@ -7,20 +7,20 @@
7
7
  #Redefine is_a?:
8
8
  #Return true, when you test with a symbol.
9
9
  class Object
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
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
- #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
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
- SUPPORTED_TARGETS = [ :latex, :html, :wiki, :text, :debug ]
99
+ SUPPORTED_TARGETS = [ :latex, :html, :wiki, :text, :debug ]
100
100
 
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.
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
- #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
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
- 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 )
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
- #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( )
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
- 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
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
- 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 )
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
- 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
- def initialize( attr={}, content = nil)
289
- #@attr is a hash containing the values for each attribute.
290
- @attr = Hash.new( )
291
- @log = DOCGENERATOR_LOGGER
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
- @attr_alias = Hash.new( )
298
+ @attr_alias = Hash.new( )
294
299
  if self.content?()
295
- @content = []
300
+ @content = []
296
301
  else
297
- @content = nil
302
+ @content = nil
298
303
  end
299
- @crbefore = false #make \n before element
300
- @crmid = false #make \n before and after opening/closing html-tag
301
- @crafter = false #make \n after element
302
- #List of targets, where the element can be used.
303
- #Details see method restrict_to()
304
- #Default: allsupported targets
305
- @targets = SUPPORTED_TARGETS.dup
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
- #Initialize the attribute hash.
309
- @@attr[self.class].each{ |k,a|
310
- #type check on Attribute does not work .
311
- if a.kind_of?( Symbol )
312
- #Filled in the second run
313
- #~ @attr[k] = @attr[a]
314
- elsif a #.kind_of?( Attribute )
315
- @attr[k] = a.new( k, self )
316
- else
317
- @attr[k] = Attribute.create().new( k, self )
318
- end
319
- }
320
- #Assign Alias-Attributes
321
- @@attr[self.class].each{ |k,a|
322
- next if !a.kind_of?( Symbol )
323
- if @attr[a]
324
- @attr_alias[k] = @attr[a]
325
- else
326
- puts "Undefined Alias-Attribute #{k}"
327
- @attr[k] = Attribute.create().new( k, self )
328
- end
329
- }
330
- attr.each{ |k,v|
331
- if @attr[k]
332
- @attr[k] << v
333
- elsif @attr_alias[k]
334
- @attr_alias[k] << v
335
- else
336
- puts "Usage of unknown attribute '#{k}' in '#{self.ids.join(',')}'"
337
- end
338
- }
339
- @called_by = prepare_tracing_info( @@trace )
340
- self << content if content
341
- end
342
- #List (array) of targets, where the element can be used.
343
- #Default are all supported targets.
344
- #
345
- #With restrictions of this attribute, elements can be restricted on special documents.
346
- def restrict_to( *argv )
347
- @targets = []
348
- @suppressed_targets = SUPPORTED_TARGETS.dup
349
- @log.warn("Element#restrict_to: #{self.inspect} restrict to #{argv.inspect}") if @log.warn?
350
- argv.each{ |arg|
351
- #~ if ! SUPPORTED_TARGETS.include?( arg )
352
- if ! @suppressed_targets.delete( arg )
353
- @log.warn("Restriction for unsupported target #{arg}") if @log.warn?
354
- end
355
- @targets << arg
356
- }
357
- self
358
- end
359
- #Only for debbuging reasons.
360
- #Should contain the first "no docgenerator.rb-place, where part is called
361
- #if @@trace is on, some tracing information is stored during creation.
362
- def prepare_tracing_info( doit = @@trace )
363
- return nil if ! doit
364
- caller().each{|c|
365
- next if ( /DocumentGenerator/ =~ c )
366
- return c
367
- }
368
- #--> No calling stack found --> Error
369
- puts '----'*10
370
- puts 'Element#prepare_tracing_info: Found no starting place in caller stack'
371
- caller().each{|c| puts c }
372
- puts '----'*10
373
- return caller()
374
- end
375
- def inspect()
376
- if @@trace
377
- called_by = ", Created in #{@called_by}"
378
- else
379
- called_by = nil #'unknown. Please set Elements.trace if needed'
380
- end
381
- return "<Class Element(#{self.ids.join(',')})#{called_by}>"
382
- #~ if @content
383
- #~ return "<Class Element(#{self.ids.join(',')}) @content=#{@content.inspect}>"
384
- #~ else
385
- #~ return "<Class Element(#{self.ids.join(',')}) @attr=#{@attr.inspect}>"
386
- #~ end
387
- end
388
- #Accessor on content
389
- attr_reader :content
390
- #Add something to the content.
391
- #Only possible on elements, which supports "content".
392
- def << ( content )
393
- if @content
394
- @content << content
395
- else
396
- @log.warn("Add content to an element without this feature #{self.ids.inspect}, #{content.inspect}") if @log.warn?
397
- end
398
- end
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
- #Add content after a target (other content)
401
- # insertafter(target,*obj)
402
- #Requires the ability of "content".
403
- def insertafter(target,*obj)
404
- self.insert(target, 1, obj)
405
- end
406
- #Add content before a target (other content)
407
- # insertbefore(target,*obj)
408
- #Requires the ability of "content".
409
- def insertbefore(target,*obj)
410
- self.insert(target, 0, obj)
411
- end
412
- #Insert content relative to a given target.
413
- #The target must exist, pos defines the relative position (0=before, 1=one after the element).
414
- #Method called by Element#insertbefore and Element#insertafter.
415
- def insert(target,pos,*obj )
416
- if @content
417
- if @content.include?( target )
418
- @content[@content.index(target)+pos ,0] = obj
419
- else
420
- puts "Insert content not possible. Reference object does not exist (#{target.inspect})"
421
- end
422
- else
423
- puts "Add content to an element without this feature"
424
- end
425
- self
426
- end
427
- #Delete the given object.
428
- def delete(target )
429
- if @content
430
- @content.delete( target )
431
- else
432
- puts "Delete content of an element without this feature"
433
- end
434
- self
435
- end
436
- #Insert an empty line after the last entry
437
- def cr()
438
- @crafter = true
439
- self
440
- end
441
- #Insert an empty line before and after the last entry
442
- def Cr()
443
- @crbefore = true
444
- @crafter = true
445
- self
446
- end
447
- #Insert an empty line after the last entry and after the opening of the tag.
448
- #This feature has it reason for lists, when each :li-tag gets a cr.
449
- #The first item gets also a cr.
450
- def cR()
451
- @crbefore = false
452
- @crmid = true
453
- @crafter = true
454
- self
455
- end
456
- #Insert an empty line before and after the last entry and after the opening of the tag.
457
- def CR()
458
- @crbefore = true
459
- @crmid = true
460
- @crafter = true
461
- self
462
- end
463
- #Accessor on attribute list
464
- attr_reader :attr
465
- #Return an attribute to add content.
466
- def [] (key)
467
- attr = @attr[key]
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
- attr = @attr_alias[key] if !attr
470
- if !attr
471
- puts "Request unknown attribute '#{key}', return a dummy"
472
- attr = Attribute.create( ).new(key, self)
473
- end
474
- return attr
475
- end
476
- #Default setting, each element class may contain contents.
477
- #Can be redefined by Elements.create.
478
- #-true: content available and necessary (e.g. <p>)
479
- #-:empty_ok: content available, but not necessary (e.g. <td>)
480
- #-false: no content, no endtag, but tag closed with / (example: <br />)
481
- #-nil: no content, no endtag, no closing (example: <br>)
482
- def content?()
483
- return true
484
- end
485
- #check if there is content assigned.
486
- def empty?()
487
- return @content.empty?
488
- end
489
- @@level = 0
490
- #Build a String to be used for the target document.
491
- #Calls Element#to_latex and Element#to_html.
492
- #~ def to_s( target = Document.target( self ) )
493
- def to_doc( target, options = {} )
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
- #Return empty string, if target is not requested.
497
- if ! @targets.include?( target )
503
+ #Return empty string, if target is not requested.
504
+ if ! @targets.include?( target )
498
505
  if @suppressed_targets.include?(target)
499
- o[:log].info("Element#to_doc: Content of #{self.inspect} suppressed for Target #{target.inspect}.") if o[:log].info?
506
+ o[:log].info("Element#to_doc: Content of #{self.inspect} suppressed for Target #{target.inspect}.") if o[:log].info?
500
507
  else
501
- o[:log].warn("Element#to_doc: Target #{target.inspect} not supported for #{self.inspect}.") if o[:log].warn?
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
- return ''
504
- end
505
- #Some checks
506
- @attr.each{|k,v|
507
- if v.required? and v.to_s == '' and v.settings.include?(target)
508
- o[:log].error "#{self.ids}: Attribut '#{k}' without required value" if o[:log].error?
509
- end
510
- }
511
- #Build the string.
512
- result = ''
513
- case target
514
- when :latex
515
- result = to_latex(o)
516
- when :html
517
- result = to_html(o)
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
- #~ result = "\n#{result}" if @crbefore
527
- #~ result << "\n" if @crafter
528
- return result
529
- end
530
- #This is a dummy method, called from Element#to_s for the target format LaTeX.
531
- #This method must be overwritten from the element class.
532
- #
533
- #By default, the concatenation of all ids and the content is taken.
534
- def to_latex(options = {})
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
- o[:log].error("Missing output routine for LaTeX (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
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
- cmd = ''
542
- cmd << "\n" if @crbefore
543
- cmd << "\\#{makroname}{#{@content}}"
544
- cmd << "\n" if @crafter
545
- return cmd
546
- end
547
- #Method for definition inside Element.create.
548
- def linebreak( flag = true )
549
- flag ? "\n" : ''
550
- end
551
- #Prints the optional attribut key inside []. If empty, nil is returned
552
- def texoptional(key)
553
- return nil if ! @attr[key].filled?
554
- return "[#{@attr[key]}]"
555
- end
556
- #Build key-val options from attributs.
557
- #Used e.g. by includegraphics.
558
- def texkeyval()
559
- keyval = []
560
- @attr.sort_by{|k,v| v.sortkey }.each{|k,v|
561
- keyval << "#{k}={#{v}}" if v.to_s != '' and v.texkeyval?
562
- }
563
- return keyval.join(', ')
564
- end
565
- #Method for html-output.
566
- #If the method is redefined, the result is taken as a tag.
567
- def htmltag()
568
- ''
569
- end
570
- #This is a dummy method, called from Element#to_s for the target format HTML.
571
- #The tag from Element.htmltag is taken and all attributes and the content are used.
572
- #
573
- #This method can be overwriten from the element class.
574
- def to_html(options = {})
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
- tag = htmltag()
577
- if ! tag
583
+ tag = htmltag()
584
+ if ! tag
578
585
  o[:log].error("No HTML element available (#{self.ids.join(',')})") if o[:log].error?
579
- return ''
580
- elsif tag == ''
581
- tag = 'span'
582
- o[:log].error("Missing output routine for HTML (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
583
- end
584
- #Test if the HTML-Tag should contain something, but there is nothing.
585
- #If :empty_ok it is ok, that there is no content (e.g <td>)
586
- #May make problems, if an empty tag is used to set a id-mark.
587
- if content?() and content? != :empty_ok and
588
- ( ! @content or @content == [] or @content == [nil] )
589
- o[:log].warn("HTML-Tag #{tag} without content -> ignored") if o[:log].warn?
590
- return ''
591
- end
592
- html = String.new()
593
- html << "\n" if @crbefore
594
- html << "<#{tag} "
595
- @attr.sort_by{|k,v| v.sortkey }.each{|k,v|
596
- html << "#{k} = \"#{v}\" " if v.to_s != '' and v.html?
597
- }
598
- if @content
599
- html << ">"
600
- html <<"\n" if @crmid
601
- html << "#{@content.to_html(options)}"
602
- html << "\n" if @crmid and @content.size > 0 and html[-1,1] != "\n"
603
- html << "</#{tag}>"
604
- elsif content?() == nil
605
- html << '>'
606
- else
607
- html << '/>'
608
- end
609
- html << "\n" if @crafter
610
- return html
611
- end #to_html
612
- def to_wiki(options = {})
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
- o[:log].error("Missing output routine for Wiki (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
615
- return "#{@content.to_wiki(options)}\n"
616
- end
617
- def to_text(options = {})
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
- o[:log].error("Missing output routine for Text (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
620
- text = String.new()
621
- text << "\n" if @crbefore
622
- text = "#{@content.to_text(options)}".strip
623
- text << "\n" if @crafter
624
- return text
625
- end
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