docgenerator-creole 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +7 -0
  2. data/examples/creole_example.rb +76 -0
  3. data/examples/creole_example_footnote.rb +66 -0
  4. data/examples/creole_example_new_plugin.rb +51 -0
  5. data/examples/creole_example_placeholder.rb +77 -0
  6. data/examples/creole_example_rail.rb +155 -0
  7. data/examples/creole_example_rubycode.rb +144 -0
  8. data/examples/creole_example_struktex.rb +170 -0
  9. data/examples/creole_example_tabular.rb +96 -0
  10. data/examples/creole_example_tikz.rb +47 -0
  11. data/lib/docgenerator-creole.rb +5 -0
  12. data/lib/docgenerator/creole.rb +15 -0
  13. data/lib/docgenerator/creole/base.rb +170 -0
  14. data/lib/docgenerator/creole/characters.rb +131 -0
  15. data/lib/docgenerator/creole/creole.rb +708 -0
  16. data/lib/docgenerator/creole/document.rb +91 -0
  17. data/lib/docgenerator/creole/inclusion_and_plugins.rb +91 -0
  18. data/lib/docgenerator/creole/inclusions.rb +148 -0
  19. data/lib/docgenerator/creole/placeholder.rb +242 -0
  20. data/lib/docgenerator/creole/plugins.rb +230 -0
  21. data/lib/docgenerator/creole/plugins/index.rb +61 -0
  22. data/lib/docgenerator/creole/plugins/rail.rb +179 -0
  23. data/lib/docgenerator/creole/plugins/rubycode4creole.rb +136 -0
  24. data/lib/docgenerator/creole/plugins/struktex.rb +60 -0
  25. data/lib/docgenerator/creole/plugins/tikz.rb +93 -0
  26. data/lib/docgenerator/creole/plugins/todonotes.rb +77 -0
  27. data/lib/docgenerator/creole/tabular.rb +405 -0
  28. data/readme.rdoc +44 -0
  29. data/unittest/Red_Flower.jpg +0 -0
  30. data/unittest/expected_creole/test_creole.html +3 -0
  31. data/unittest/expected_creole/test_creole_characters_all.creole +28 -0
  32. data/unittest/expected_creole/test_creole_characters_all.html +18 -0
  33. data/unittest/expected_creole/test_creole_characters_all.latex +36 -0
  34. data/unittest/expected_creole/test_creole_characters_special.html +10 -0
  35. data/unittest/expected_creole/test_creole_characters_special.latex +18 -0
  36. data/unittest/expected_creole/test_creole_comment.context +11 -0
  37. data/unittest/expected_creole/test_creole_comment.creole +12 -0
  38. data/unittest/expected_creole/test_creole_comment.html +9 -0
  39. data/unittest/expected_creole/test_creole_comment.latex +11 -0
  40. data/unittest/expected_creole/test_creole_countdown.html +3 -0
  41. data/unittest/expected_creole/test_creole_countdown.latex +4 -0
  42. data/unittest/expected_creole/test_creole_creole1.0test.html +182 -0
  43. data/unittest/expected_creole/test_creole_creole1.0test.latex +253 -0
  44. data/unittest/expected_creole/test_creole_creole1.0test.text +160 -0
  45. data/unittest/expected_creole/test_creole_footnotes.html +9 -0
  46. data/unittest/expected_creole/test_creole_footnotes.latex +14 -0
  47. data/unittest/expected_creole/test_creole_footnotes_groupid.html +15 -0
  48. data/unittest/expected_creole/test_creole_footnotes_label.html +9 -0
  49. data/unittest/expected_creole/test_creole_headings.html +17 -0
  50. data/unittest/expected_creole/test_creole_headings.latex +19 -0
  51. data/unittest/expected_creole/test_creole_headings.text +48 -0
  52. data/unittest/expected_creole/test_creole_headings.wiki +37 -0
  53. data/unittest/expected_creole/test_creole_hr.html +7 -0
  54. data/unittest/expected_creole/test_creole_hr.latex +9 -0
  55. data/unittest/expected_creole/test_creole_hr.text +4 -0
  56. data/unittest/expected_creole/test_creole_ignore.html +3 -0
  57. data/unittest/expected_creole/test_creole_ignore.latex +4 -0
  58. data/unittest/expected_creole/test_creole_ignore.text +2 -0
  59. data/unittest/expected_creole/test_creole_inline.html +3 -0
  60. data/unittest/expected_creole/test_creole_inline.latex +4 -0
  61. data/unittest/expected_creole/test_creole_inline.text +2 -0
  62. data/unittest/expected_creole/test_creole_inline_apostroph.html +7 -0
  63. data/unittest/expected_creole/test_creole_inline_apostroph.latex +9 -0
  64. data/unittest/expected_creole/test_creole_inline_apostroph.text +5 -0
  65. data/unittest/expected_creole/test_creole_inline_ruby.html +12 -0
  66. data/unittest/expected_creole/test_creole_inline_ruby.latex +20 -0
  67. data/unittest/expected_creole/test_creole_inline_ruby_raw.html +6 -0
  68. data/unittest/expected_creole/test_creole_inline_ruby_raw.latex +8 -0
  69. data/unittest/expected_creole/test_creole_input.normsource +22 -0
  70. data/unittest/expected_creole/test_creole_input.normsource_1.8 +23 -0
  71. data/unittest/expected_creole/test_creole_input_file_simple.html +15 -0
  72. data/unittest/expected_creole/test_creole_input_file_simple_readlines.html +15 -0
  73. data/unittest/expected_creole/test_creole_label.html +12 -0
  74. data/unittest/expected_creole/test_creole_label.latex +15 -0
  75. data/unittest/expected_creole/test_creole_line_break.html +6 -0
  76. data/unittest/expected_creole/test_creole_line_break.latex +8 -0
  77. data/unittest/expected_creole/test_creole_links_explicit_internal.html +6 -0
  78. data/unittest/expected_creole/test_creole_links_explicit_internal.text +4 -0
  79. data/unittest/expected_creole/test_creole_links_explicit_with_em.html +3 -0
  80. data/unittest/expected_creole/test_creole_links_explicit_with_em.latex +4 -0
  81. data/unittest/expected_creole/test_creole_links_explicit_with_em.text +2 -0
  82. data/unittest/expected_creole/test_creole_links_external.html +6 -0
  83. data/unittest/expected_creole/test_creole_links_external.latex +8 -0
  84. data/unittest/expected_creole/test_creole_links_external.text +4 -0
  85. data/unittest/expected_creole/test_creole_links_external_implicit.html +9 -0
  86. data/unittest/expected_creole/test_creole_links_external_implicit.latex +12 -0
  87. data/unittest/expected_creole/test_creole_links_external_implicit.text +6 -0
  88. data/unittest/expected_creole/test_creole_links_file.html +6 -0
  89. data/unittest/expected_creole/test_creole_links_file.latex +8 -0
  90. data/unittest/expected_creole/test_creole_links_file.text +4 -0
  91. data/unittest/expected_creole/test_creole_links_implicit_end.creole +4 -0
  92. data/unittest/expected_creole/test_creole_links_implicit_end.html +3 -0
  93. data/unittest/expected_creole/test_creole_links_implicit_end.latex +4 -0
  94. data/unittest/expected_creole/test_creole_list_ol.html +12 -0
  95. data/unittest/expected_creole/test_creole_list_ol.latex +22 -0
  96. data/unittest/expected_creole/test_creole_list_ol_after_ul.html +12 -0
  97. data/unittest/expected_creole/test_creole_list_ol_after_ul.latex +20 -0
  98. data/unittest/expected_creole/test_creole_list_ol_after_ul.text +6 -0
  99. data/unittest/expected_creole/test_creole_list_ol_ul.html +15 -0
  100. data/unittest/expected_creole/test_creole_list_ol_ul.latex +26 -0
  101. data/unittest/expected_creole/test_creole_list_ul.html +22 -0
  102. data/unittest/expected_creole/test_creole_list_ul.latex +40 -0
  103. data/unittest/expected_creole/test_creole_list_ul.normsource +85 -0
  104. data/unittest/expected_creole/test_creole_list_ul.normsource_1.8 +83 -0
  105. data/unittest/expected_creole/test_creole_list_ul_too_much.html +24 -0
  106. data/unittest/expected_creole/test_creole_list_ul_too_much.latex +44 -0
  107. data/unittest/expected_creole/test_creole_list_ulul_without_ul.html +6 -0
  108. data/unittest/expected_creole/test_creole_list_ulul_without_ul.latex +12 -0
  109. data/unittest/expected_creole/test_creole_mix_titles_list.html +10 -0
  110. data/unittest/expected_creole/test_creole_mix_titles_list.latex +18 -0
  111. data/unittest/expected_creole/test_creole_mix_titles_list.text +12 -0
  112. data/unittest/expected_creole/test_creole_newline.html +9 -0
  113. data/unittest/expected_creole/test_creole_newline.latex +11 -0
  114. data/unittest/expected_creole/test_creole_newline.text +7 -0
  115. data/unittest/expected_creole/test_creole_paragraphs.html +6 -0
  116. data/unittest/expected_creole/test_creole_paragraphs.latex +8 -0
  117. data/unittest/expected_creole/test_creole_paragraphs.normsource +26 -0
  118. data/unittest/expected_creole/test_creole_paragraphs.normsource_1.8 +27 -0
  119. data/unittest/expected_creole/test_creole_paragraphs.text +4 -0
  120. data/unittest/expected_creole/test_creole_paragraphs.wiki +4 -0
  121. data/unittest/expected_creole/test_creole_paragraphs_wrap.html +5 -0
  122. data/unittest/expected_creole/test_creole_paragraphs_wrap.latex +6 -0
  123. data/unittest/expected_creole/test_creole_paragraphs_wrap.text +4 -0
  124. data/unittest/expected_creole/test_creole_paragraphs_wrap.wiki +4 -0
  125. data/unittest/expected_creole/test_creole_paragraphs_wrap0.html +9 -0
  126. data/unittest/expected_creole/test_creole_paragraphs_wrap0.latex +11 -0
  127. data/unittest/expected_creole/test_creole_paragraphs_wrap0.text +7 -0
  128. data/unittest/expected_creole/test_creole_paragraphs_wrap0.wiki +7 -0
  129. data/unittest/expected_creole/test_creole_paragraphs_wrap60.html +5 -0
  130. data/unittest/expected_creole/test_creole_paragraphs_wrap60.latex +6 -0
  131. data/unittest/expected_creole/test_creole_paragraphs_wrap60.text +4 -0
  132. data/unittest/expected_creole/test_creole_paragraphs_wrap60.wiki +4 -0
  133. data/unittest/expected_creole/test_creole_paragraphs_wrap_with_linebreaks.html +5 -0
  134. data/unittest/expected_creole/test_creole_paragraphs_wrap_with_linebreaks.latex +6 -0
  135. data/unittest/expected_creole/test_creole_paragraphs_wrap_with_linebreaks.text +4 -0
  136. data/unittest/expected_creole/test_creole_paragraphs_wrap_with_linebreaks.wiki +4 -0
  137. data/unittest/expected_creole/test_creole_picture_link.html +6 -0
  138. data/unittest/expected_creole/test_creole_pictures.html +10 -0
  139. data/unittest/expected_creole/test_creole_pictures.latex +13 -0
  140. data/unittest/expected_creole/test_creole_pictures_css.html +6 -0
  141. data/unittest/expected_creole/test_creole_pictures_css.latex +8 -0
  142. data/unittest/expected_creole/test_creole_pictures_imgclass.html +6 -0
  143. data/unittest/expected_creole/test_creole_pictures_imgclass.latex +8 -0
  144. data/unittest/expected_creole/test_creole_pictures_longdesc.html +3 -0
  145. data/unittest/expected_creole/test_creole_pictures_width.html +3 -0
  146. data/unittest/expected_creole/test_creole_pictures_width.latex +4 -0
  147. data/unittest/expected_creole/test_creole_placeholders_html.html +7 -0
  148. data/unittest/expected_creole/test_creole_placeholders_html.latex +8 -0
  149. data/unittest/expected_creole/test_creole_placeholders_html.text +4 -0
  150. data/unittest/expected_creole/test_creole_placeholders_latex.html +6 -0
  151. data/unittest/expected_creole/test_creole_placeholders_latex.latex +9 -0
  152. data/unittest/expected_creole/test_creole_placeholders_latex.text +4 -0
  153. data/unittest/expected_creole/test_creole_short_html.html +3 -0
  154. data/unittest/expected_creole/test_creole_short_html.latex +4 -0
  155. data/unittest/expected_creole/test_creole_short_html.text +2 -0
  156. data/unittest/expected_creole/test_creole_shy.creole +6 -0
  157. data/unittest/expected_creole/test_creole_shy.html +6 -0
  158. data/unittest/expected_creole/test_creole_shy.latex +8 -0
  159. data/unittest/expected_creole/test_creole_shy.text +4 -0
  160. data/unittest/expected_creole/test_creole_tabular.creole +22 -0
  161. data/unittest/expected_creole/test_creole_tabular.html +20 -0
  162. data/unittest/expected_creole/test_creole_tabular.latex +22 -0
  163. data/unittest/expected_creole/test_creole_tabular_creole.creole +21 -0
  164. data/unittest/expected_creole/test_creole_tabular_creole.html +20 -0
  165. data/unittest/expected_creole/test_creole_tabular_creole.latex +21 -0
  166. data/unittest/expected_creole/test_creole_tabular_css.creole +24 -0
  167. data/unittest/expected_creole/test_creole_tabular_css.html +20 -0
  168. data/unittest/expected_creole/test_creole_tabular_css.latex +22 -0
  169. data/unittest/expected_creole/test_creole_tabular_multicols.creole +16 -0
  170. data/unittest/expected_creole/test_creole_tabular_multicols.html +14 -0
  171. data/unittest/expected_creole/test_creole_tabular_multicols.latex +16 -0
  172. data/unittest/expected_creole/test_creole_tabular_row_parameters.latex +22 -0
  173. data/unittest/expected_creole/test_creole_tabular_with_cell_option.creole +21 -0
  174. data/unittest/expected_creole/test_creole_tabular_with_cell_option.html +20 -0
  175. data/unittest/expected_creole/test_creole_toc.html +13 -0
  176. data/unittest/expected_creole/test_creole_toc.latex +22 -0
  177. data/unittest/expected_creole/test_creole_toc.text +4 -0
  178. data/unittest/expected_creole/test_creole_toc_level.html +7 -0
  179. data/unittest/expected_creole/test_creole_toc_level.latex +10 -0
  180. data/unittest/expected_creole/test_creole_toc_level.text +3 -0
  181. data/unittest/expected_creole/test_creole_toc_level_text.html +8 -0
  182. data/unittest/expected_creole/test_creole_toc_level_text.latex +9 -0
  183. data/unittest/expected_creole/test_creole_toc_text.html +5 -0
  184. data/unittest/expected_creole/test_creole_toc_text.latex +5 -0
  185. data/unittest/expected_creole/test_creole_ul_multiple_line.html +7 -0
  186. data/unittest/expected_creole/test_creole_ul_multiple_line.latex +14 -0
  187. data/unittest/expected_creole/test_creole_ul_with_blank.html +11 -0
  188. data/unittest/expected_creole/test_creole_ul_with_blank.latex +20 -0
  189. data/unittest/expected_creole/test_creole_ul_with_bold.creole +0 -0
  190. data/unittest/expected_creole/test_creole_ul_with_bold.html +11 -0
  191. data/unittest/expected_creole/test_creole_ul_with_bold.latex +18 -0
  192. data/unittest/expected_creole/test_creole_ul_with_bold.text +7 -0
  193. data/unittest/expected_creole/test_creole_verbatim.html +25 -0
  194. data/unittest/expected_creole/test_creole_verbatim.latex +33 -0
  195. data/unittest/expected_creole/test_creole_verbatim.text +17 -0
  196. data/unittest/expected_creole/test_creole_verbatim_inline.html +6 -0
  197. data/unittest/expected_creole/test_creole_verbatim_inline.latex +8 -0
  198. data/unittest/expected_creole/test_creole_verbatim_inline_at_start.html +6 -0
  199. data/unittest/expected_creole/test_creole_verbatim_inline_at_start.latex +8 -0
  200. data/unittest/expected_creole_rail/test_rail_creole_object.tex +33 -0
  201. data/unittest/expected_creole_rail/test_rail_creole_placeholder.tex +40 -0
  202. data/unittest/expected_rubycode4doc/creole_complete.html +26 -0
  203. data/unittest/expected_rubycode4doc/creole_complete.tex +40 -0
  204. data/unittest/expected_rubycode4doc/creole_in_tab.html +4 -0
  205. data/unittest/expected_rubycode4doc/creole_in_tab.tex +6 -0
  206. data/unittest/expected_rubycode4doc/creole_inline_ruby.html +7 -0
  207. data/unittest/expected_rubycode4doc/creole_output.html +2 -0
  208. data/unittest/expected_rubycode4doc/creole_output.tex +4 -0
  209. data/unittest/expected_rubycode4doc/creole_rubycode.html +1 -0
  210. data/unittest/expected_rubycode4doc/creole_rubycode.tex +3 -0
  211. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated.html +1 -0
  212. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated.tex +3 -0
  213. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated_listings.html +3 -0
  214. data/unittest/expected_rubycode4doc/creole_rubycode_evaluated_listings.tex +5 -0
  215. data/unittest/unittest_creole.rb +1379 -0
  216. data/unittest/unittest_creole_placeholders.rb +161 -0
  217. data/unittest/unittest_creole_plugin_rail.rb +148 -0
  218. data/unittest/unittest_creole_plugin_rubycode4doc.rb +123 -0
  219. data/unittest/unittest_creole_plugin_struktex.rb +26 -0
  220. data/unittest/unittest_creole_tabular.rb +212 -0
  221. metadata +529 -0
