docgenerator 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. data/build_test_and_doc.rb +505 -0
  2. data/examples/creole_example.rb +82 -0
  3. data/examples/creole_example_footnote.rb +67 -0
  4. data/examples/creole_example_placeholder.rb +77 -0
  5. data/examples/creole_example_rail.rb +154 -0
  6. data/examples/creole_example_rubycode.rb +144 -0
  7. data/examples/creole_example_struktex.rb +169 -0
  8. data/examples/docgenerator_example.rb +1 -1
  9. data/examples/docgenerator_example_footnote.rb +1 -0
  10. data/examples/docgenerator_example_list.rb +3 -0
  11. data/examples/docgenerator_example_restrictions.rb +1 -1
  12. data/examples/docgenerator_example_tabular.rb +1 -1
  13. data/examples/docgenerator_example_tripfalls.rb +2 -2
  14. data/examples/results/readme +2 -1
  15. data/examples/wiki2docgenerator_example.rb +61 -32
  16. data/lib/creole/creole2doc.rb +57 -58
  17. data/lib/creole/creole_characters.rb +56 -0
  18. data/lib/creole/creole_inclusion_and_plugins.rb +59 -284
  19. data/lib/creole/creole_inclusions.rb +142 -0
  20. data/lib/creole/creole_placeholder.rb +57 -23
  21. data/lib/creole/creole_plugins.rb +198 -0
  22. data/lib/creole/creole_tabular.rb +16 -8
  23. data/lib/creole/plugins/rail.rb +182 -0
  24. data/lib/creole/plugins/rubycode4creole.rb +136 -0
  25. data/lib/creole/plugins/struktex.rb +59 -0
  26. data/lib/creole/plugins/todonotes.rb +70 -0
  27. data/lib/docgenerator.rb +161 -71
  28. data/lib/docgenerator/attribute.rb +189 -156
  29. data/lib/docgenerator/characters.rb +824 -267
  30. data/lib/docgenerator/compatibility_v1.rb +249 -0
  31. data/lib/docgenerator/css.rb +53 -32
  32. data/lib/docgenerator/document.rb +119 -56
  33. data/lib/docgenerator/element.rb +304 -351
  34. data/lib/docgenerator/element_meta.rb +303 -0
  35. data/lib/docgenerator/elements.rb +1112 -481
  36. data/lib/docgenerator/environments.rb +153 -62
  37. data/lib/docgenerator/footnote.rb +30 -9
  38. data/lib/docgenerator/lists.rb +71 -47
  39. data/lib/docgenerator/packages/attachfile.rb +136 -0
  40. data/lib/{packages/docgenerator_caption.rb → docgenerator/packages/caption.rb} +28 -19
  41. data/lib/docgenerator/packages/hyperref.rb +194 -0
  42. data/lib/docgenerator/packages/listings.rb +179 -0
  43. data/lib/docgenerator/packages/pdfpages.rb +43 -0
  44. data/lib/docgenerator/packages/rubycode4doc.rb +227 -0
  45. data/lib/{packages/docgenerator_scrlettr2.rb → docgenerator/packages/scrlettr2.rb} +25 -16
  46. data/lib/docgenerator/packages/scrpage2.rb +410 -0
  47. data/lib/docgenerator/packages/struktex.rb +447 -0
  48. data/lib/docgenerator/packages/todonotes.rb +85 -0
  49. data/lib/{packages/docgenerator_url.rb → docgenerator/packages/url.rb} +7 -6
  50. data/lib/docgenerator/sections.rb +257 -83
  51. data/lib/docgenerator/standard.rb +19 -11
  52. data/lib/docgenerator/tabular.rb +234 -118
  53. data/lib/{templates → docgenerator/templates}/docgenerator_template.rb +52 -44
  54. data/lib/{templates → docgenerator/templates}/docgenerator_template.yaml +0 -0
  55. data/lib/{templates → docgenerator/templates}/docgenerator_template_css.rb +22 -16
  56. data/lib/wiki2doc/plugins/rubycode4wiki.rb +53 -0
  57. data/lib/wiki2doc/plugins/struktex.rb +12 -0
  58. data/lib/wiki2doc/wiki2docgenerator.rb +39 -38
  59. data/lib/wiki2doc/wikimedia_document.rb +24 -0
  60. data/manpage_elements.rb +10411 -0
  61. data/readme.rd +34 -24
  62. data/unittest/creole_testtext.creole +11 -0
  63. data/unittest/expected/test_document_usepackage_undefined.log +2 -2
  64. data/unittest/expected/test_runtex.stdout +0 -1
  65. data/unittest/expected/test_runtex_2.stdout +0 -1
  66. data/unittest/expected/toc_css.css +3 -2
  67. data/unittest/expected_creole/test_creole_characters_all.creole +28 -0
  68. data/unittest/expected_creole/test_creole_characters_all.html +15 -15
  69. data/unittest/expected_creole/test_creole_characters_all.latex +15 -15
  70. data/unittest/expected_creole/test_creole_footnotes_groupid.html +15 -0
  71. data/unittest/expected_creole/test_creole_links_file.html +2 -2
  72. data/unittest/expected_creole/test_creole_links_file.latex +2 -2
  73. data/unittest/expected_creole/test_creole_links_file.text +2 -2
  74. data/unittest/expected_creole/test_creole_picture_link.html +1 -1
  75. data/unittest/expected_creole_rail/test_rail_creole_object.tex +33 -0
  76. data/unittest/expected_creole_rail/test_rail_creole_placeholder.tex +40 -0
  77. data/unittest/expected_rubycode4doc/creole_complete.html +26 -0
  78. data/unittest/expected_rubycode4doc/creole_complete.tex +40 -0
  79. data/unittest/expected_rubycode4doc/creole_in_tab.html +4 -0
  80. data/unittest/expected_rubycode4doc/creole_in_tab.tex +6 -0
  81. data/unittest/expected_rubycode4doc/creole_inline_ruby.html +7 -0
  82. data/unittest/expected_rubycode4doc/creole_output.html +2 -0
  83. data/unittest/expected_rubycode4doc/creole_output.tex +4 -0
  84. data/unittest/expected_rubycode4doc/creole_rubycode.html +1 -0
  85. data/unittest/expected_rubycode4doc/creole_rubycode.tex +3 -0
  86. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated.html +1 -0
  87. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated.tex +3 -0
  88. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated_listings.html +3 -0
  89. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated_listings.tex +5 -0
  90. data/unittest/expected_rubycode4doc/wiki_1.html +8 -0
  91. data/unittest/expected_rubycode4doc/wiki_2.html +8 -0
  92. data/unittest/expected_rubycode4doc/wiki_3.html +9 -0
  93. data/unittest/expected_rubycode4doc/wiki_immediate_1.html +5 -0
  94. data/unittest/expected_rubycode4doc/wiki_immediate_2.html +5 -0
  95. data/unittest/expected_rubycode4doc/wiki_immediate_3.html +8 -0
  96. data/unittest/expected_rubycode4doc/wiki_immediate_full.html +21 -0
  97. data/unittest/expected_struktex/test_struktex_krug.creole +15 -0
  98. data/unittest/expected_struktex/test_struktex_krug.tex +19 -0
  99. data/unittest/expected_struktex/test_struktex_krug.wiki +15 -0
  100. data/unittest/expected_struktex/test_struktex_statement.creole +7 -0
  101. data/unittest/expected_struktex/test_struktex_statement.tex +9 -0
  102. data/unittest/expected_struktex/test_struktex_statement.wiki +7 -0
  103. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.html +0 -0
  104. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.latex +0 -0
  105. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.text +0 -0
  106. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.wiki +0 -0
  107. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.html +1 -1
  108. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.latex +1 -1
  109. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.text +1 -1
  110. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.wiki +1 -1
  111. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.html +0 -0
  112. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.latex +0 -0
  113. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.text +0 -0
  114. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.wiki +0 -0
  115. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote_2.html +0 -0
  116. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote_groupid.html +0 -0
  117. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.html +0 -0
  118. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.latex +0 -0
  119. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.text +0 -0
  120. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.wiki +0 -0
  121. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.html +0 -0
  122. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.latex +0 -0
  123. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.text +0 -0
  124. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.wiki +0 -0
  125. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_label.html +0 -0
  126. data/unittest/expected_wikimedia/test_wiki_link.html +8 -0
  127. data/unittest/expected_wikimedia/test_wiki_link.latex +17 -0
  128. data/unittest/expected_wikimedia/test_wiki_link.wiki +11 -0
  129. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.html +0 -0
  130. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.latex +0 -0
  131. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.text +0 -0
  132. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.wiki +0 -0
  133. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.html +0 -0
  134. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.latex +0 -0
  135. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.text +0 -0
  136. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.wiki +0 -0
  137. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.html +0 -0
  138. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.latex +0 -0
  139. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.text +0 -0
  140. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.wiki +0 -0
  141. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.html +0 -0
  142. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.latex +0 -0
  143. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.text +0 -0
  144. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.wiki +0 -0
  145. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.html +0 -0
  146. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.latex +0 -0
  147. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.text +0 -0
  148. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.wiki +0 -0
  149. data/unittest/expected_wikimedia/test_wiki_picture.html +55 -0
  150. data/unittest/expected_wikimedia/test_wiki_picture.latex +76 -0
  151. data/unittest/expected_wikimedia/test_wiki_picture_thumb.html +5 -0
  152. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_tab1.html +0 -0
  153. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_tab1.latex +0 -0
  154. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_tab1.wiki +0 -0
  155. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.html +0 -0
  156. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.latex +0 -0
  157. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.text +0 -0
  158. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.wiki +0 -0
  159. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.html +0 -0
  160. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.latex +0 -0
  161. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.text +0 -0
  162. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.wiki +0 -0
  163. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.html +0 -0
  164. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.latex +0 -0
  165. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.text +0 -0
  166. data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.wiki +0 -0
  167. data/unittest/{unittest_creole2doc.rb → unittest_creole.rb} +385 -476
  168. data/unittest/unittest_creole_placeholders.rb +272 -0
  169. data/unittest/unittest_creole_plugin_rail.rb +147 -0
  170. data/unittest/unittest_docgenerator.rb +206 -332
  171. data/unittest/unittest_docgenerator_characters.rb +650 -0
  172. data/unittest/unittest_docgenerator_runtex.rb +48 -20
  173. data/unittest/unittest_packages_struktex.rb +187 -0
  174. data/unittest/unittest_rubycode4doc.rb +275 -0
  175. data/unittest/unittest_wikimedia.rb +479 -0
  176. metadata +245 -172
  177. data/examples/results_expected/docgenerator_example.html +0 -39
  178. data/examples/results_expected/docgenerator_example.pdf +0 -0
  179. data/examples/results_expected/docgenerator_example.tex +0 -56
  180. data/examples/results_expected/docgenerator_example_footnote.html +0 -40
  181. data/examples/results_expected/docgenerator_example_footnote.pdf +0 -0
  182. data/examples/results_expected/docgenerator_example_footnote.tex +0 -50
  183. data/examples/results_expected/docgenerator_example_list.html +0 -18
  184. data/examples/results_expected/docgenerator_example_list.pdf +0 -0
  185. data/examples/results_expected/docgenerator_example_list.tex +0 -46
  186. data/examples/results_expected/docgenerator_example_restrictions.html +0 -22
  187. data/examples/results_expected/docgenerator_example_restrictions.pdf +0 -0
  188. data/examples/results_expected/docgenerator_example_restrictions.tex +0 -31
  189. data/examples/results_expected/docgenerator_example_tabular.html +0 -37
  190. data/examples/results_expected/docgenerator_example_tabular.pdf +0 -0
  191. data/examples/results_expected/docgenerator_example_tabular.tex +0 -41
  192. data/examples/results_expected/docgenerator_example_tripfalls.html +0 -27
  193. data/examples/results_expected/docgenerator_example_tripfalls.pdf +0 -0
  194. data/examples/results_expected/docgenerator_example_tripfalls.tex +0 -31
  195. data/lib/packages/docgenerator_attachfile.rb +0 -71
  196. data/lib/packages/docgenerator_hyperref.rb +0 -109
  197. data/lib/packages/docgenerator_listings.rb +0 -103
  198. data/lib/packages/docgenerator_pdfpages.rb +0 -24
  199. data/lib/packages/docgenerator_scrpage2.rb +0 -172
  200. data/self_docgenerator.rb +0 -163
  201. data/unittest/expected_wiki/test_wiki_link.html +0 -8
  202. data/unittest/expected_wiki/test_wiki_link.latex +0 -17
  203. data/unittest/expected_wiki/test_wiki_link.wiki +0 -11
  204. data/unittest/expected_wiki/test_wiki_picture.html +0 -55
  205. data/unittest/expected_wiki/test_wiki_picture.latex +0 -76
  206. data/unittest/expected_wiki/test_wiki_picture_thumb.html +0 -5
  207. data/unittest/test_rakefile_docgenerator.rb +0 -43
  208. data/unittest/unittest_versions.rb +0 -44
  209. data/unittest/unittest_wiki2doc.rb +0 -464
