docgenerator-creole 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,91 @@
1
+ #encoding: utf-8
2
+ =begin rdoc
3
+ =end
4
+
5
+ require 'log4r'
6
+
7
+ module Docgenerator
8
+ =begin rdoc
9
+ Collect the classes to handle Creole-input.
10
+
11
+ More about creole at http://www.wikicreole.org/
12
+ =end
13
+ module Creole
14
+ =begin rdoc
15
+ Build a document.
16
+ This is just a little combination of the classes Document and Creole.
17
+
18
+ For the future: This class could allow features t build one TeX-file and
19
+ multiple HTML (corresponding to pages).
20
+
21
+ HTML-pagebreak could be forced with ======== or something similar.
22
+ =end
23
+ class Creole_document
24
+
25
+ =begin rdoc
26
+ Define a creole document. The settings are forwarded to Document#new()
27
+
28
+ Some settings are used only directly in Creole_document.
29
+ - :with_toc: Add a table of contents at the beginning of the document.
30
+ - :content: Wiki-text. Same as Creole_document#<<
31
+ - :logname: Name for Creole#log
32
+ =end
33
+ def initialize( settings = {} )
34
+ @with_toc = settings[:with_toc ]
35
+ settings.delete(:with_toc) #Avoid error message in Document.new
36
+ settings[:logname] ||= 'CreoleDoc' #Just a name for easier debugging/logging
37
+
38
+ @creole = Creole.new(
39
+ #Get content if available and delete setting to avoid error message in Document.new
40
+ :logname => settings.delete(:logname), #for logger
41
+ :content => settings.delete(:content),
42
+ :ignore => settings.delete(:ignore),
43
+ :targetdir => settings.delete(:targetdir)
44
+ )
45
+ #fixme/ideen parameter
46
+ #preamble -> vor wiki-texten
47
+ #post -> nach wiki-texten
48
+
49
+ @doc = Document.new(settings)
50
+
51
+ @doc.runtex = settings[:runtex] if settings[:runtex]
52
+
53
+ @log = @doc.log
54
+
55
+ @doc.body << creole
56
+
57
+ end
58
+ #The related document
59
+ attr_reader :doc
60
+ #The related creole-object
61
+ attr_reader :creole
62
+ #Add content to the wiki.
63
+ def << (content)
64
+ @creole << content
65
+ end
66
+ =begin rdoc
67
+ Save the creole document.
68
+
69
+ If requested, the tableofcontents is added.
70
+ The first Creole_document#save decides, which variant is added (html/tex)
71
+ =end
72
+ def save( filename, options = {} )
73
+ if @with_toc
74
+ @doc.body.insertbefore(creole, element(:htmlonly,{}, creole.toc(:level => @with_toc )))
75
+ @doc.body.insertbefore(creole, element(:latexonly,{},element(:tableofcontents).cr))
76
+ case @with_toc
77
+ when Numeric
78
+ @doc.head << element(:latexonly,{},"\\setcounter{tocdepth}{#{@with_toc}}\n")
79
+ end
80
+ @with_toc = false #Add it only once
81
+ end #@with_toc
82
+
83
+ @doc.save(filename, options )
84
+ end
85
+ #Use runtex if available.
86
+ def runtex=(option)
87
+ @doc.runtex = option
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,91 @@
1
+ =begin rdoc
2
+ Creole inclusions and plugins
3
+
4
+ This classes are defined to implement transclusions (http://en.wikipedia.org/wiki/Transclusion)
5
+
6
+ * Inclusions are used later with {{xx}}
7
+ more at http://www.wikicreole.org/wiki/Inclusion
8
+ * Plugins are used later with <<xx>>
9
+ more at http://www.wikicreole.org/wiki/Plugin
10
+
11
+ By default, an inclusion expects a pictures, unless it es defined something else.
12
+
13
+ You can extend Wikis with additional inclusions:
14
+
15
+ wiki = Creole.new()
16
+ wiki.inclusion['xxx'] = Creole_inclusion_xxx
17
+ =end
18
+
19
+ #
20
+
21
+ module Docgenerator
22
+ module Creole
23
+
24
+ =begin rdoc
25
+ Dummy class for all inclusions and plugins.
26
+ Used to check the correct definition.
27
+
28
+ - Inclusions are used later with {{xx}}
29
+ - Plugins are used later with <<xx>>
30
+
31
+ Derived classes (Inclusions):
32
+ - Creole_inclusion_img
33
+ - Creole_inclusion_footnote_group
34
+ - Creole_inclusion_footnote
35
+
36
+ Derived classes (Plugins):
37
+ - Creole_default_plugin
38
+ - Creole_plugin_ruby
39
+ - Creole_plugin_ruby_raw
40
+ More subclasses may be possible.
41
+ =end
42
+ class Creole_inclusion_and_plugin
43
+ =begin rdoc
44
+ Example:
45
+ {{inclusionname|description|option1=1,option2=2}}
46
+
47
+ Parameters:
48
+ * inclusionname: Name of the inclusion (normally fix for an instance, unless e.g. Creole_inclusion_img)
49
+ * description: First parameter of the plugin.
50
+ * options: Array with the comma separated values.
51
+ In the example:
52
+ ['option1=1','option2=2']
53
+ * wiki: creole-instance, where the plugin/inclusion is defined.
54
+ =end
55
+ def initialize( inclusionname, description, options, wiki )
56
+ @inclusionname = inclusionname
57
+ @description = description
58
+ @options = options
59
+ @wiki = wiki
60
+
61
+ raise "Inclusion received no wiki but #{wiki.inspect}" unless wiki.is_a?(Creole)
62
+ end
63
+ #Reader for the wiki.
64
+ attr_reader :wiki
65
+
66
+ =begin rdoc
67
+ Define meta-methods for Creole_inclusion_and_plugin
68
+ =end
69
+ class << self
70
+ =begin rdoc
71
+ Define class as a Inclusion.
72
+ You may use the class as:
73
+ {{key}}
74
+ =end
75
+ def set_inclusions_key(key)
76
+ Inclusions::Collection[key] = self
77
+ end
78
+ =begin rdoc
79
+ Define class as a Plugin.
80
+ You may use the class as:
81
+ <<key>>
82
+ =end
83
+ def set_plugin_key(key)
84
+ Plugins::Collection[key] = self
85
+ end
86
+
87
+ end #Meta-methods
88
+ end #Creole_inclusion_and_plugin
89
+ end #module Creole
90
+ end #module Docgenerator
91
+
@@ -0,0 +1,148 @@
1
+ =begin rdoc
2
+ Creole inclusions.
3
+
4
+ This classes are defined to implement inclusions.
5
+
6
+ * Inclusions are used later with {{xx}}
7
+ more at http://www.wikicreole.org/wiki/Inclusion
8
+
9
+ By default, an inclusion expects a pictures, unless it es defined something else.
10
+
11
+ You can extend Wikis with additional inclusions:
12
+
13
+ wiki = Creole.new()
14
+ wiki.inclusion['xxx'] = Creole_inclusion_xxx
15
+ =end
16
+
17
+ #
18
+
19
+ module Docgenerator
20
+ module Creole
21
+
22
+ =begin rdoc
23
+ Define Inclusions
24
+
25
+ Inclusions are used via {{...}}
26
+
27
+ Default: Creole_inclusion_img (defined in class definition Creole_inclusion_img)
28
+ =end
29
+ module Inclusions
30
+ Collection = Hash.new()
31
+
32
+ =begin rdoc
33
+ Include images.
34
+ http://www.wikicreole.org/wiki/Images
35
+
36
+ There are yet more features than in standard.
37
+
38
+ This is also the default for inclusions.
39
+
40
+ Usage:
41
+ {{picurl.jpg|Alternate text|class=cc}}
42
+ {{picurl.jpg|Alternate text|css=width:50%}}
43
+
44
+ See also Placeholders::Creole_figure.
45
+ =end
46
+ class Creole_inclusion_img < Creole_inclusion_and_plugin
47
+ Collection.default = self
48
+ =begin rdoc
49
+ Define an image.
50
+ The existence of the picture is checked.
51
+
52
+ Supported options:
53
+ * alt (2nd parameter of {{picsrc|...}}
54
+ * css or imgcss
55
+ * class or imgclass
56
+ * longdesc (can take a url, at least opera offers to call the description)
57
+ * width (only LaTeX. For HTML, use css-option).
58
+ =end
59
+ def initialize( picname, alt_text, options, wiki )
60
+ super
61
+ @img = element(:img,{ :src => @inclusionname })
62
+ @img[:alt] << alt_text if alt_text
63
+ #Check existence of Picture. Only possible if the related wiki is available.
64
+ wiki.check_link_existence( @inclusionname, wiki.log )
65
+
66
+ css = CSS.new( :log => wiki.log )
67
+
68
+ #
69
+ #Check for options
70
+ #
71
+ #Missing options:
72
+ #* align
73
+ #* border
74
+ #* height
75
+ #* hspace
76
+ #* name
77
+ #* vspace
78
+ options.each{|option|
79
+ case option
80
+ when /^(img)?css\s*=\s*(.*)/
81
+ $2.split(/\s*;\s*/).each{|css_assignment|
82
+ css_assignment =~ /(.+?)\s*:\s*(.+)/
83
+ css[$1] = $2
84
+ }
85
+ when /^(img)?class\s*=\s*(.*)/
86
+ @img[:class] << $2
87
+ when /^width\s*=\s*(.*)/ #only for TeX
88
+ @img[:width] << $1
89
+ when /^height\s*=\s*(.*)/
90
+ @img[:height] << $1
91
+ when /^texoption\s*=\s*(.*)/
92
+ @img[:texoption] << $1
93
+ when /^caption\s*=\s*(.*)/
94
+ #makes only sense in TeX-output.
95
+ @img = element(:figure,{},[element(:centering), @img.Cr, element(:caption,{},$1).cr])
96
+ when /^longdesc\s*=\s*(.*)/ #gibt einen URI (nach RFC 2396) an, wo eine Langbeschreibung der Grafik zu finden ist
97
+ @img[:longdesc] << $1
98
+ else
99
+ wiki.log.warn("Img: Undefined option #{option}") if wiki.log.warn?
100
+ end #case option
101
+ } if options
102
+ @img.attr[:style] << css
103
+
104
+ end
105
+ def to_doc(target, options = {})
106
+ @img.to_doc(target, options)
107
+ end
108
+ end #Creole_inclusion_img
109
+
110
+ =begin rdoc
111
+ Some short html
112
+
113
+ Usage:
114
+ {{html|code}}
115
+
116
+ Note:
117
+ There is also a placeholder for larger html:
118
+ <<<html
119
+ content
120
+ >>>
121
+ =end
122
+ class Creole_short_html < Creole_inclusion_and_plugin
123
+ #We don't use it as plugin. Closing > from html may be confusing as in:
124
+ # <<html|<em>kursuiv</em>>>
125
+ set_inclusions_key 'html'
126
+
127
+
128
+ def initialize( inclusionname, description, options, wiki )
129
+ super
130
+ options.each{|option|
131
+ #~ case option
132
+ #~ else
133
+ @wiki.log.warn("HTML with unknown option #{option.inspect} not found") if @wiki.log.warn?
134
+ #~ end
135
+ }
136
+ @source = description
137
+
138
+ end
139
+ #Return content only for html
140
+ def to_doc( target, options = {})
141
+ target == :html ? @source.to_doc( target, options ) : ''
142
+ end
143
+ end #Creole_inclusion_html
144
+ end #module Inclusions
145
+ end #module Creole
146
+ end #module Docgenerator
147
+
148
+
@@ -0,0 +1,242 @@
1
+ module Docgenerator
2
+ module Creole
3
+
4
+ =begin rdoc
5
+ Placeholder are defined in Creole-Syntax via <<< >>>
6
+
7
+ Placeholders get a name and optional parameters:
8
+ <<<name|parameter
9
+
10
+ Placeholders collect the content between <<< and >>>.
11
+
12
+ Derived classes are:
13
+ - Creole::Placeholders::Dummy
14
+ - Creole::Placeholders::Html
15
+ - Creole::Placeholders::Latex
16
+ - Creole::Creole_tabular
17
+ - Creole::Creole_tab
18
+ =end
19
+ class Placeholder
20
+ =begin rdoc
21
+ Define meta-methods for Creole_inclusion_and_plugin
22
+ =end
23
+ class << self
24
+ =begin rdoc
25
+ Define class as a placeholder.
26
+ You may use the class as:
27
+ {{key}}
28
+ =end
29
+ def set_placeholder_key(key)
30
+ Placeholders::Collection[key] = self
31
+ end
32
+ end
33
+
34
+ #Error is thrown, if the parameters don't fit the need of the placeholder
35
+ class ParameterError < ArgumentError; end;
36
+ =begin rdoc
37
+ Each placeholder get the wiki where it belongs to.
38
+
39
+ Parameters is an optional string.
40
+
41
+ Definition inside the wiki:
42
+ <<<name|parameters
43
+ content
44
+ >>>
45
+ Placeholders collect the content between <<< and >>>.
46
+ =end
47
+ def initialize( wiki, parameters = nil)
48
+ @wiki = wiki
49
+ @parameters = parameters
50
+ @log = @wiki.log
51
+ end
52
+ #
53
+ #Add the content between <<< and >>>.
54
+ def << (content)
55
+ @source = [] unless @source
56
+ @source << content
57
+ end
58
+ #
59
+ #Possibility to analyse the content.
60
+ def close()
61
+ @source.freeze
62
+ end
63
+ #Export it. Should be redefined by sub classes.
64
+ def to_doc( target, options = {})
65
+ @source.to_doc( target, options )
66
+ end
67
+ end #Placeholder
68
+
69
+
70
+ =begin rdoc
71
+ Collection of Placeholder-children
72
+
73
+ Placeholders are used via <<<...>>>.
74
+ =end
75
+ module Placeholders
76
+ =begin rdoc
77
+ Just a dummy for wrong definitions.
78
+
79
+ This class is used by Creole a default placeholder.
80
+ =end
81
+ class Dummy < Placeholder
82
+ end #Placeholder::Dummy
83
+
84
+ #List of defined Placeholders.
85
+ Collection = Hash.new( Dummy )
86
+ #Get a Placeholder.
87
+ def self.[](key)
88
+ Collection[key]
89
+ end
90
+
91
+
92
+ =begin rdoc
93
+ Placeholder for pure HTML-output.
94
+ This content is ignored in LaTeX, Wiki... documents.
95
+
96
+ Usage:
97
+ <<<html
98
+ content
99
+ >>>
100
+
101
+ Note:
102
+ There is also a plugin for short html:
103
+ {{html|code}}
104
+ =end
105
+ class Creole_html < Placeholder
106
+ set_placeholder_key 'html'
107
+ #Return content only for html
108
+ def to_doc( target, options = {})
109
+ target == :html ? @source.to_doc( target, options ) : ''
110
+ end
111
+ end #Creole_html
112
+
113
+ =begin
114
+ Placeholder for pure LaTeX-output.
115
+ This content is ignored in HTML, Wiki... documents.
116
+
117
+ Idea for option: Parse the content by the wiki.
118
+
119
+ Pro:
120
+ -allows the usage of <<ruby|...
121
+ Cons:
122
+ -unexpected conversions?
123
+ =end
124
+ class Creole_latex < Placeholder
125
+ set_placeholder_key 'latex'
126
+ #Return content only for latex
127
+ def to_doc( target, options = {})
128
+ target == :latex ? @source.to_doc( target, options ) : ''
129
+ end
130
+ end #Creole_latex
131
+
132
+ =begin rdoc
133
+ Usage:
134
+ <<<comment
135
+ This text is a comment.
136
+ >>>
137
+ =end
138
+ class Creole_comment < Placeholder
139
+ set_placeholder_key 'comment'
140
+ #Return content as a comment
141
+ def to_doc( target, options = {})
142
+ case target
143
+ when :html; to_html( options )
144
+ when :latex; to_latex( options )
145
+ when :context; to_latex( options )
146
+ when :creole; to_creole( options )
147
+ else
148
+ @log.error("Creole_comment not supported for target #{target.inspect}") if @log.error?
149
+ end
150
+ end
151
+ def to_html(options = {})
152
+ return "<!-- #{@source.join} -->"
153
+ end
154
+ alias :to_context :to_latex
155
+ def to_latex(options = {})
156
+ return @source.map{|l| "%#{l}" }.join
157
+ end
158
+ def to_creole(options = {})
159
+ return "<<<comment\n#{@source.join}>>>"
160
+ end
161
+ end #Creole_comment
162
+
163
+ =begin
164
+ See also Inclusions::Creole_inclusion_img
165
+
166
+ Usage:
167
+ <<<figure|picname.jpg|options
168
+ Description
169
+ >>>
170
+
171
+ Options may be:
172
+ # options if element Figure
173
+ # options if element CSS
174
+ =end
175
+ class Creole_figure < Placeholder
176
+ set_placeholder_key 'figure'
177
+
178
+ #Return content as a comment
179
+ def to_doc( target, options = {})
180
+ css = CSS.new()
181
+ caption = nil
182
+ includegraphics_options = {}
183
+
184
+ fig = element(:figure,
185
+ :style => css
186
+ ).CR
187
+ float = 'top'
188
+ @parameters.split(/\|/).each{|parameter|
189
+ case parameter
190
+ when /caption\s*=\s*(.*)/
191
+ caption = $1
192
+ when /class\s*=\s*(.*)/
193
+ fig.attr[:class] << $1
194
+ when /texwidth\s*=(.*)/
195
+ includegraphics_options[:width] = $1
196
+ when /(.*)=(.*)/
197
+ if fig.attr[$1]
198
+ fig[$1] = $2
199
+ elsif css.supports?($1)
200
+ css[$1] = $2
201
+ else
202
+ @log.warn("Unknown option %s in figure %s" % [parameter, src])
203
+ end
204
+ else
205
+ if includegraphics_options[:src]
206
+ @log.warn("Unknown option %s in figure %s" % [parameter, src])
207
+ else #Image is first parameter.
208
+ includegraphics_options[:src] = parameter
209
+ end
210
+ end
211
+ }
212
+
213
+ #Set defauts:
214
+ {'border-width' =>'1px',
215
+ 'border-style' =>'solid',
216
+ 'float' => 'right',
217
+ 'width' => '50%',
218
+ }.each{|key,value|
219
+ css[key] = value unless css[key]
220
+ }
221
+
222
+ fig << element(:includegraphics,includegraphics_options).cr
223
+ fig << element(:label,{:name=>'fig:%s' % includegraphics_options[:src]}).cr
224
+ if @source
225
+ fig << element(:newline).cr
226
+ fig << @source
227
+ end
228
+ fig << element(:caption,{}, caption).cr if caption
229
+ fig.to_doc( target, options)
230
+ end
231
+ end
232
+
233
+ end #module Placeholders
234
+ end #module Creole
235
+ end #module Docgenerator
236
+
237
+
238
+ __END__
239
+ To be done:
240
+ rubycode (see plugin Creole_plugin_ruby )
241
+
242
+ Steuerparameter mit | nach plugin-name?