@@ -0,0 +1,136 @@
1
+ =begin rdoc
2
+ Little helper to make documention on ruby scripts,
3
+ Ruby fragments are defined in the creole-source,
4
+ You can get the code and the results.
5
+
6
+ The source code is enriched with the results and can be shown.
7
+ =end
8
+
9
+ #Only for quick tests
10
+ $:.unshift("../../") if $0 == __FILE__
11
+
12
+ #~ fixme: use listings instead verbatim
13
+ #~ check usage??
14
+
15
+ require 'docgenerator/creole'
16
+ require 'docgenerator/packages/rubycode4doc'
17
+
18
+ module Docgenerator
19
+ module Creole
20
+
21
+ =begin rdoc
22
+ Write rubycode inside creole-text
23
+ =end
24
+ module Rubycode
25
+
26
+ =begin rdoc
27
+ Print ruby source code as is
28
+ =end
29
+ class Code < Placeholder
30
+ set_placeholder_key 'rubycode'
31
+ #Return content in a verbatim environment
32
+ def to_doc( target, options = {})
33
+ codetest = Docgenerator::Rubycode::CodeTest.new(nil, @source.join )
34
+ #~ element(:verbatim,{},@source ).cr.to_doc( target, options )
35
+ element(:verbatim, {
36
+ :style => 'rubycode',
37
+ }, codetest.sourcecode ).cr.to_doc( target, options )
38
+ end
39
+ end #Code
40
+
41
+ #
42
+ #Print ruby source code and put the result of each line as a comment.
43
+ #
44
+ #Example:
45
+ # 1 + 1
46
+ #becomes
47
+ # 1 + 1 #2
48
+ class Code_evaluated < Placeholder
49
+ set_placeholder_key 'rubycode_evaluated'
50
+ #Return content in a verbatim environment
51
+ def to_doc( target, options = {})
52
+ codetest = Docgenerator::Rubycode::CodeTest.new(nil, @source.join )
53
+ #~ element(:verbatim,{},@source ).cr.to_doc( target, options )
54
+ element(:verbatim, {
55
+ :style => 'rubycode_evaluated',
56
+ }, codetest.code_evaluation ).cr.to_doc( target, options )
57
+ end
58
+ end #Code_evaluated
59
+
60
+ #
61
+ #Print ruby source code and put the result of each line as a comment.
62
+ #
63
+ #Same as Code_evaluated, but export is done for in TeX-Package listings.
64
+ class Code_evaluated_listings < Placeholder
65
+ set_placeholder_key 'rubycode_evaluated_listings'
66
+ #Return content in a verbatim environment
67
+ def to_doc( target, options = {})
68
+ codetest = Docgenerator::Rubycode::CodeTest.new(nil, @source.join )
69
+ #~ element(:verbatim, {
70
+ #~ :style => 'rubycode_evaluated',
71
+ #~ }, codetest.code_evaluation ).cr.to_doc( target, options )
72
+ codetest.code_evaluation_lstlisting.to_doc( target, options )
73
+
74
+ end
75
+ end #Code_evaluated_listing
76
+
77
+ #
78
+ #Take only the output of the rubycode
79
+ #
80
+ class Code_output < Placeholder
81
+ set_placeholder_key 'rubycode_output'
82
+ #Return content in a verbatim environment
83
+ def to_doc( target, options = {})
84
+ codetest = Docgenerator::Rubycode::CodeTest.new(nil, @source.join )
85
+ #~ element(:verbatim,{},@source ).cr.to_doc( target, options )
86
+ element(:verbatim, {
87
+ :style => 'rubycode_output',
88
+ }, codetest.output ).cr.to_doc( target, options )
89
+ end
90
+ end #Code_output
91
+
92
+ #
93
+ #Build a table.
94
+ #Each row corresponds with a source code line.
95
+ #You get source code, result and output of the code line.
96
+ #
97
+ #
98
+ class Code_in_tab < Placeholder
99
+ set_placeholder_key 'rubycode_in_tab'
100
+ #Return content in a verbatim environment
101
+ def to_doc( target, options = {})
102
+ codetest = Docgenerator::Rubycode::CodeTest.new(nil, @source.join )
103
+ codetest.code_in_tab.to_doc( target, options )
104
+ end
105
+ end #Code_in_tab
106
+ end #module Rubycode
107
+ end #module Creole
108
+ end #module Docgenerator
109
+
110
+ if $0 == __FILE__
111
+ wiki = Docgenerator::Creole::Creole.new()
112
+ wiki << <<wiki
113
+ rubycode
114
+ <<<rubycode
115
+ 1 + 1
116
+ >>>
117
+ ----
118
+ rubycode_output
119
+ <<<rubycode_output
120
+ puts 1 + 1
121
+ >>>
122
+ ----
123
+ rubycode_evaluated
124
+ <<<rubycode_evaluated
125
+ 1 + 1
126
+ >>>
127
+ ----
128
+ rubycode_in_tab
129
+ <<<rubycode_in_tab
130
+ 1 + 1
131
+ >>>
132
+ wiki
133
+ puts wiki.to_html
134
+ end
135
+
136
+ __END__
@@ -0,0 +1,60 @@
1
+ #encoding: utf-8
2
+ =begin rdoc
3
+ Add support of Struktex::Structogramm for Creole.
4
+ =end
5
+ #~ require 'docgenerator/creole'
6
+ require 'docgenerator/packages/struktex.rb'
7
+
8
+ module Docgenerator
9
+ module Creole
10
+
11
+ =begin rdoc
12
+ Define Creole placeholder.
13
+
14
+ The placeholder insertion must contain three parameters:
15
+
16
+ >>>structogramm{Declarations/Interfaces;120;25}
17
+ Statement
18
+ -> field1 description
19
+ <- field2 description
20
+ <-> field3 description
21
+ <<<
22
+ Details see Docgenerator::Structogramm
23
+ =end
24
+ class Creole_structogramm < Placeholder
25
+ set_placeholder_key('structogramm')
26
+
27
+ #~ fixme
28
+ #~ parameters optional als placeholder,
29
+ #~ hier aber benötigt.
30
+ #~ Defaults??
31
+
32
+ def initialize( wiki, parameters = nil)
33
+ super
34
+ #~ @wiki = wiki
35
+ #~ @log = @wiki.log
36
+ par = parameters ? parameters.split(/;/) : []
37
+ case par.size
38
+ when 0
39
+ raise ParameterError, "Creole_structogramm: Missing parameters"
40
+ when 3
41
+ title = par[0]
42
+ x = par[1]
43
+ y = par[2]
44
+ @source = ''
45
+ @structogramm = Packages::Struktex::Structogramm.new( title, x, y, @source )
46
+ else
47
+ raise ParameterError, "Creole_structogramm: Wrong number of parameters: #{parameters.inspect}"
48
+ end
49
+ end
50
+ #Instance of class Structogramm.
51
+ attr_reader :structogramm
52
+
53
+ #Return content only for latex
54
+ def to_doc( target, options = {})
55
+ target == :latex ? @structogramm.to_doc( target, options ) : ''
56
+ end
57
+ end #Creole_latex
58
+
59
+ end #module Creole
60
+ end #module Docgenerator
@@ -0,0 +1,93 @@
1
+ #encoding: utf-8
2
+ =begin rdoc
3
+ Example of usage:
4
+
5
+ <<<tikz_img|template_module.png|remember picture|width=\textwidth
6
+ \node[red,ultra thick,rounded corners,draw] at (.95,.75) (source) {1};
7
+ >>>
8
+ * (1) Datenquelle muss definiert werden<<tikz|\draw[] (0,0) -- (source);>>
9
+
10
+ See also creole_example_tikz.rb
11
+ =end
12
+ #~ require 'docgenerator/packages/todonotes.rb'
13
+
14
+ #
15
+ module Docgenerator
16
+ module Creole
17
+ module Plugins
18
+ =begin rdoc
19
+ Define a TikZ inclusion.
20
+
21
+ Usage:
22
+
23
+ <<tikz|\draw[] (0,0) -- (1,1);>>
24
+
25
+ =end
26
+ class Creole_tikz < Creole_inclusion_and_plugin
27
+ Collection['tikz'] = self
28
+ def to_doc(target, options = {})
29
+ target == :latex ?
30
+ '\tikz[overlay,remember picture]{%s}' % @description
31
+ : ''
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ module Placeholders
38
+ =begin rdoc
39
+ Include a graphic inside a tikz-environment
40
+
41
+ Usage:
42
+ <<<tikz_img|template_module.png|width=\textwidth
43
+ \node[red,ultra thick,rounded corners,draw] at (.95,.75) {1};
44
+ >>>
45
+
46
+ * parameters are
47
+ # the picture name
48
+ # alt=: Define alternative text (only HTML)
49
+ # remember picture: tikzpicture-option. Labels are added 'global'.
50
+
51
+ * The other options are forwarded to Inclusions::Creole_inclusion_img
52
+ * Commands in the code are relative to image,
53
+ (0,0) is at the lower left of the picture and (1,1) is at the upper right.
54
+ =end
55
+ class Tikz_img < Placeholder
56
+ set_placeholder_key 'tikz_img'
57
+ #Return content only for html
58
+ def to_doc( target, options = {})
59
+ parameters = @parameters.split('|')
60
+ picname = parameters.shift
61
+ alttext = nil
62
+ tikz_options = []
63
+ parameters.each{|par|
64
+ case par
65
+ when /alt\s*=\s*(.*)/
66
+ alttext = $1
67
+ parameters.delete(par)
68
+ when 'remember picture', '>=.*'
69
+ tikz_options << par
70
+ parameters.delete(par)
71
+ end
72
+ }
73
+ img = Inclusions::Creole_inclusion_img.new( picname, alttext, parameters, @wiki )
74
+ @source ||=[]
75
+ case target
76
+ when :latex
77
+ <<'tex' % [tikz_options.join(','), img.to_doc( target, options ), @source.join.strip]
78
+ \begin{tikzpicture}[%s]
79
+ \node[anchor=south west,inner sep=0pt] (image) at (0,0)
80
+ {%s};
81
+ \begin{scope}[x={(image.south east)},y={(image.north west)}]
82
+ %s
83
+ \end{scope}
84
+ \end{tikzpicture}
85
+ tex
86
+ else #return only the graphic
87
+ img.to_doc( target, options )
88
+ end
89
+ end #Tikz_img#to_doc
90
+ end #Tikz_img
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,77 @@
1
+ require 'docgenerator/packages/todonotes.rb'
2
+
3
+ module Docgenerator
4
+ module Creole
5
+
6
+ =begin rdoc
7
+ Classes to provide support for the todonotes-package.
8
+
9
+ * http://ctan.org/tex-archive/macros/latex/contrib/todonotes/
10
+ =end
11
+ module Todo
12
+
13
+ class Creole_todolist < Creole_inclusion_and_plugin
14
+ set_plugin_key('listoftodos') #use <<todo|..>>
15
+ def to_doc(target, options = {})
16
+ element(:listoftodos, options).to_doc(target, options)
17
+ end
18
+ end
19
+ =begin rdoc
20
+ Define a plugin for the todonotes-package.
21
+ =end
22
+ class Creole_todo < Creole_inclusion_and_plugin
23
+
24
+ set_plugin_key('todo') #use <<todo|..>>
25
+
26
+ #define default options for todonotes. may be redefined for children of this class.
27
+ def default_options; {}; end
28
+
29
+ =begin rdoc
30
+ Usage:
31
+ <<todo|what to do|color=red>>
32
+ =end
33
+ def initialize( inclusionname, description, options, wiki )
34
+ #~ @inclusionname = inclusionname #fix 'todo'
35
+ @description = description
36
+ @options = default_options.dup
37
+ options.each{|opt|
38
+ case opt
39
+ when /color\s*=\s*/
40
+ @options[:color] = $~.post_match
41
+ when /inline/
42
+ @options[:inline] = true
43
+ else
44
+ wiki.log.warn("Todo #{@description} with undefined option #{opt}")
45
+ end
46
+ }
47
+ @wiki = wiki
48
+
49
+ raise "Inclusion received no wiki but #{wiki.inspect}" unless wiki.is_a?(Creole)
50
+ end
51
+
52
+ def to_doc(target, options = {})
53
+ element(:todo, @options, @description).to_doc(target, options)
54
+ end
55
+ end #Creole_todo
56
+
57
+ =begin rdoc
58
+ A variant of Creole_todo with green color.
59
+ =end
60
+ class Creole_todo_green < Creole_todo
61
+ set_plugin_key('todo_green') #use <<todo_green|..>>
62
+ #define default options for todonotes. may be redefined for children of this class.
63
+ def default_options; {:color => 'green'}; end
64
+ end
65
+
66
+ =begin rdoc
67
+ A variant of Creole_todo with inline-layout.
68
+ =end
69
+ class Creole_todo_inline < Creole_todo
70
+ set_plugin_key('todo_inline') #use <<todo_inline|..>>
71
+ #define default options for todonotes. may be redefined for children of this class.
72
+ def default_options; {:inline => true}; end
73
+ end
74
+
75
+ end #module Todo
76
+ end #module Creole
77
+ end #module Docgenerator
@@ -0,0 +1,405 @@
1
+ #encoding: UTF-8
2
+
3
+ #
4
+ module Docgenerator
5
+ module Creole
6
+ =begin
7
+ "Original" creole tab.
8
+
9
+ Defined as a collector, so we can collect the content first and
10
+ build the tabular later.
11
+
12
+ Details see http://www.wikicreole.org/wiki/Tables
13
+
14
+ Usage:
15
+ Tables are done like this:
16
+ |=header col1|=header col2|
17
+ |col1|col2|
18
+ |you |can |
19
+ |also |align\\ it. |
20
+
21
+ =end
22
+ class Creole_tab < Placeholder
23
+ set_placeholder_key 'creole_tabular' #original creole-tab definition
24
+
25
+ #Extend the class by a little structure
26
+ Cell = Struct.new('Cell', :content, :type )
27
+
28
+ #Finish the tabular.
29
+ #Each cell is added left justified.
30
+ def close(options)
31
+ #~ @log.error("Standard creole tabulars not supported yet" )
32
+
33
+ step = 0 #start
34
+ head = []
35
+ content = []
36
+ @source.each{|line|
37
+ content << []
38
+ #delete trailing empty cells
39
+ line.chomp.gsub(/\|\s*$/,'').split(/\|/)[1..-1].each{|cell|
40
+ case cell
41
+ when /^=/
42
+ content.last << Cell.new(@wiki.inline($~.post_match.strip, options),:th)
43
+ else
44
+ content.last << Cell.new(@wiki.inline(cell.strip, options), :td)
45
+ end
46
+ }
47
+ }
48
+
49
+ max_size = 0
50
+ content.each{|line|
51
+ max_size = [max_size, line.size].max
52
+ }
53
+
54
+ @tab = element(:tabular, {#:style => tab_css,
55
+ :columns => max_size,
56
+ :columndescription => 'l' * max_size,
57
+ }).cR
58
+ content.each{|line|
59
+ @tab << row = element(:row).cr
60
+ line.each{|cell|
61
+ options = {}
62
+ options[:align] = 'right' if cell.content.join('xxx') =~ /\A\s*-?[\d,\.]+\s*\Z/
63
+ row << element(cell.type,options, cell.content).cr
64
+ }
65
+ }
66
+ end
67
+ def to_doc( target, options = {})
68
+ self.close(options) unless @tab
69
+ @tab.to_doc( target, options )
70
+ end
71
+ end #Creole_tab
72
+
73
+ =begin rdoc
74
+ Create tabulars analog to Wikimedia.
75
+
76
+ Usage:
77
+ before
78
+ <<<tabular
79
+ |!columns=3
80
+ |!columndescription=ccc
81
+ |!border=1px
82
+ |!css= color: red
83
+ |=1
84
+ |=2
85
+ |=3
86
+ |-
87
+ |eins
88
+ |zwei
89
+ |drei
90
+ |-
91
+ |one
92
+ |two
93
+ |three
94
+ >>>
95
+ after
96
+
97
+ You can add additional settings to cells:
98
+ <<<tabular
99
+ |!columns=3
100
+ |eins||css=color: red
101
+ |css = zwei
102
+ |||class=empty
103
+ >>>
104
+ =end
105
+ class Creole_tabular < Placeholder
106
+ set_placeholder_key 'tabular'
107
+
108
+ #Define a container for cells
109
+ class Row
110
+ #Flag for hline
111
+ attr_accessor :hline
112
+ #Flag for toprule
113
+ attr_accessor :toprule
114
+ #Flag for midrule
115
+ attr_accessor :midrule
116
+ #Add a cell to a row
117
+ def << (cell)
118
+ @cells = [] unless @cells
119
+ @cells << cell
120
+ end
121
+ def each
122
+ @cells.each{|cell| yield cell } if @cells
123
+ end
124
+ #Return number of cells
125
+ def size
126
+ if @cells
127
+ @cells.size
128
+ else
129
+ #fixme error?
130
+ 0
131
+ end
132
+ end
133
+ end
134
+ #Extend the class by a little structure
135
+ class Cell
136
+ =begin rdoc
137
+ The content of a cell is separated from settings by two ||
138
+
139
+ If you have an empty cell with additional setting, you must write three |
140
+
141
+ Supported additional settings:
142
+ * css= define css-style options
143
+ * class= define HTML-class
144
+ * title= define a title (results in popup during mouse-over)
145
+ =end
146
+ def initialize( content, type, wiki, local_options )
147
+ @content, options = content.split(/\|\|/,2)
148
+ @content = '' unless @content #just in case of empty content
149
+ @options = {}
150
+ options.split(/\|/).each{|option|
151
+ case option
152
+ when /class\s*=\s*/
153
+ @options[:class] = $~.post_match
154
+ when /css\s*=\s*/
155
+ @options[:style] = $~.post_match
156
+ when /title\s*=\s*/
157
+ @options[:title] = $~.post_match
158
+ when /pos\s*=\s*/ #only for multicol
159
+ @options[:pos] = $~.post_match
160
+ when /columns\s*=\s*/
161
+ wiki.log.debug("Creole_tabular::Cell #{type} converted to multicol")
162
+ type = :multicolumn #loose th/td-information -- fixme
163
+ @options[:colspan] = $~.post_match.to_i
164
+ when '' #ignore them
165
+ else
166
+ wiki.log.warn("Creole_tabular::Cell: Undefined option #{option.inspect}")
167
+ end
168
+ } if options
169
+ @type = type #:td or :th
170
+ @wiki = wiki
171
+ @local_options = local_options
172
+ end
173
+ #Return the content as a element.
174
+ def cell_element()
175
+ element(@type,@options, @wiki.inline(@content, @local_options)).cr
176
+ end
177
+ end #class Cell
178
+
179
+ #Build the tabular.
180
+ def close()
181
+ #~ fixme:
182
+ #~ *CSS-format
183
+ #~ *generelle def
184
+
185
+ step = 0 #start
186
+ head = []
187
+ content = [Row.new]
188
+
189
+ options = { :log => @log }
190
+ local_options = {
191
+ :log => @log,
192
+ :inclusions => @wiki.inclusions,
193
+ :plugins => @wiki.plugins.dup
194
+ }
195
+ #No footnotes inside tabulars
196
+ local_options[:plugins].delete('footnote')
197
+ local_options[:plugins].delete('footnotes')
198
+
199
+ tab_css = CSS.new( :log => @log )
200
+ @source.each{|cell|
201
+ case cell
202
+ when /^\|!/ #generell cell definition
203
+ case $~.post_match().strip
204
+ when /columns\s*=\s*(.*)/
205
+ options[:columns] = $1.to_i
206
+ when /border\s*=\s*(.*)/
207
+ options[:border] = $1
208
+ when /columndescription\s*=\s*(.*)/
209
+ options[:columndescription] = $1
210
+ when /css\s*=\s*(.*)\s*:\s*(.*)/
211
+ tab_css[$1] = $2
212
+ when '' #
213
+ else
214
+ @log.warn("#{self}: Unknown tabular option #{$1}") if @log.warn?
215
+ end
216
+ when /^\|-(.*)/ #new line
217
+ if $1 #there are options for the row
218
+ $1.split(/\|/).each{|option|
219
+ case option
220
+ when /hline/; content.last.hline = true
221
+ when /toprule/; content.last.toprule = true
222
+ when /midrule/; content.last.midrule = true
223
+ when /\A\s*\Z/, nil
224
+ else
225
+ @log.warn("#{self}: Unknown row option #{option.inspect}") if @log.warn?
226
+ end
227
+ }
228
+ end
229
+ content << Row.new #Start new row
230
+ when /^\|=/ #header cell
231
+ #~ content.last << Cell.new(@wiki.inline($~.post_match.strip, local_options), :th)
232
+ content.last << Cell.new($~.post_match.strip, :th, @wiki, local_options)
233
+ when /^\|/ #content of a cell
234
+ #~ content.last << Cell.new(@wiki.inline($~.post_match.strip, local_options), :td)
235
+ content.last << Cell.new($~.post_match.strip, :td, @wiki, local_options)
236
+ else #error!
237
+ raise "cell/log-warning in #{cell.inspect}"
238
+ end
239
+ }
240
+
241
+ max_size = 0
242
+ content.each{|line|
243
+ max_size = [max_size, line.size].max
244
+ }
245
+
246
+ if options[:columns] and options[:columns] < max_size
247
+ @log.warn("Creole-tabular: Defined size #{options[:columns]} < no of columns (#{max_size})") if @log.warn?
248
+ end
249
+
250
+ if self.is_a?(Docgenerator::Creole::Creole_longtable)
251
+ @tab = element(:longtable, { :style => tab_css,
252
+ }.merge(options) ).cR
253
+ #~ elsif self.is_a?(Docgenerator::Creole::Creole_supertabular) #Not supported
254
+ #~ @tab = element(:supertabular, { :style => tab_css,
255
+ #~ }.merge(options) ).cR
256
+ elsif self.is_a?(Docgenerator::Creole::Creole_tabular)
257
+ @tab = element(:tabular, { :style => tab_css,
258
+ }.merge(options) ).cR
259
+ else
260
+ raise ArgumentError, "Unsupported tabular-class #{self.class}"
261
+ end
262
+
263
+ content.each{|line|
264
+ @tab << row = element(:row).cr
265
+ row.hline if line.hline
266
+ row.toprule if line.toprule
267
+ row.midrule if line.midrule
268
+ line.each{|cell|
269
+ row << cell.cell_element.cr
270
+ }
271
+ }
272
+ end
273
+ def to_doc( target, options = {})
274
+ @tab.to_doc( target, options )
275
+ end
276
+ end #Creole_tabular
277
+
278
+ class Creole_longtable < Creole_tabular
279
+ set_placeholder_key 'longtable'
280
+ end
281
+
282
+ #~ class Creole_supertabular < Creole_tabular ##Not supported
283
+ #~ set_placeholder_key 'supertabular'
284
+ #~ end
285
+ =begin rdoc
286
+ This class needs the CSV-package (the user is responsible to load it).
287
+
288
+ The LaTeX document needs the booktabs-package
289
+
290
+ Options:
291
+ * headers=false: Firest line contains headers (default: true)
292
+ * format or columndescription: LaTeX header description
293
+
294
+ Fixmes:
295
+ * More parameters:
296
+ ** toprule, hline,
297
+ ** Other table (supertabular...)
298
+ * Bug: CSV without header returns Array of array
299
+
300
+ =end
301
+ class Creole_tabular_csv < Placeholder
302
+ set_placeholder_key 'tabular_csv'
303
+ def to_doc( target, options = {})
304
+ if ! defined? CSV
305
+ @log.fatal("tabular_csv needs CSV-package")
306
+ raise "tabular_csv needs CSV-package"
307
+ end
308
+ @log.fatal("tabular_csv needs parameters (format, col_sep)") unless @parameters.respond_to? :split
309
+ columndescription = nil
310
+ headers = true #first CSV-line contains
311
+ colsep = ';'
312
+ @parameters.split(/[|;]/).each{|parameter|
313
+ case parameter
314
+ when /headers=false/; headers = false
315
+ when /(format|columndescription)=(.*)/; columndescription = $2
316
+ #Some separator get a name. This is made especially, of the separator is also used as parameter separator.
317
+ when /(col_sep)=(.*)/; colsep = {'semicolon' => ';', 'tab' => "\t", 'bar' => '|'}[$2] || $2
318
+ @log.warn("tabular_csv with undefined separator (use semicolon, tab or bar)" % parameter) unless colsep
319
+ else
320
+ @log.warn("tabular_csv with unknown option %s" % parameter)
321
+ end
322
+ }
323
+
324
+ csv = CSV.parse(@source.join, :col_sep => colsep, :headers => true)
325
+ if ! columndescription
326
+ columndescription = 'c' * csv.headers.size
327
+ @log.warn("tabular_csv without LaTeX columndescription. Use %s" % columndescription)
328
+ end
329
+ tab = element(:tabular, { :columns => csv.headers.size, :columndescription => columndescription }).cR
330
+ tab << row = element(:row).cr.toprule
331
+ csv.headers.each{|title|row << element(:th,{}, title) }
332
+ csv.each{|line|
333
+ tab << row = element(:row).cr
334
+ line.each{|cell|
335
+ row << element(:td,{}, cell.last)
336
+ }
337
+ }
338
+ tab.to_doc( target, options )
339
+ end
340
+ end
341
+
342
+ end #module Creole
343
+
344
+ end #module Docgenerator
345
+
346
+
347
+ if $0 == __FILE__
348
+ creole = Docgenerator::Creole::Creole.new(
349
+ :name => 'tabular_creole',
350
+ :content => <<'creole'
351
+ <<<tabular
352
+ |!columns=3
353
+ |!columndescription=ccc
354
+ |=a
355
+ |=b
356
+ |=c
357
+ |-
358
+ |a
359
+ |b
360
+ |c
361
+ >>>
362
+ creole
363
+ )
364
+ require 'csv'
365
+ creole = Docgenerator::Creole::Creole.new(
366
+ :name => 'tabular_creole',
367
+ :content => <<'creole'
368
+ <<<tabular_csv|columndescription=rrr|col_sep=semicolon
369
+ 1;2;3
370
+ yy;yy;yy;
371
+ xx;xx;xx;
372
+ >>>
373
+ creole
374
+ ) #if false
375
+
376
+ puts creole.to_html #testcode
377
+ puts creole.to_latex #testcode
378
+ end
379
+ __END__
380
+
381
+ class Creole_tabular_cvs
382
+ include Placeholder
383
+
384
+ <<<tabular_csv|CSV-Options
385
+ yy;yy;yy;
386
+ yy;yy;yy;
387
+ yy;yy;yy;
388
+ <<<
389
+
390
+
391
+ Die Syntax:
392
+ *{| beginnt eine Tabelle. Hier können zusätzliche Formatierungseigenschaften kommen.
393
+ **Zumindest columns==__ sollte gesetzt sein
394
+ *! beginnt eine neue Zelle einer Titelzeile
395
+ *| beginnt eine neue Zelle
396
+ *|format| z.B. rowspan...
397
+ *|format|| Zwei || beenden die Parameter der Zelle.
398
+ Dann sinnvoll, wenn im Text selbst ein | vorkommt
399
+ (z.B. ein Macro verwendet wird)
400
+ *|- trennt zwei Zeilen der Tabelle
401
+ **hline: Zusätzlicher Trennstrich über der Zeile
402
+ **toprule, midrule, bottomrule: Zusätzlicher Trennstrich über der Zeile (erfordert booktabs.sty)
403
+ *|} beendet eine Tabelle
404
+
405
+