@@ -0,0 +1,505 @@
1
+ #encoding: utf-8
2
+ =begin
3
+ Generates new versions for test.
4
+
5
+ Generates:
6
+ *unittest_docgenerator_characters.rb based on
7
+ * test for each element
8
+ =end
9
+
10
+ #~ Dir['lib/**/wiki*/*'].each{|file| puts "require '#{file}'".sub(/lib\//,'') }
11
+ #~ exit
12
+
13
+ require 'date'
14
+ $:.unshift('lib')
15
+ require 'docgenerator'
16
+ Docgenerator::DOCGENERATOR_LOGGER.level = Log4r::WARN
17
+ #~ require 'docgenerator/compatibility_v1'
18
+ require 'docgenerator/packages/attachfile.rb'
19
+ require 'docgenerator/packages/caption.rb'
20
+ require 'docgenerator/packages/hyperref.rb'
21
+ require 'docgenerator/packages/listings.rb'
22
+ require 'docgenerator/packages/pdfpages.rb'
23
+ require 'docgenerator/packages/rubycode4doc.rb'
24
+ require 'docgenerator/packages/scrlettr2.rb'
25
+ require 'docgenerator/packages/scrpage2.rb'
26
+ require 'docgenerator/packages/struktex.rb'
27
+ require 'docgenerator/packages/todonotes.rb'
28
+ require 'docgenerator/packages/url.rb'
29
+
30
+ require 'creole/creole2doc.rb'
31
+ require 'creole/plugins/rail.rb'
32
+ require 'creole/plugins/rubycode4creole.rb'
33
+ require 'creole/plugins/struktex.rb'
34
+ require 'creole/plugins/todonotes.rb'
35
+
36
+ require 'wiki2doc/wiki2docgenerator.rb'
37
+ require 'wiki2doc/plugins/rubycode4wiki.rb'
38
+ require 'wiki2doc/plugins/struktex.rb'
39
+
40
+
41
+ =begin rdoc
42
+ List all known elements
43
+ =end
44
+ def puts_elements
45
+ ObjectSpace.each_object(Class).map{|o|
46
+ o.name || ''
47
+ }.sort.each{|o|
48
+ puts o if o =~ /^Docgenerator/
49
+ #~ puts o if o.is_a?(Docgenerator::Element)
50
+ }
51
+ end
52
+
53
+
54
+
55
+ =begin rdoc
56
+ Define a new outputter to catch data into an array
57
+ =end
58
+ class ArrayOutputter < Log4r::StdoutOutputter
59
+ =begin rdoc
60
+ Collect messages in array.
61
+ =end
62
+ def write(message)
63
+ @messages ||= [] #create with first call
64
+ @messages << message
65
+ end
66
+ =begin rdoc
67
+ Clear message array and return messages
68
+ =end
69
+ def flush
70
+ @messages ||= [] #create with first call
71
+ messages = @messages.dup
72
+ @messages.clear
73
+ messages
74
+ end
75
+ end #ArrayOutputter
76
+
77
+ TESTHEAD = <<testhead
78
+ #encoding: utf-8
79
+
80
+ =begin rdoc
81
+ Test generated by #{__FILE__} #{Date.today}
82
+ =end
83
+
84
+ gem 'test-unit'
85
+ require 'test/unit'
86
+
87
+ if $0 == __FILE__
88
+ $:.unshift("../lib")
89
+ end
90
+ require 'docgenerator'
91
+ #~ DOCGENERATOR_LOGGER.level = Log4r::DEBUG
92
+
93
+ =begin rdoc
94
+ Define a new outputter to catch data into an array
95
+ =end
96
+ class ArrayOutputter < Log4r::StdoutOutputter
97
+ =begin rdoc
98
+ Collect messages in array.
99
+ =end
100
+ def write(message)
101
+ @messages ||= [] #create with first call
102
+ @messages << message
103
+ end
104
+ =begin rdoc
105
+ Clear message array and return messages
106
+ =end
107
+ def flush
108
+ @messages ||= [] #create with first call
109
+ messages = @messages.dup
110
+ @messages.clear
111
+ messages
112
+ end
113
+ end #ArrayOutputter
114
+
115
+ testhead
116
+
117
+ def mk_character_test(filename = "unittest/unittest_docgenerator_characters_#{Date.today}.xx")
118
+ File.open(filename, 'w:utf-8'){|f_test|
119
+ puts "Create #{f_test.path}"
120
+ f_test << TESTHEAD
121
+ f_test << <<code
122
+ include Docgenerator
123
+ class Test_characters < Test::Unit::TestCase
124
+ def self.startup()
125
+ #DEBUG would contain messages
126
+ @@log = Log4r::Logger.new('Test_characters', Log4r::INFO)
127
+ @@log.outputters = @@logoutputter = ArrayOutputter.new('xx')
128
+ end #self.startup()
129
+
130
+ code
131
+
132
+ #Some Coding to prepare the unit tests
133
+ els = nil
134
+ lclass = nil
135
+ File.open('../lib/docgenerator/characters.rb', 'r:utf-8').each_line{|line|#
136
+ case line
137
+ when /\A\s*#/ #skip
138
+ when /class\s*(\w+)\s/
139
+ lclass = $1
140
+ els = [ $1.downcase.to_sym ]
141
+ when /add_id\s*(\w+)/
142
+ els << $1
143
+ when /add_(html|latex|wiki|creole|text)_output\s*'(.+?)'/
144
+ target = $1
145
+ result = $2.sub(/'/, "''")
146
+ f_test << "\n def test_character_#{lclass}_#{target}()\n"
147
+ els.each{|el|
148
+ if result.sub!(/\#\{@content\}/, '1')
149
+ f_test << " assert_equal( '#{result}', element(#{el.inspect}, {}, 1).to_#{target}( :log => @@log))\n"
150
+ else
151
+ f_test << " assert_equal( '#{result}', element(#{el.inspect}).to_#{target}( :log => @@log))\n"
152
+ end
153
+ f_test << " assert_equal( [], @@logoutputter.flush)\n"
154
+ }
155
+ f_test << " end #test_character_#{lclass}_#{target}\n"
156
+ end
157
+ }
158
+
159
+ f_test << <<code
160
+ end #class Test_characters
161
+ code
162
+ }
163
+ end #mk_character_test()
164
+
165
+ class Docgenerator::Element
166
+ def self.each()
167
+ @@ids.values.uniq.each{|cl| yield cl }
168
+ end
169
+ end
170
+
171
+ def mk_element_test(pattern)
172
+
173
+ testcode= []
174
+ Docgenerator::Element.each{|cl|
175
+ next unless cl.name =~ pattern
176
+ #exclude dummy element.
177
+ next if %w{Docgenerator::Sectioning::DummySectioning}.include?(cl.name.to_s)
178
+ p cl.name
179
+
180
+ testclass = "Test_element_#{cl.name.downcase.gsub(/::/, '_')}"
181
+ @@log = Log4r::Logger.new(cl.element_ids.first.to_s, Log4r::DEBUG)
182
+ @@log.outputters = @@logoutputter = ArrayOutputter.new('xx')
183
+ @@el = cl.new(:log => @@log )
184
+ testcode << <<code
185
+ =begin rdoc
186
+ Test #{cl.name}.
187
+ =end
188
+ class #{testclass} < Test::Unit::TestCase
189
+ def self.startup()
190
+ @@log = Log4r::Logger.new('#{cl.element_ids.first.to_s}', Log4r::DEBUG)
191
+ @@log.outputters = @@logoutputter = ArrayOutputter.new('xx')
192
+ @@el = #{cl.name}.new(:log => @@log)
193
+
194
+ #fill attributes
195
+ code
196
+ @@el.attr.each{|k,a|
197
+ if a.required?
198
+ #this may give an error, if the attribute has wrong type/layout...
199
+ @@el[k] << "Attr_#{k}"
200
+ testcode << " @@el[#{k.inspect}] << 'Attr_#{k}'"
201
+ else #only as template
202
+ testcode << " \#@@el[#{k.inspect}] << 'Attr_#{k}'"
203
+ end
204
+ }
205
+
206
+ if @@el.content?
207
+ @@el << 'content'
208
+ testcode<< " #fill content"
209
+ testcode<< " @@el << 'content'"
210
+ else
211
+ testcode<< " #element allows no content"
212
+ end
213
+
214
+ testcode<< " #Store log messages"
215
+ testcode<< " @@messages = @@logoutputter.flush"
216
+ #test log-content
217
+ @@messages = @@log.outputters.first.flush
218
+ testname = "test_element_#{cl.name.downcase.gsub(/::/, '_')}_log"
219
+
220
+ testcode<< <<code
221
+ end #self.startup()
222
+ =begin rdoc
223
+ Check messages from logger.
224
+ This may include warnings for wrong content format...
225
+
226
+ The following messages are expected:
227
+ #{@@messages.to_yaml}
228
+ =end
229
+ def #{testname}
230
+ assert_equal(
231
+ #{@@messages.inspect},
232
+ @@messages
233
+ )
234
+ end ##{testname}
235
+ code
236
+ %w{latex html context text wiki creole}.each{|target|
237
+ testname = "test_element_#{cl.name.downcase.gsub(/::/, '_')}_#{target}"
238
+ result = @@el.send("to_#{target}".to_sym, :log => @@log)
239
+
240
+ testcode<< <<code
241
+ =begin
242
+ Test #{cl.name}#to_#{target}.
243
+ =end
244
+ def #{testname}()
245
+ assert_equal(
246
+ code
247
+ #Problem:
248
+ if result.count("\n") < 2 #einzeilig
249
+ #\u (\url...) wird als Unicode-eingabe interpretiert. Desahlb muss \ maskiert werden.
250
+ testcode<< " #{result.inspect.gsub(/\\/, '\\\\')},"
251
+ else #mehrzeilig
252
+ =begin
253
+ Problem: %{inhalt} macht Probleme bei Strings mit { und }
254
+ <<<xx fügt leerzeichen ein, komma für nächste Parameter geht auch nicht.
255
+ =end
256
+ testcode<< " %Q{#{result.gsub(/\\/, '\\\\\\\\')}}," #mehrzeilig
257
+ #~ testcode<< "#~ <<result"
258
+ #~ testcode<< @@el.send("to_#{target}".to_sym).gsub(/\\/, '\\\\\\\\').gsub(/^/, '#~ ')
259
+ #~ testcode<< "#~ result"
260
+ end
261
+ testcode<< " @@el.to_#{target}( :log => @@log).encode('utf-8')"
262
+ testcode<< " )"
263
+ messages = @@logoutputter.flush
264
+ testcode<< <<code
265
+ =begin
266
+ Check messages from #{cl.name}#to_#{target}. Expected:
267
+ #{messages.to_yaml}
268
+ =end
269
+ assert_equal(
270
+ #{messages.inspect},
271
+ @@logoutputter.flush
272
+ )
273
+ code
274
+ testcode<< " end ##{testname}"
275
+ }
276
+ testcode<< "end ##{testclass}"
277
+
278
+ }
279
+
280
+ File.open("unittest/x_unittest_docgenerator_elements_#{Date.today}.rb", 'w:utf-8'){|f_test|
281
+ puts "Create #{f_test.path}"
282
+ f_test << TESTHEAD
283
+ f_test << testcode.join("\n")
284
+ }
285
+
286
+ #~ puts testcode.join("\n")
287
+ end #mk_element_test
288
+
289
+ =begin rdoc
290
+ Prepare a documentation, based on execution and meta-analyse.
291
+ =end
292
+ def mk_element_doc(pattern, filename = "manpage_element.rb")
293
+
294
+ rd_code= [<<xx
295
+ =begin rdoc
296
+ Generated manpages for elements.
297
+ =end
298
+
299
+ module Doc
300
+
301
+ module Docgenerator
302
+ module Characters; end
303
+ module Creole; end
304
+ module Elements; end
305
+ module Environments; end
306
+ module Letter; end
307
+ module Listings; end
308
+ module Lists; end
309
+ module Sectioning; end
310
+ module Tables; end
311
+ module Wikimedia; end
312
+ end
313
+
314
+ module Struktex; end
315
+
316
+ xx
317
+ ]
318
+ log = Log4r::Logger.new('log', Log4r::WARN) #avoid message
319
+ log.outputters = logoutputter = ArrayOutputter.new('xx')
320
+
321
+ Docgenerator::Element.each{|cl|
322
+ next unless cl.name =~ pattern
323
+
324
+ #exclude dummy element.
325
+ next if %w{Docgenerator::Sectioning::DummySectioning}.include?(cl.name.to_s)
326
+ p cl.name
327
+
328
+ el = cl.new(:log => log )
329
+ rd_code << <<code
330
+ =begin rdoc
331
+ =#{cl.name}
332
+ See also ::#{cl.name}
333
+
334
+ code
335
+ if ! el.attr.empty?
336
+ tab = element(:tabular, columns: 10).Cr
337
+ tab << row = element(:row ).cr
338
+ row << element(:th, {}, 'Name')
339
+ row << element(:th, {}, 'required?')
340
+ row << element(:th, {}, 'HTML')
341
+ row << element(:th, {}, 'LaTeX')
342
+ row << element(:th, {}, '~keyval')
343
+ row << element(:th, {}, 'ConTeXt')
344
+ row << element(:th, {}, 'Text')
345
+ row << element(:th, {}, 'Wiki')
346
+ row << element(:th, {}, 'Creole')
347
+ row << element(:th, {}, 'Values')
348
+
349
+ el.attr.each{|k,a|
350
+ ##fixme element(:radic) statt 'X'?
351
+ tab << row = element(:row).cr
352
+ row << element(:col, {}, k.inspect)
353
+ row << element(:col, {}, a.required? ? 'X' : '-' )
354
+ row << element(:col, {}, a.html? ? 'X' : '-' )
355
+ row << element(:col, {}, a.latex? ? 'X' : '-' )
356
+ row << element(:col, {}, a.texkeyval? ? 'X' : '-' )
357
+ row << element(:col, {}, a.context? ? 'X' : '-' )
358
+ row << element(:col, {}, a.text? ? 'X' : '-' )
359
+ row << element(:col, {}, a.wiki? ? 'X' : '-' )
360
+ row << element(:col, {}, a.creole? ? 'X' : '-' )
361
+ #~ rd_code << "===Attribute #{k.inspect}"
362
+ if a.required?
363
+ #this may give an error, if the attribute has wrong type/layout...
364
+ el[k] << "Value for #{k}"
365
+ #~ rd_code << "* required"
366
+ #~ else
367
+ #~ rd_code << "* optional"
368
+ end
369
+ #~ rd_code << "* used for:"
370
+ #~ rd_code << " * HTML" if a.html?()
371
+ #~ rd_code << " * LaTeX" if a.latex?()
372
+ #~ rd_code << " * LaTeX as key-val parameter" if a.texkeyval?()
373
+ #~ rd_code << " * ConTeXt" if a.context?()
374
+ #~ rd_code << " * text" if a.text?()
375
+ #~ rd_code << " * wiki (wikimedia)" if a.wiki?()
376
+ #~ rd_code << " * wiki (creole)" if a.creole?()
377
+
378
+ row << col = element(:col)
379
+ if a.allowed_values
380
+ col << ul = element(:ul)
381
+ #~ rd_code << "* Allowed values:"
382
+ a.allowed_values.each{|x|
383
+ ul << element(:li,{}, x.inspect)
384
+ #~ rd_code << " * #{x.inspect}"
385
+ }
386
+ end
387
+ }
388
+
389
+ rd_code<< "==Attributes"
390
+ rd_code<< tab.to_html(:log=> log)
391
+ end
392
+
393
+ #~ rd_code<< "==Content"
394
+ if el.content?
395
+ el << 'content'
396
+ rd_code<< "The element can contain content"
397
+ else
398
+ rd_code<< "The element allows no content"
399
+ end
400
+
401
+ rd_code<< "\n==Generate an object"
402
+ cmd = " test = #{el.class}.new( "
403
+ el.attr.each{|k,a|
404
+ cmd << "\n #{k.inspect} => #{a.content.inspect}," unless a.content.empty?
405
+ }
406
+ cmd.sub!(/,\Z/, "\n") #delete last , from attributes if available.
407
+ cmd << " )"
408
+ cmd << "\n test << #{el.content.inspect}" if el.content?
409
+
410
+ cmd << "\n\nAlternative generation\n"
411
+ el.element_ids.each{|id|
412
+ cmd << " test = element(#{id.inspect}#{ ' , { ...Attributes... }' unless el.attr.empty?})\n"
413
+ }
414
+ rd_code << cmd
415
+
416
+
417
+ rd_code<< "\n==Outputs"
418
+
419
+ %w{latex html context text wiki creole}.each{|target|
420
+
421
+ el2 = el.dup #later check with cr, cR... would modify the result
422
+
423
+ logoutputter.flush #clear messages
424
+ result = el.send("to_#{target}".to_sym, :log => log)
425
+ rd_code<< <<code
426
+ ===test.to_#{target}
427
+ #{result.gsub(/^/, " ")}
428
+ code
429
+ logoutputter.flush.each{|message|
430
+ case message
431
+ when /(Missing output routine for .*)\(/
432
+ rd_code << "* #{$1}"
433
+ when /No related document for tableofcontents/
434
+ when %r{ERROR log: :li/wiki: Unknown list type nil}
435
+ else
436
+ p "Uncatched message: #{message}"
437
+ end
438
+ }#logoutputter.flush
439
+
440
+ cr_first = true
441
+ #try different cr-commands
442
+ [ :cr, :cR, :Cr, :CR ].each{| cr |
443
+ el2.send(cr)
444
+ result2 = el2.send("to_#{target}".to_sym, :log => log)
445
+
446
+ if result != result2
447
+ if cr_first #first difference -> print start information
448
+ rd_code << <<code
449
+ ====:cr, :cR, :Cr, :CR
450
+ With Element#cr, Element#cR, Element#Cr, Element#CR you may influence
451
+ the code layout.
452
+ [[START]]/[[END]] are not part of the output, but needed to illustrate the
453
+ line breaks.
454
+
455
+ Default:
456
+ #{"[[START]]#{result}[[END]]".gsub(/^/, " ")}
457
+ code
458
+ cr_first = false
459
+ end #cr_first
460
+ rd_code << <<code
461
+ Result after Element##{cr}:
462
+ #{"[[START]]#{result2}[[END]]".gsub(/^/, " ")}
463
+ code
464
+ end
465
+ } #different cr-commands
466
+ } #targets
467
+ rd_code << <<code
468
+ =end
469
+ class #{cl.name}
470
+ end ##{cl.name}
471
+ code
472
+ } #Element.each
473
+
474
+ rd_code << "end"
475
+
476
+ puts rd_code.join("\n").encoding
477
+ puts rd_code.join("\n").valid_encoding?
478
+
479
+ File.open(filename, 'w:cp1252'){|f_test|
480
+ puts "Create #{f_test.path}"
481
+ f_test << rd_code.join("\n")
482
+ }
483
+
484
+ end #mk_element_doc(pattern)
485
+
486
+ #~ mk_character_test( )
487
+ #~ mk_character_test( "unittest_docgenerator_characters.rb" )
488
+
489
+ #~ mk_element_test(/./i)
490
+ #~ mk_element_test(/\A(?:.(?<!Characters))*\Z/i) #ohne characters
491
+ #~ mk_element_test(/include/i)
492
+ #~ mk_element_test(/img/i)
493
+ #~ mk_element_test(/Section/i)
494
+
495
+ #~ mk_element_doc(/img/i, 'manpage_extract.rb')
496
+ mk_element_doc(/sectioning/i, 'manpage_extract.rb')
497
+ #~ mk_element_doc(/elements/i, 'manpage_extract.rb')
498
+ #~ mk_element_doc(/tables/i, 'manpage_extract.rb')
499
+ #~ mk_element_doc(/envi/i, 'manpage_extract.rb')
500
+ #~ mk_element_doc(/list/i, 'manpage_extract.rb')
501
+ #~ mk_element_doc(/style|foot/i, 'manpage_extract.rb')
502
+ #~ mk_element_doc(/\A(?:.(?<!Characters))*\Z/i) #ohne characters
503
+ #~ mk_element_doc(/./i)
504
+
505
+ #~ puts_elements