docgenerator 1.2.1 → 2.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 (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,43 @@
1
+ =begin rdoc
2
+ Implement includepdf from pdfpages-package.
3
+
4
+ Requires a
5
+ doc.head << element(:usepackage,{},'pdfpages')
6
+
7
+ The usepackage command loads this script by its own.
8
+
9
+ You may also use:
10
+ require 'docgenerator/packages/pdfpages.rb'
11
+ ...
12
+ doc.head << IncludePDF.head
13
+
14
+ =end
15
+
16
+ #
17
+ module Docgenerator
18
+ module Packages
19
+ =begin rdoc
20
+ Implement includepdf from pdfpages-package.
21
+ =end
22
+ class IncludePDF < Element
23
+ =begin rdoc
24
+ Return header definition for usage of the command.
25
+ =end
26
+ def self.head()
27
+ element(:usepackage,{},'pdfpages').cr
28
+ end
29
+
30
+ add_attribute :pages, Attribute.create( [ :texkeyval], [ String ] )
31
+ add_attribute :nup, Attribute.create( [ :texkeyval], [ /\d+x\d+/ ] ) #multiple logical pages onto each sheet of paper.
32
+ add_attribute :landscape, Attribute.create( [ :texkeyval], [ true, false ] ) #multiple logical pages onto each sheet of paper.
33
+ add_attribute :pagecommand, Attribute.create( [ :texkeyval], [ String ] ) #multiple logical pages onto each sheet of paper.
34
+ add_attribute :link, Attribute.create( [ :texkeyval], [ true, false] )
35
+ add_attribute :linkname, Attribute.create( [ :texkeyval], [ String ] )
36
+ add_attribute :linktodoc, Attribute.create( [ :texkeyval], [ true, false] ) #Lets the inserted pages be hyperlinks to the document from which they were extracted.
37
+ #~ add_attribute :addtotoc, Attribute.create( [ :texkeyval], [ /.+,.+,.+,.+,.+/] ), #
38
+
39
+ add_output( :latex, '#{linebreak(@crbefore)}\includepdf[#{texkeyval()}]{#{@content}}#{linebreak(@crafter)}')
40
+
41
+ end #IncludePDF
42
+ end #module Packages
43
+ end #module Docgenerator
@@ -0,0 +1,227 @@
1
+ =begin rdoc
2
+ Little helper to make documention on ruby scripts,
3
+ Ruby fragments are executed line by line.
4
+
5
+ The source code is enriched with the results and can be shown.
6
+ =end
7
+
8
+ require 'docgenerator'
9
+ require 'docgenerator/packages/listings'
10
+ #~ require '../../lib/packages/docgenerator_listings'
11
+
12
+ #
13
+ module Docgenerator
14
+ module Rubycode
15
+
16
+
17
+ class CodeTest
18
+ #Catch output.
19
+ #
20
+ #Used to replace $stdout
21
+ class MyIO < String
22
+ def write( cont )
23
+ self << cont
24
+ end
25
+ end #MyIO
26
+
27
+ Code_line = Struct.new('Code_line', :code, :line_number, :result, :output, :outputtab, :comment )
28
+ @@all = {}
29
+ =begin rdoc
30
+ Get some executable ruby code and analyse it.
31
+ If a name is given, it is stored for later reuse (see CodeTest[])
32
+ =end
33
+ def initialize( name, code = '' )
34
+ @name = name
35
+ if @@all[@name]
36
+ raise "Double definition of CodeTest #{name.inspect}"
37
+ else
38
+ @@all[@name] = self
39
+ end if name
40
+ #Keep binding for code execution
41
+ @bind = binding
42
+ #Collection of all coding lines (elements are Code_line-struct)
43
+ @codelines = []
44
+ code.split(/\n/).each{|c|
45
+ self << c
46
+ }
47
+ end
48
+ =begin rdoc
49
+ Add one coding line.
50
+ -Each line is executed,
51
+ -The result o fthe line is added to #result
52
+ -The output is added to #output
53
+
54
+ Restrictions:
55
+ -One line, one command (only last command returns its result)
56
+ =end
57
+ def << ( c )
58
+ #fixme: command mit Strings "#...
59
+ command, comment = c.chomp.split(/#/, 2 )
60
+ #~ if comment
61
+ #~ puts '--'*10 + 'comment'
62
+ #~ puts c.chomp
63
+ #~ puts command
64
+ #~ puts comment.inspect
65
+ #~ end
66
+ begin
67
+ $stdout = output = MyIO.new
68
+ codeline = Code_line.new( c.chomp, @codelines.size + 1, eval(c, @bind) )
69
+ rescue SyntaxError
70
+ $stdout = STDOUT
71
+ DOCGENERATOR_LOGGER.error("CodeTest #{@name}: Syntax Error with: '#{c}'") if DOCGENERATOR_LOGGER.error?
72
+ return
73
+ end
74
+ $stdout = STDOUT
75
+ codeline.outputtab = []
76
+ if output.size > 0
77
+ codeline.output = output.inspect
78
+ codeline.outputtab = output.split("\n")
79
+ end
80
+ codeline.comment = comment
81
+ @codelines << codeline
82
+ end
83
+ #Get 'plain' sourcecode
84
+ def sourcecode()
85
+ code = []
86
+ @codelines.each{|codeline|
87
+ code << codeline.code
88
+ }
89
+ code.join("\n")
90
+ end
91
+ #Get 'plain' output
92
+ def output()
93
+ output = []
94
+ @codelines.each{|codeline|
95
+ #~ output << codeline.output
96
+ output << codeline.outputtab
97
+ }
98
+ output.join("\n")
99
+ end
100
+ =begin rdoc
101
+ Get code and results in a verbatim env.
102
+ The comments starts after the column max. (default: longest code line + 3 )
103
+
104
+ Example:
105
+ 1 + 1
106
+ becomes
107
+ 1 + 1 #2
108
+
109
+ fixme: define scope, from-to line
110
+ =end
111
+ def code_evaluation( max = @codelines.map{|f|f.code.size}.max + 3 )
112
+ evaluated_code = []
113
+ @codelines.each{|codeline|
114
+ #Prepare coding line with result of the line if not done before
115
+ evaluated_line = "%-#{max}s" % [ codeline.code ]
116
+ if codeline.result or codeline.output
117
+ evaluated_line << " # "
118
+ end
119
+ if codeline.result
120
+ evaluated_line << '-> %-10s' % [ codeline.result ]
121
+ end
122
+ if codeline.output
123
+ evaluated_line << '=> %-10s' % [ codeline.output ]
124
+ end
125
+ evaluated_code << evaluated_line
126
+ }
127
+ evaluated_code.join("\n")
128
+ end
129
+
130
+ #Get code and results in a lstlistings environment.
131
+ def code_evaluation_lstlisting( max = @codelines.map{|f|f.code.size}.max + 3 )
132
+ element(:lstlisting,{ :numbers => 'left',
133
+ :numberstyle => '\tiny',
134
+ :class => 'rubycode_with_result',
135
+ }, self.code_evaluation( max) ).cR
136
+ end #code_evaluation()
137
+ =begin rdoc
138
+ Get code
139
+ =end
140
+ def code()
141
+ element(:lstlisting,{ :numbers => 'left',
142
+ :numberstyle => '\tiny',
143
+ :class => 'rubycode',
144
+ }, @codelines.map{|codeline| codeline.code}.join("\n")).cR
145
+ end #code_evaluation()
146
+ =begin rdoc
147
+ return tabular with code, result and output.
148
+ =end
149
+ def code_in_tab()
150
+ #~ element(:verbatim,{}, @code)
151
+ #~ puts 'tabularx mag kein verbatim'
152
+ #~ tabular = element(:tabularx, {
153
+ #~ :columndescription => 'lXllXX',
154
+ #~ :width => '\\textwidth',
155
+ tabular = element(:tabular, {
156
+ :columndescription => 'lp{3cm}llp{3cm}',
157
+ :columns => 5,
158
+ :border => 1,
159
+ }).Cr
160
+ tabular << row = element(:row).cr.hline
161
+ row << element(:col, {}, 'No' )
162
+ row << element(:col, {}, 'Code' )
163
+ row << element(:col, {}, 'Result' )
164
+ row << element(:col, {}, 'Output' )
165
+ row << element(:col, {}, 'Output2' )
166
+ @codelines.each{|c|
167
+ tabular << row = element(:row).cr
168
+ row << element(:col, {}, c.line_number )
169
+ if c.code.include?("\n")
170
+ row << element(:col, {}, element(:lstlisting,{:class => 'rubycode' }, ["\n", c.code]) ).Cr
171
+ else
172
+ row << element(:col, {}, element(:lstinline,{:class => 'rubycode' }, c.code) )
173
+ end
174
+ row << element(:col, {}, c.result )
175
+ row << element(:col, {}, c.output ? element(:verb,{ :class => 'ruby_result_string' }, c.output) : nil )
176
+ #~ row << element(:col, {}, c.outputtab.map{|i| [i, element(:br)]}.flatten[0..-2] )
177
+ row << element(:col, {}, element(:verbatim,{:class => 'ruby_result'}, c.outputtab.join("\n") ) )
178
+ }
179
+ tabular
180
+ end
181
+ =begin rdoc
182
+ Get the code fragment
183
+ =end
184
+ def self.[](name)
185
+ @@all[name]
186
+ end
187
+ =begin rdoc
188
+ Build a Document with required head-definitions
189
+ (usepackage...)
190
+ =end
191
+ def self.mk_document( title )
192
+ doc = Document.new(
193
+ :title => title
194
+ )
195
+ doc.head << element(:usepackage,{ }, 'listings').cr
196
+ doc.head << element(:usepackage,{ }, 'color').cr
197
+ doc.head << element(:lstloadlanguages,{}, 'ruby' ).cr
198
+ doc.head << element(:lstset, {
199
+ :language => 'ruby',
200
+ :commentstyle => '\color{blue}',
201
+ } ).cr
202
+ return doc
203
+ end
204
+ end #CodeTest
205
+ end #module Rubycode
206
+ end #module Docgenerator
207
+
208
+ if $0 == __FILE__
209
+ test = CodeTest.new('codetest', <<CODE
210
+ a = 5
211
+ b = a * 5
212
+ puts b
213
+ puts b + 3
214
+ CODE
215
+ )
216
+ puts test.code_evaluation
217
+
218
+ puts "\n====Add more code====\n\n"
219
+ test << <<TEST
220
+ 3.times{|i|
221
+ puts i
222
+ }
223
+ TEST
224
+
225
+
226
+ puts test.code_evaluation
227
+ end #if $0 == __FILE__
@@ -1,12 +1,17 @@
1
- #
2
- #Definition of elements for class DocGenerator_scrlettr2.rb
3
- #used by for DocGenerator.rb
4
- #
1
+ =begin rdoc
2
+ Definition of elements for LaTeX class scrlettr2 (Koma-Script)
3
+
4
+ * http://www.ctan.org/tex-archive/macros/latex/contrib/koma-script/
5
+ =end
5
6
  if __FILE__ == $0
6
7
  require 'docgenerator'
7
8
  end
8
9
  #~ require 'date'
9
10
 
11
+ #
12
+ module Docgenerator
13
+ module Packages
14
+ module Letter
10
15
  DocumentTemplate.new(
11
16
  :scrlttr2, :latex, %q|<<prefix>>
12
17
  \documentclass[<<classoptions>>]{scrlttr2}
@@ -25,7 +30,6 @@ DocumentTemplate.new(
25
30
 
26
31
 
27
32
  class LoadLetterOption < Element
28
- Element.add( [:loadletteroption], LoadLetterOption)
29
33
 
30
34
  def to_latex( options = {} )
31
35
  cmd = ''
@@ -40,12 +44,8 @@ end #LoadLetterOption
40
44
  # element(:setkomavar,{:field => field}, .content).cr
41
45
  # element(:setkomavar,{:field => field, :fieldtext=>'Text'}, .content).cr
42
46
  class Setkomavar < Element
43
- Element.add( [:setkomavar], Setkomavar)
44
- add_attributes( {
45
- :field => Attribute.create( [ :latex, :required ], [Symbol], 1 ),
46
- :fieldtext => Attribute.create( [ :latex, :required ], [String], 2 ),
47
- }#.update(HTML_ATTR_ALL)
48
- )
47
+ add_attribute :field, Attribute.create( [ :latex, :required ], [Symbol], 1 )
48
+ add_attribute :fieldtext, Attribute.create( [ :latex, :required ], [String], 2 )
49
49
 
50
50
  def to_latex( options = {} )
51
51
  cmd = ''
@@ -70,8 +70,8 @@ end #Setkomavar
70
70
  # :opening => '~',
71
71
  # :closing => '~',
72
72
  # }).cr
73
- class Letter < Environment
74
- Element.add( [:letter], self )
73
+ class Letter < Environments::Environment
74
+
75
75
  add_attributes( {
76
76
  :address => Attribute.create( [ :latex, :required ] ),
77
77
  :date => Attribute.create( [ :latex ], [String] ), #Date?
@@ -120,7 +120,13 @@ class Letter < Environment
120
120
  return ''
121
121
  end
122
122
  end
123
- def to_latex_environment( environment, options = {} )
123
+ =begin rdoc
124
+ Redefine to_latex_environment.
125
+
126
+ Parameters for letters are defined via #setkomavar.
127
+
128
+ =end
129
+ def to_latex_environment( environment, parameter = nil, options = {} )
124
130
  cmd = ''
125
131
  cmd << "\n" if @crbefore
126
132
  cmd << "\n\\begin{#{environment}}"
@@ -155,7 +161,7 @@ class Letter < Environment
155
161
  return cmd
156
162
  end
157
163
  def to_latex( options = {} )
158
- return to_latex_environment( 'letter', options )
164
+ return to_latex_environment( 'letter', nil, options )
159
165
  end
160
166
  def to_html( options = {})
161
167
  cmd = element( :div ).CR
@@ -169,4 +175,7 @@ class Letter < Environment
169
175
  #~ cmd << "\n" if @crafter
170
176
  return cmd.to_html(options)
171
177
  end
172
- end
178
+ end
179
+ end #module Letter
180
+ end #module Packages
181
+ end #module Docgenerator
@@ -0,0 +1,410 @@
1
+ module Docgenerator
2
+ module Packages
3
+ =begin rdoc
4
+ Support for scrpage2.sty (Koma-Script)
5
+
6
+ * http://www.ctan.org/tex-archive/macros/latex/contrib/koma-script/
7
+ =end
8
+ module Scrpage2
9
+
10
+ =begin rdoc
11
+ Define Element :clearscrheadings
12
+
13
+ Create an instance with
14
+ element( :clearscrheadings, [ attributes, [content]] )
15
+ or
16
+ Clearscrheadings.new( [ attributes, [content]] )
17
+ Attributes are not defined for this element.
18
+ =end
19
+ class Clearscrheadings < Element
20
+ has_no_content false
21
+ add_latex_output '#{linebreak(@crbefore)}\clearscrheadings #{linebreak(@crafter)}'
22
+ end #Clearscrheadings
23
+
24
+ =begin rdoc
25
+ Define Element :clearscrheadfoot
26
+
27
+ Create an instance with
28
+ element( :clearscrheadfoot, [ attributes, [content]] )
29
+ or
30
+ Clearscrheadfoot.new( [ attributes, [content]] )
31
+ Attributes are not defined for this element.
32
+ =end
33
+ class Clearscrheadfoot < Element
34
+ has_no_content false
35
+ add_latex_output '#{linebreak(@crbefore)}\clearscrheadfoot #{linebreak(@crafter)}'
36
+ end #Clearscrheadfoot
37
+
38
+ =begin rdoc
39
+ Define Element :clearscrplain
40
+
41
+ Create an instance with
42
+ element( :clearscrplain, [ attributes, [content]] )
43
+ or
44
+ Clearscrplain.new( [ attributes, [content]] )
45
+ Attributes are not defined for this element.
46
+ =end
47
+ class Clearscrplain < Element
48
+ has_no_content false
49
+ add_latex_output '#{linebreak(@crbefore)}\clearscrplain #{linebreak(@crafter)}'
50
+ end #Clearscrplain
51
+
52
+ =begin rdoc
53
+ Define Element :pagestyle
54
+
55
+ Create an instance with
56
+ element( :pagestyle, [ attributes, [content]] )
57
+ or
58
+ Pagestyle.new( [ attributes, [content]] )
59
+ Attributes are not defined for this element.
60
+
61
+ Values: scrheadings, scrplain
62
+
63
+ =end
64
+ class Pagestyle < Element
65
+ #fixme check content only scrheadings, scrplain
66
+ add_latex_output '#{linebreak(@crbefore)}\pagestyle{#{@content}}#{linebreak(@crafter)}'
67
+ end #Pagestyle
68
+
69
+ =begin rdoc
70
+ Define Element :manualmark
71
+
72
+ Create an instance with
73
+ element( :manualmark, [ attributes, [content]] )
74
+ or
75
+ Manualmark.new( [ attributes, [content]] )
76
+ Attributes are not defined for this element.
77
+ =end
78
+ class Manualmark < Element
79
+ has_no_content false
80
+ add_latex_output '#{linebreak(@crbefore)}\manualmark #{linebreak(@crafter)}'
81
+ end #Manualmark
82
+
83
+ =begin rdoc
84
+ Define Element :automark
85
+
86
+ Create an instance with
87
+ element( :automark, [ attributes, [content]] )
88
+ or
89
+ Automark.new( [ attributes, [content]] )
90
+ Attributes may be:
91
+ * :rightmark:
92
+ =end
93
+ class Automark < Element
94
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
95
+ add_latex_output '#{linebreak(@crbefore)}\automark#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
96
+ end #Automark
97
+
98
+ =begin rdoc
99
+ Define Element :lehead
100
+
101
+ Create an instance with
102
+ element( :lehead, [ attributes, [content]] )
103
+ or
104
+ Lehead.new( [ attributes, [content]] )
105
+ Attributes may be:
106
+ * :rightmark:
107
+ =end
108
+ class Lehead < Element
109
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
110
+ add_latex_output '#{linebreak(@crbefore)}\lehead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
111
+ end #Lehead
112
+
113
+ =begin rdoc
114
+ Define Element :cehead
115
+
116
+ Create an instance with
117
+ element( :cehead, [ attributes, [content]] )
118
+ or
119
+ Cehead.new( [ attributes, [content]] )
120
+ Attributes may be:
121
+ * :rightmark:
122
+ =end
123
+ class Cehead < Element
124
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
125
+ add_latex_output '#{linebreak(@crbefore)}\cehead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
126
+ end #Cehead
127
+
128
+ =begin rdoc
129
+ Define Element :rehead
130
+
131
+ Create an instance with
132
+ element( :rehead, [ attributes, [content]] )
133
+ or
134
+ Rehead.new( [ attributes, [content]] )
135
+ Attributes may be:
136
+ * :rightmark:
137
+ =end
138
+ class Rehead < Element
139
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
140
+ add_latex_output '#{linebreak(@crbefore)}\rehead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
141
+ end #Rehead
142
+
143
+ =begin rdoc
144
+ Define Element :lefoot
145
+
146
+ Create an instance with
147
+ element( :lefoot, [ attributes, [content]] )
148
+ or
149
+ Lefoot.new( [ attributes, [content]] )
150
+ Attributes may be:
151
+ * :rightmark:
152
+ =end
153
+ class Lefoot < Element
154
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
155
+ add_latex_output '#{linebreak(@crbefore)}\lefoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
156
+ end #Lefoot
157
+
158
+ =begin rdoc
159
+ Define Element :cefoot
160
+
161
+ Create an instance with
162
+ element( :cefoot, [ attributes, [content]] )
163
+ or
164
+ Cefoot.new( [ attributes, [content]] )
165
+ Attributes may be:
166
+ * :rightmark:
167
+ =end
168
+ class Cefoot < Element
169
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
170
+ add_latex_output '#{linebreak(@crbefore)}\cefoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
171
+ end #Cefoot
172
+
173
+ =begin rdoc
174
+ Define Element :refoot
175
+
176
+ Create an instance with
177
+ element( :refoot, [ attributes, [content]] )
178
+ or
179
+ Refoot.new( [ attributes, [content]] )
180
+ Attributes may be:
181
+ * :rightmark:
182
+ =end
183
+ class Refoot < Element
184
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
185
+ add_latex_output '#{linebreak(@crbefore)}\refoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
186
+ end #Refoot
187
+
188
+ =begin rdoc
189
+ Define Element :lohead
190
+
191
+ Create an instance with
192
+ element( :lohead, [ attributes, [content]] )
193
+ or
194
+ Lohead.new( [ attributes, [content]] )
195
+ Attributes may be:
196
+ * :rightmark:
197
+ =end
198
+ class Lohead < Element
199
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
200
+ add_latex_output '#{linebreak(@crbefore)}\lohead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
201
+ end #Lohead
202
+
203
+ =begin rdoc
204
+ Define Element :cohead
205
+
206
+ Create an instance with
207
+ element( :cohead, [ attributes, [content]] )
208
+ or
209
+ Cohead.new( [ attributes, [content]] )
210
+ Attributes may be:
211
+ * :rightmark:
212
+ =end
213
+ class Cohead < Element
214
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
215
+ add_latex_output '#{linebreak(@crbefore)}\cohead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
216
+ end #Cohead
217
+
218
+ =begin rdoc
219
+ Define Element :rohead
220
+
221
+ Create an instance with
222
+ element( :rohead, [ attributes, [content]] )
223
+ or
224
+ Rohead.new( [ attributes, [content]] )
225
+ Attributes may be:
226
+ * :rightmark:
227
+ =end
228
+ class Rohead < Element
229
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
230
+ add_latex_output '#{linebreak(@crbefore)}\rohead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
231
+ end #Rohead
232
+
233
+
234
+ =begin rdoc
235
+ Define Element :lofoot
236
+
237
+ Create an instance with
238
+ element( :lofoot, [ attributes, [content]] )
239
+ or
240
+ Lofoot.new( [ attributes, [content]] )
241
+ Attributes may be:
242
+ * :rightmark:
243
+ =end
244
+ class Lofoot < Element
245
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
246
+ add_latex_output '#{linebreak(@crbefore)}\lofoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
247
+ end #Lofoot
248
+
249
+ =begin rdoc
250
+ Define Element :cofoot
251
+
252
+ Create an instance with
253
+ element( :cofoot, [ attributes, [content]] )
254
+ or
255
+ Cofoot.new( [ attributes, [content]] )
256
+ Attributes may be:
257
+ * :rightmark:
258
+ =end
259
+ class Cofoot < Element
260
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
261
+ add_latex_output '#{linebreak(@crbefore)}\cofoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
262
+ end #Cofoot
263
+
264
+ =begin rdoc
265
+ Define Element :rofoot
266
+
267
+ Create an instance with
268
+ element( :rofoot, [ attributes, [content]] )
269
+ or
270
+ Rofoot.new( [ attributes, [content]] )
271
+ Attributes may be:
272
+ * :rightmark:
273
+ =end
274
+ class Rofoot < Element
275
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
276
+ add_latex_output '#{linebreak(@crbefore)}\rofoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
277
+ end #Rofoot
278
+
279
+ =begin rdoc
280
+ Define Element :ihead
281
+
282
+ Create an instance with
283
+ element( :ihead, [ attributes, [content]] )
284
+ or
285
+ Ihead.new( [ attributes, [content]] )
286
+ Attributes may be:
287
+ * :rightmark:
288
+ =end
289
+ class Ihead < Element
290
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
291
+ add_latex_output '#{linebreak(@crbefore)}\ihead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
292
+ end #Ihead
293
+
294
+ =begin rdoc
295
+ Define Element :chead
296
+
297
+ Create an instance with
298
+ element( :chead, [ attributes, [content]] )
299
+ or
300
+ Chead.new( [ attributes, [content]] )
301
+ Attributes may be:
302
+ * :rightmark:
303
+ =end
304
+ class Chead < Element
305
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
306
+ add_latex_output '#{linebreak(@crbefore)}\chead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
307
+ end #Chead
308
+
309
+ =begin rdoc
310
+ Define Element :ohead
311
+
312
+ Create an instance with
313
+ element( :ohead, [ attributes, [content]] )
314
+ or
315
+ Ohead.new( [ attributes, [content]] )
316
+ Attributes may be:
317
+ * :rightmark:
318
+ =end
319
+ class Ohead < Element
320
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
321
+ add_latex_output '#{linebreak(@crbefore)}\ohead#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
322
+ end #Ohead
323
+
324
+ =begin rdoc
325
+ Define Element :ifoot
326
+
327
+ Create an instance with
328
+ element( :ifoot, [ attributes, [content]] )
329
+ or
330
+ Ifoot.new( [ attributes, [content]] )
331
+ Attributes may be:
332
+ * :rightmark:
333
+ =end
334
+ class Ifoot < Element
335
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
336
+ add_latex_output '#{linebreak(@crbefore)}\ifoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
337
+ end #Ifoot
338
+
339
+ =begin rdoc
340
+ Define Element :cfoot
341
+
342
+ Create an instance with
343
+ element( :cfoot, [ attributes, [content]] )
344
+ or
345
+ Cfoot.new( [ attributes, [content]] )
346
+ Attributes may be:
347
+ * :rightmark:
348
+ =end
349
+ class Cfoot < Element
350
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
351
+ add_latex_output '#{linebreak(@crbefore)}\cfoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
352
+ end #Cfoot
353
+
354
+ =begin rdoc
355
+ Define Element :ofoot
356
+
357
+ Create an instance with
358
+ element( :ofoot, [ attributes, [content]] )
359
+ or
360
+ Ofoot.new( [ attributes, [content]] )
361
+ Attributes may be:
362
+ * :rightmark:
363
+ =end
364
+ class Ofoot < Element
365
+ add_attribute :rightmark, Attribute.create( [ :latex ], [ String ] )
366
+ add_latex_output '#{linebreak(@crbefore)}\ofoot#{texoptional(:rightmark)}{#{@content}}#{linebreak(@crafter)}'
367
+ end #Ofoot
368
+
369
+ #~ #
370
+ #
371
+ #~ class Captionof < Element
372
+ #~ #Make the key known to the complete key-list of elements.
373
+ #~ Element.add( [:captionof], Captionof)
374
+ #~ add_attributes( HTML_ATTR_ALL )
375
+ #~ add_attributes( {
376
+ #~ :float_type => Attribute.create( [ :latex, :required ], [ 'figure', 'table' ] ),
377
+ #~ :lst_entry => Attribute.create( [ ], [ String ] ),
378
+ #~ } )
379
+
380
+ #~ #Redefine standard output.
381
+ #~ #Options are given, if an option is avalaible.
382
+ #~ def to_latex()
383
+ #~ cmd = linebreak(@crbefore)
384
+ #~ cmd << "\\captionof{#{@attr[:float_type]}}"
385
+ #~ #Empty [] would return empty entry for list of figures,
386
+ #~ cmd << "[#{@attr[:lst_entry]}]" if @attr[:lst_entry].content?
387
+ #~ cmd << "{#{@content}}"
388
+ #~ cmd << linebreak(@crafter)
389
+ #~ return cmd
390
+ #~ end
391
+ #~ def htmltag(); 'span'; end #fixme
392
+ #~ def to_html()
393
+ #~ return ''
394
+ #~ end
395
+ #~ end #
396
+
397
+ end #module Scrpage2
398
+ end #module Packages
399
+ end #module Docgenerator
400
+ __END__
401
+ pdf.head << element(:usepackage,{}, 'scrpage2' ).cr
402
+ pdf.head << element(:usepackage,{}, 'totpages' ).cr
403
+
404
+ pdf.head << element(:pagestyle,{}, 'scrheadings' ).cr
405
+ pdf.head << element(:automark, {}, 'section').cr
406
+
407
+ pdf.head << element(:clearscrheadings).cr
408
+ pdf.head << element(:ihead, {}, '\\headmark').cr
409
+ pdf.head << element(:ofoot,{}, '\\pagemark/\\ref{TotPages}').cr
410
+ pdf.head << element(:ifoot,{}, '\\url{http://www.lickert.net}').cr