docgenerator 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/examples/creole_example_tabular.rb +95 -0
  2. data/examples/docgenerator_example.rb +5 -5
  3. data/lib/creole/creole2doc.rb +28 -18
  4. data/lib/creole/creole_inclusions.rb +4 -4
  5. data/lib/creole/creole_placeholder.rb +4 -1
  6. data/lib/creole/creole_tabular.rb +173 -155
  7. data/lib/creole/plugins/rail.rb +118 -119
  8. data/lib/creole/plugins/struktex.rb +35 -35
  9. data/lib/creole/plugins/todonotes.rb +8 -1
  10. data/lib/docgenerator/attribute.rb +160 -160
  11. data/lib/docgenerator/characters.rb +343 -311
  12. data/lib/docgenerator/css.rb +167 -167
  13. data/lib/docgenerator/document.rb +525 -511
  14. data/lib/docgenerator/element.rb +316 -316
  15. data/lib/docgenerator/element_meta.rb +114 -114
  16. data/lib/docgenerator/elements.rb +19 -9
  17. data/lib/docgenerator/environments.rb +3 -1
  18. data/lib/docgenerator/lists.rb +177 -174
  19. data/lib/docgenerator/packages/hyperref.rb +74 -70
  20. data/lib/docgenerator/packages/multicol.rb +33 -0
  21. data/lib/docgenerator/packages/scrlettr2.rb +152 -151
  22. data/lib/docgenerator/packages/todonotes.rb +1 -1
  23. data/lib/docgenerator/tabular.rb +463 -400
  24. data/lib/docgenerator/templates/docgenerator_template.rb +94 -84
  25. data/lib/docgenerator/templates/docgenerator_template.yaml +75 -15
  26. data/lib/docgenerator.rb +1 -1
  27. data/lib/wiki2doc/wiki2docgenerator.rb +1 -1
  28. data/meta_test_and_doc/build__meta.rb +125 -0
  29. data/meta_test_and_doc/build_doc.rb +333 -0
  30. data/meta_test_and_doc/build_test.rb +251 -0
  31. data/meta_test_and_doc/manpages/attachfile.rb +389 -0
  32. data/meta_test_and_doc/manpages/caption.rb +133 -0
  33. data/meta_test_and_doc/manpages/characters.rb +3738 -0
  34. data/meta_test_and_doc/manpages/elements.rb +6851 -0
  35. data/meta_test_and_doc/manpages/environments.rb +985 -0
  36. data/meta_test_and_doc/manpages/footnote.rb +439 -0
  37. data/meta_test_and_doc/manpages/hyperref.rb +605 -0
  38. data/meta_test_and_doc/manpages/listings.rb +988 -0
  39. data/meta_test_and_doc/manpages/lists.rb +1463 -0
  40. data/meta_test_and_doc/manpages/others.rb +129 -0
  41. data/meta_test_and_doc/manpages/packages.rb +13 -0
  42. data/meta_test_and_doc/manpages/pdfpages.rb +108 -0
  43. data/meta_test_and_doc/manpages/readme.rdoc +9 -0
  44. data/meta_test_and_doc/manpages/scrlettr2.rb +362 -0
  45. data/meta_test_and_doc/manpages/scrpage2.rb +2028 -0
  46. data/meta_test_and_doc/manpages/sectioning.rb +2467 -0
  47. data/meta_test_and_doc/manpages/tables.rb +2088 -0
  48. data/meta_test_and_doc/manpages/todonotes.rb +235 -0
  49. data/meta_test_and_doc/manpages/wiki2docgenerator.rb +64 -0
  50. data/{readme.rd → readme.rdoc} +18 -1
  51. data/unittest/expected/test_tabular.creole +33 -0
  52. data/unittest/expected_creole/test_creole_creole1.0test.html +3 -3
  53. data/unittest/expected_creole/test_creole_creole1.0test.latex +3 -3
  54. data/unittest/expected_creole/test_creole_creole1.0test.text +3 -3
  55. data/unittest/expected_creole/test_creole_inline_apostroph.html +6 -0
  56. data/unittest/expected_creole/test_creole_inline_apostroph.latex +8 -0
  57. data/unittest/expected_creole/test_creole_inline_apostroph.text +4 -0
  58. data/unittest/expected_creole/test_creole_input.normsource +12 -12
  59. data/unittest/expected_creole/test_creole_input.normsource_1.8 +23 -0
  60. data/unittest/expected_creole/test_creole_links_external_implicit.html +2 -2
  61. data/unittest/expected_creole/test_creole_links_external_implicit.latex +2 -2
  62. data/unittest/expected_creole/test_creole_links_external_implicit.text +2 -2
  63. data/unittest/expected_creole/test_creole_links_implicit_end.html +1 -1
  64. data/unittest/expected_creole/test_creole_links_implicit_end.latex +1 -1
  65. data/unittest/expected_creole/test_creole_list_ul.normsource +42 -42
  66. data/unittest/expected_creole/test_creole_list_ul.normsource_1.8 +83 -0
  67. data/unittest/expected_creole/test_creole_paragraphs.normsource +15 -15
  68. data/unittest/expected_creole/test_creole_paragraphs.normsource_1.8 +27 -0
  69. data/unittest/expected_creole/test_creole_tabular.creole +22 -0
  70. data/unittest/expected_creole/test_creole_tabular_creole.creole +19 -0
  71. data/unittest/expected_creole/test_creole_tabular_css.creole +24 -0
  72. data/unittest/expected_creole/test_creole_tabular_multicols.creole +16 -0
  73. data/unittest/expected_creole/test_creole_tabular_multicols.html +14 -0
  74. data/unittest/expected_creole/test_creole_tabular_multicols.latex +16 -0
  75. data/unittest/expected_creole/test_creole_tabular_with_cell_option.creole +21 -0
  76. data/unittest/expected_creole/test_creole_toc_level_text.html +2 -2
  77. data/unittest/expected_creole/test_creole_toc_level_text.latex +2 -2
  78. data/unittest/expected_packages/test_multicol_3.tex +2 -0
  79. data/unittest/expected_packages/test_multicol_3_titleline.tex +2 -0
  80. data/unittest/expected_templates/test_article.tex +23 -0
  81. data/unittest/expected_templates/test_article_utf8.tex +34 -0
  82. data/unittest/expected_templates/test_context.miv +18 -0
  83. data/unittest/expected_templates/test_creole.creole +8 -0
  84. data/unittest/expected_templates/test_html.html +12 -0
  85. data/unittest/expected_templates/test_html401_strict.html +14 -0
  86. data/unittest/expected_templates/test_html401_trans.html +14 -0
  87. data/unittest/expected_templates/test_html_utf8.html +14 -0
  88. data/unittest/expected_templates/test_include.tex +17 -0
  89. data/unittest/expected_templates/test_include_utf8.tex +17 -0
  90. data/unittest/expected_templates/test_text.txt +6 -0
  91. data/unittest/expected_templates/test_wiki.wiki +6 -0
  92. data/unittest/expected_templates/test_xhtml_strict.html +14 -0
  93. data/unittest/expected_templates/test_xhtml_trans.html +14 -0
  94. data/unittest/unittest_creole.rb +27 -6
  95. data/unittest/unittest_creole_placeholders.rb +1 -123
  96. data/unittest/unittest_creole_tabular.rb +174 -0
  97. data/unittest/unittest_docgenerator.rb +4 -3
  98. data/unittest/unittest_docgenerator_characters.rb +4769 -615
  99. data/unittest/unittest_packages_multicol.rb +84 -0
  100. data/unittest/unittest_rubycode4doc.rb +0 -1
  101. data/unittest/unittest_templates.rb +64 -0
  102. metadata +163 -77
  103. data/build_test_and_doc.rb +0 -505
  104. data/manpage_elements.rb +0 -10411
@@ -5,52 +5,52 @@ module Docgenerator
5
5
  =begin rdoc
6
6
  Extension for Log4r::Logger (#INFO)
7
7
  =end
8
- module Logger_INFO
9
- #Print INFO-message, if logging level is WARN
10
- def INFO?()
11
- Log4r::WARN >= self.level
12
- end #INFO?()
8
+ module Logger_INFO
9
+ #Print INFO-message, if logging level is WARN
10
+ def INFO?()
11
+ Log4r::WARN >= self.level
12
+ end #INFO?()
13
13
  =begin rdoc
14
14
  INFO is a *important* information.
15
15
  It's like a warning, but outputted as information.
16
16
  =end
17
- def INFO(*args)
18
- return unless INFO?
19
- level = self.level #remember previous level
20
- self.level = Log4r::INFO #temporary level change
21
- self.info(*args)
22
- self.level = level
23
- end
24
- end
17
+ def INFO(*args)
18
+ return unless INFO?
19
+ level = self.level #remember previous level
20
+ self.level = Log4r::INFO #temporary level change
21
+ self.info(*args)
22
+ self.level = level
23
+ end
24
+ end #Logger_INFO
25
25
  =begin rdoc
26
26
  Container for a document.
27
27
 
28
28
  Each document contains a header and a body. Both are special Element classes.
29
29
  =end
30
- class Document
31
- include Docgenerator #get VERSION
32
-
33
- #Valid meta tags, used for HTML
34
- #
35
- #This meta-tags are used by sitegenerator
36
- VALID_META_TAGS = %w{
37
- keywords
38
- description
39
- id
40
- altlang
41
- toc
42
- pdf
43
- odp
44
- amazon
45
- forum
46
- feed
47
- }
48
- class << VALID_META_TAGS
49
- # Return true if self is part of the given parameter.
50
- def ===(o)
51
- return self.include?(o)
52
- end
53
- end
30
+ class Document
31
+ include Docgenerator #get VERSION
32
+
33
+ #Valid meta tags, used for HTML
34
+ #
35
+ #This meta-tags are used by sitegenerator
36
+ VALID_META_TAGS = %w{
37
+ keywords
38
+ description
39
+ id
40
+ altlang
41
+ toc
42
+ pdf
43
+ odp
44
+ amazon
45
+ forum
46
+ feed
47
+ }
48
+ class << VALID_META_TAGS
49
+ # Return true if self is part of the given parameter.
50
+ def ===(o)
51
+ return self.include?(o)
52
+ end
53
+ end #class << VALID_META_TAGS
54
54
 
55
55
  =begin rdoc
56
56
  Create a new document.
@@ -60,244 +60,251 @@ The templates refer to the corresponding TeX-classes.
60
60
  - report
61
61
  - book
62
62
  =end
63
- def initialize( settings = {} )
64
- #Set template defaults
65
- @template = {
66
- :html => DocumentTemplate[:html],
67
- :latex => DocumentTemplate[:article],
68
- :text => DocumentTemplate[:text],
69
- :wiki => DocumentTemplate[:wiki],
70
- }
71
- @language = 'ngerman' #default
72
- @date = nil
63
+ def initialize( settings = {} )
64
+ #Set template defaults
65
+ @template = {
66
+ :html => DocumentTemplate[:html],
67
+ :latex => DocumentTemplate[:article],
68
+ :text => DocumentTemplate[:text],
69
+ :wiki => DocumentTemplate[:wiki],
70
+ }
71
+ @language = 'ngerman' #default
72
+ @date = nil
73
73
 
74
- ##>>>>temporary check, old interface
75
- #~ puts settings.inspect
76
- if ! settings.is_a?(Hash)
77
- #Make an exception to correct data
78
- raise "Old interface for Document#new, use :template => "
79
- settings = { :template => settings }
80
- end
81
- ##<<<<temporary check, old interface
82
-
83
- @log = settings[:log]
84
- if ! @log
85
- @log = Log4r::Logger.new( 'Doc', Log4r::WARN )
86
- @log.outputters = Log4r::StdoutOutputter.new('log_xxx')
87
- end
88
- @log.extend(Logger_INFO) unless @log.respond_to?(:INFO)
89
-
90
- @meta = {} #some meta-Tags for HTML
91
- @body = element( :body, { :log => @log } )
92
- @head = element( :head, { :log => @log } )
93
- #~ @body.part_of << self
94
- #~ @head.part_of << self
95
- @options = []
96
- #Flag to avoid double definition of docinfo()
97
- @docinfo_called = false
98
- @creator = nil
74
+ ##>>>>temporary check, old interface
75
+ #~ puts settings.inspect
76
+ if ! settings.is_a?(Hash)
77
+ #Make an exception to correct data
78
+ raise "Old interface for Document#new, use :template => "
79
+ settings = { :template => settings }
80
+ end
81
+ ##<<<<temporary check, old interface
82
+
83
+ @log = settings[:log]
84
+ if ! @log
85
+ @log = Log4r::Logger.new( settings[:logname] || 'Doc', Log4r::WARN )
86
+ @log.outputters = Log4r::StdoutOutputter.new('log_xxx')
87
+ end
88
+ @log.extend(Logger_INFO) unless @log.respond_to?(:INFO)
89
+
90
+ @meta = {} #some meta-Tags for HTML
91
+ @body = element( :body, { :log => @log } )
92
+ @head = element( :head, { :log => @log } )
93
+ #~ @body.part_of << self
94
+ #~ @head.part_of << self
95
+ @options = []
96
+ #Flag to avoid double definition of docinfo()
97
+ @docinfo_called = false
98
+ @creator = nil
99
99
 
100
- settings.each{|key, value|
101
- case key
102
- when :title, :shorttitle, :author, :date, :keywords, :description, :creator, :language
103
- self.send("#{key}=".to_sym, value)
104
- #~ when :odp, :pdf, :amazon #VALID_META_TAGS
105
- when *VALID_META_TAGS.map{|mkey|mkey.to_sym}
106
- self.meta( key, value )
107
- when :template
108
- [value].flatten.each{|template|
109
- case template
110
- when DocumentTemplate
111
- @template[template.target] = template
112
- when Symbol
113
- templ = DocumentTemplate[template]
114
- if ! templ.is_a?( DocumentTemplate )
115
- @log.fatal("Unknown template #{template}, valid:\n\t#{DocumentTemplate.keys.join("\n\t")}") if @log.fatal?
116
- else
117
- @template[templ.target] = templ
118
- end
119
- end
120
- } #templates
121
- when :css
122
- if ! File.exist?(value)
123
- @log.warn("CSS-Reference not found (#{value})") if @log.warn?
124
- end
125
- #~ @head << element(:htmlonly,{}, <<css
126
- #~ <meta http-equiv="Content-Style-Type" content="text/css">
127
- #~ css
128
- #~ <link rel="stylesheet" type="text/css" href="#{value}">
129
- #~ ).cr
130
- @head << element( :link, {
131
- :href => value,
132
- :rel => 'stylesheet',
133
- :type => "text/css" } ).cr. restrict_to(:html)
134
- when :maketitle
135
- #:maketitle is defined, but we have also to check, if it is true
136
- @body << element(:maketitle ).cr if settings[key]
137
- when :log
138
- else
139
- @log.warn("Document.new: Unknown setting #{key.inspect} (=#{value.inspect})") if @log.warn?
100
+ settings.each{|key, value|
101
+ case key
102
+ when :title, :shorttitle, :author, :date, :keywords, :description, :creator, :language
103
+ self.send("#{key}=".to_sym, value)
104
+ #~ when :odp, :pdf, :amazon #VALID_META_TAGS
105
+ when *VALID_META_TAGS.map{|mkey|mkey.to_sym}
106
+ self.meta( key, value )
107
+ when :template
108
+ [value].flatten.each{|template|
109
+ case template
110
+ when DocumentTemplate
111
+ @template[template.target] = template
112
+ when Symbol
113
+ templ = DocumentTemplate[template]
114
+ if ! templ.is_a?( DocumentTemplate )
115
+ @log.fatal("Unknown template #{template}, valid:\n\t#{DocumentTemplate.keys.join("\n\t")}") if @log.fatal?
116
+ else
117
+ @template[templ.target] = templ
118
+ end
119
+ end
120
+ } #templates
121
+ when :css
122
+ if ! File.exist?(value)
123
+ @log.warn("CSS-Reference not found (#{value})") if @log.warn?
124
+ end
125
+ #~ @head << element(:htmlonly,{}, <<css
126
+ #~ <meta http-equiv="Content-Style-Type" content="text/css">
127
+ #~ css
128
+ #~ <link rel="stylesheet" type="text/css" href="#{value}">
129
+ #~ ).cr
130
+ @head << element( :link, {
131
+ :href => value,
132
+ :rel => 'stylesheet',
133
+ :type => "text/css" } ).cr. restrict_to(:html)
134
+ when :maketitle
135
+ #:maketitle is defined, but we have also to check, if it is true
136
+ @body << element(:maketitle ).cr if settings[key]
137
+ when :latex_options
138
+ add_option(value)
139
+ when :log
140
+ else
141
+ @log.warn("Document.new: Unknown setting #{key.inspect} (=#{value.inspect})") if @log.warn?
142
+ end
143
+ } #settings
144
+
145
+ if @template[:html].encoding.name == 'UTF-8'
146
+ @head << element(:htmlonly,{},'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">').Cr
140
147
  end
141
- } #settings
142
148
 
143
- end
144
- #body and head are lists, containing elements.
145
- attr_reader :body, :head
146
- attr_reader :template
147
- #Logger for the document
148
- attr_reader :log
149
- #Document title
150
- attr_accessor :title, :shorttitle
151
- #Set document description
152
- attr_writer :author, :date, :keywords, :description, :creator
153
- attr_writer :language
154
- #Flag, if tex should be started immediate after document creation.
155
- attr_writer :runtex
156
- #Add more keywords
157
- def keyword_add( keyword )
158
- @keywords << ", #{keyword}"
159
- end
149
+ end
150
+ #body and head are lists, containing elements.
151
+ attr_reader :body, :head
152
+ attr_reader :template
153
+ #Logger for the document
154
+ attr_reader :log
155
+ #Document title
156
+ attr_accessor :title, :shorttitle
157
+ #Set document description
158
+ attr_writer :author, :date, :keywords, :description, :creator
159
+ attr_writer :language
160
+ #Flag, if tex should be started immediate after document creation.
161
+ attr_writer :runtex
162
+ #Add more keywords
163
+ def keyword_add( keyword )
164
+ @keywords << ", #{keyword}"
165
+ end
160
166
 
161
- #Constant to detect the generated header
162
- PREFIX_ENDFLAG = 'Generation-Info-End'
163
- #
164
- #Define, if there should be a message in case of:
165
- #-:change Document changed
166
- #-:nochange Document existed, but is unchanged
167
- #Please provide an array with the wanted values.
168
- def Document.givemessage=( value = [:change, :nochange] )
169
- @@givemessage = value
170
- end
171
- @@givemessage = [:change, :nochange]
172
- def Document.givemessage(); @@givemessage; end
167
+ #Constant to detect the generated header
168
+ PREFIX_ENDFLAG = 'Generation-Info-End'
169
+ #
170
+ #Define, if there should be a message in case of:
171
+ #-:change Document changed
172
+ #-:nochange Document existed, but is unchanged
173
+ #Please provide an array with the wanted values.
174
+ def Document.givemessage=( value = [:change, :nochange] )
175
+ @@givemessage = value
176
+ end
177
+ @@givemessage = [:change, :nochange]
178
+ def Document.givemessage(); @@givemessage; end
173
179
  =begin rdoc
174
180
  Add a meta-tag-information for the HTML-Output.
175
181
  =end
176
- def meta( key, content )
177
- key = key.to_s
178
-
179
- if ! VALID_META_TAGS.include?(key)
180
- @log.warn("Unknown meta-tag #{key} (#{content})") if @log.warn?
181
- @log.info("\tAllowed meta-tags: #{VALID_META_TAGS.join(', ')}") if @log.info?
182
+ def meta( key, content )
183
+ key = key.to_s
184
+
185
+ if ! VALID_META_TAGS.include?(key)
186
+ @log.warn("Unknown meta-tag #{key} (#{content})") if @log.warn?
187
+ @log.info("\tAllowed meta-tags: #{VALID_META_TAGS.join(', ')}") if @log.info?
188
+ end
189
+ if @meta[key]
190
+ @log.warn("Double definition meta-tag #{key} (old: #{@meta[key]}, new: #{content})") if @log.warn? and @meta[key] != content
191
+ end
192
+
193
+ @meta[key] = content
182
194
  end
183
- if @meta[key]
184
- @log.warn("Double definition meta-tag #{key} (old: #{@meta[key]}, new: #{content})") if @log.warn? and @meta[key] != content
195
+ #Prepare the docinfo.
196
+ #May be called only once.
197
+ #
198
+ #If the title should change (e.g. when you save the document twice in different versions)
199
+ #you can do it via the parameter.
200
+ def docinfo()
201
+ #If this method is called twice (e.g. with save to tex and html),
202
+ #then the title is doubled in the second output.
203
+ #(Elements are added to @head)
204
+ return nil if @docinfo_called
205
+ @docinfo_called = true
206
+
207
+ #Build docinfo.
208
+ result = []
209
+ result << element( :title, {:short => shorttitle }, @title).CR if @title
210
+ result << element( :author, {}, @author).cr if @author
211
+ result << element( :date, {}, @date).cr if @date
212
+ result << element( :keywords, {}, @keywords).cr if @keywords
213
+ result << element( :metadescription, {}, @description).cr if @description
214
+ result << element( :creator, {}, @creator).cr if @creator
215
+ @meta.each{ |key, content|
216
+ result << element( :meta, { :name => key, :content => content } ).cr
217
+ }
218
+ return result
185
219
  end
186
-
187
- @meta[key] = content
188
- end
189
- #Prepare the docinfo.
190
- #May be called only once.
191
- #
192
- #If the title should change (e.g. when you save the document twice in different versions)
193
- #you can do it via the parameter.
194
- def docinfo()
195
- #If this method is called twice (e.g. with save to tex and html),
196
- #then the title is doubled in the second output.
197
- #(Elements are added to @head)
198
- return nil if @docinfo_called
199
- @docinfo_called = true
200
-
201
- #Build docinfo.
202
- result = []
203
- result << element( :title, {:short => shorttitle }, @title).CR if @title
204
- result << element( :author, {}, @author).cr if @author
205
- result << element( :date, {}, @date).cr if @date
206
- result << element( :keywords, {}, @keywords).cr if @keywords
207
- result << element( :metadescription, {}, @description).cr if @description
208
- result << element( :creator, {}, @creator).cr if @creator
209
- @meta.each{ |key, content|
210
- result << element( :meta, { :name => key, :content => content } ).cr
211
- }
212
- return result
213
- end
214
- def add_option( option)
215
- @options << option
216
- end
217
- #Prepare a table of content.
218
- #
219
- #There is no sense to use it with LaTeX, better you use \tableofcontents
220
- #
221
- #Options:
222
- #- id: Id of div, needed for CSS-formatting
223
- #- tocfilename: Added as prefix to link.
224
- # can be used to make toc for in another file (cross-referencing)
225
- #- level: Depth of toc
226
- #The document should be filled before you add the toc.
227
- #You an use Element#insertbefore:
228
- # doc.body.insertbefore(start, doc.toc)
229
- def toc( options = {} )
230
- opt = {
231
- :id => 'toc',
232
- :tocfilename => nil, #Can be used to build cross references
233
- :level => 3,
234
- :log => @log
235
- }.update(options)
236
-
237
- opt[:level] = 3 unless opt[:level]
238
- opt[:log].info("Prepare Table of contents, options: #{options.keys.inspect}") if opt[:log].info?
239
- opt[:log].debug("Options: #{[:id, :level, :tocfilename].map{|k| "#{k}: #{opt[k].inspect}"}.join(',')}") if opt[:log].debug?
240
-
241
- toc = element(:div, { :id => opt[:id] }).cR
242
- opt[:pre].is_a?(String) ? toc << element(:p, {}, opt[:pre] ).cr : toc << opt[:pre]
243
-
244
- toc_uls = [ toc ]
220
+ #Add an class option for LaTeX
221
+ def add_option( *options)
222
+ options.each{|option| @options << option }
223
+ end
224
+ #Prepare a table of content.
225
+ #
226
+ #There is no sense to use it with LaTeX, better you use \tableofcontents
227
+ #
228
+ #Options:
229
+ #- id: Id of div, needed for CSS-formatting
230
+ #- tocfilename: Added as prefix to link.
231
+ # can be used to make toc for in another file (cross-referencing)
232
+ #- level: Depth of toc
233
+ #The document should be filled before you add the toc.
234
+ #You an use Element#insertbefore:
235
+ # doc.body.insertbefore(start, doc.toc)
236
+ def toc( options = {} )
237
+ opt = {
238
+ :id => 'toc',
239
+ :tocfilename => nil, #Can be used to build cross references
240
+ :level => 3,
241
+ :log => @log
242
+ }.update(options)
245
243
 
246
- #fixme
247
- #It would be nicer to get something like 1-1-1 instead of a counter.
248
- toccnt = 0
249
- toc_ids = [ :chapter, :section,:subsection, :subsubsection, :paragraph, :subparagraph,:minisec]
250
- @body.content.flatten.each{|el|
251
- if ! el.respond_to?(:element_ids)
252
- #e.g. Wikitext. Has a to_doc, but doesn't react on flatten.
253
- opt[:log].error("Toc: Element without ids #{el.class}") if opt[:log].error?
254
- next
255
- end
256
- #Get section depth. Determine it via the position inside toc_ids.
257
- depth = toc_ids.index((el.element_ids & toc_ids)[0])
258
- next if ! depth #Element is no header
244
+ opt[:level] = 3 unless opt[:level]
245
+ opt[:log].info("Prepare Table of contents, options: #{options.keys.inspect}") if opt[:log].info?
246
+ opt[:log].debug("Options: #{[:id, :level, :tocfilename].map{|k| "#{k}: #{opt[k].inspect}"}.join(',')}") if opt[:log].debug?
259
247
 
260
- opt[:log].debug("Toc: Found entry on level #{depth}: <#{el.content}>") if opt[:log].debug?
261
- #Create an id if not already defined
262
- if el[:id].content.empty?
263
- el[:id] << "toc#{toccnt += 1}"
264
- end
265
- if depth > opt[:level]
266
- opt[:log].debug("Toc: Reject by level #{el.content}") if opt[:log].debug?
267
- next
268
- end
248
+ toc = element(:div, { :id => opt[:id] }).cR
249
+ opt[:pre].is_a?(String) ? toc << element(:p, {}, opt[:pre] ).cr : toc << opt[:pre]
250
+
251
+ toc_uls = [ toc ]
269
252
 
270
- #Check missing levels
271
- (depth - toc_uls.size).times{|i|
272
- opt[:log].warn("Toc: Jump over section level #{depth-1+i} (#{opt[:tocfilename]})") if opt[:log].warn?
273
- toc_uls << element(:ul, {}, element(:li ).cr ).cR
274
- if toc_uls.size == 2 #First entry
275
- toc_uls.first << toc_uls.last
276
- else
277
- toc_uls[-2].content.last << toc_uls.last
253
+ #fixme
254
+ #It would be nicer to get something like 1-1-1 instead of a counter.
255
+ toccnt = 0
256
+ toc_ids = [ :chapter, :section,:subsection, :subsubsection, :paragraph, :subparagraph,:minisec]
257
+ @body.content.flatten.each{|el|
258
+ if ! el.respond_to?(:element_ids)
259
+ #e.g. Wikitext. Has a to_doc, but doesn't react on flatten.
260
+ opt[:log].error("Toc: Element without ids #{el.class}") if opt[:log].error?
261
+ next
262
+ end
263
+ #Get section depth. Determine it via the position inside toc_ids.
264
+ depth = toc_ids.index((el.element_ids & toc_ids)[0])
265
+ next if ! depth #Element is no header
266
+
267
+ opt[:log].debug("Toc: Found entry on level #{depth}: <#{el.content}>") if opt[:log].debug?
268
+ #Create an id if not already defined
269
+ if el[:id].content.empty?
270
+ el[:id] << "toc#{toccnt += 1}"
278
271
  end
279
- }
280
-
281
- #Build new toc-list and deletet bigger ones
282
- if ! toc_uls[depth]
283
- opt[:log].debug("Toc: Start new level #{depth}") if opt[:log].debug?
284
- toc_uls << element(:ul).cR
285
- if depth == 1
286
- toc << toc_uls[depth]
287
- else
288
- toc_uls[depth -1 ].content.last << toc_uls[depth]
272
+ if depth > opt[:level]
273
+ opt[:log].debug("Toc: Reject by level #{el.content}") if opt[:log].debug?
274
+ next
289
275
  end
290
- else #delete levels under actual level
291
- if toc_uls.slice!(depth+1..toc_uls.size+1)
292
- opt[:log].debug("Toc: Stop level > #{depth}") if opt[:log].debug?
276
+
277
+ #Check missing levels
278
+ (depth - toc_uls.size).times{|i|
279
+ opt[:log].warn("Toc: Jump over section level #{depth-1+i} (#{opt[:tocfilename]})") if opt[:log].warn?
280
+ toc_uls << element(:ul, {}, element(:li ).cr ).cR
281
+ if toc_uls.size == 2 #First entry
282
+ toc_uls.first << toc_uls.last
283
+ else
284
+ toc_uls[-2].content.last << toc_uls.last
285
+ end
286
+ }
287
+
288
+ #Build new toc-list and deletet bigger ones
289
+ if ! toc_uls[depth]
290
+ opt[:log].debug("Toc: Start new level #{depth}") if opt[:log].debug?
291
+ toc_uls << element(:ul).cR
292
+ if depth == 1
293
+ toc << toc_uls[depth]
294
+ else
295
+ toc_uls[depth -1 ].content.last << toc_uls[depth]
296
+ end
297
+ else #delete levels under actual level
298
+ if toc_uls.slice!(depth+1..toc_uls.size+1)
299
+ opt[:log].debug("Toc: Stop level > #{depth}") if opt[:log].debug?
300
+ end
293
301
  end
294
- end
295
- toc_uls[depth] << element(:li, {}, element(:a, {:href => "#{opt[:tocfilename]}##{el[:id]}" }, el.content ) ).cr
296
- }
297
- opt[:post].is_a?(String) ? toc << element(:p, {}, opt[:post] ).cr : toc << opt[:post]
298
-
299
- return toc
300
- end #toc
302
+ toc_uls[depth] << element(:li, {}, element(:a, {:href => "#{opt[:tocfilename]}##{el[:id]}" }, el.content ) ).cr
303
+ }
304
+ opt[:post].is_a?(String) ? toc << element(:p, {}, opt[:post] ).cr : toc << opt[:post]
305
+
306
+ return toc
307
+ end #toc
301
308
  =begin rdoc
302
309
  Save the file.
303
310
  The type of the document is determined by the file extensison.
@@ -327,151 +334,151 @@ Valid options:
327
334
  If you want to give parameters to specific 'Element'-objects you can define the keys here.
328
335
  If you don't make it, you get warnings about undefined options.
329
336
  =end
330
- def save( filename, options = {} )
331
- #check old interface before 1.1.0
332
- case options
333
- when true, false
334
- @log.warn( "Old interface for Document.save, use :overwrite => true/false" ) if @log.error?
335
- options = { :overwrite => options }
336
- end
337
+ def save( filename, options = {} )
338
+ #check old interface before 1.1.0
339
+ case options
340
+ when true, false
341
+ @log.warn( "Old interface for Document.save, use :overwrite => true/false" ) if @log.error?
342
+ options = { :overwrite => options }
343
+ end
344
+
345
+ options = {
346
+ :overwrite => true,
347
+ :replacements => {} ,
348
+ :additional_options => [],
349
+ :target => nil, #Will be set by extension
350
+ :runtex => @runtex,
351
+ }.update(options)
337
352
 
338
- options = {
339
- :overwrite => true,
340
- :replacements => {} ,
341
- :additional_options => [],
342
- :target => nil, #Will be set by extension
343
- :runtex => @runtex,
344
- }.update(options)
345
-
346
- #Check valid options
347
- options.each{|key,value|
348
- case key
349
- when :overwrite, :replacements, :target
350
- when :additional_options
351
- else
352
- if options[:additional_options].include?(key)
353
- @log.warn( "unknown option #{key.inspect} for Document.save" ) if @log.warn?
353
+ #Check valid options
354
+ options.each{|key,value|
355
+ case key
356
+ when :overwrite, :replacements, :target
357
+ when :additional_options
354
358
  else
355
- @log.debug( "Save-Specific option #{key.inspect} in Document.save" ) if @log.debug?
356
- end
357
- end
358
- }
359
-
360
- if ! @template
361
- @log.error( "No template available to create #{filename}" ) if @log.error?
362
- return false
363
- end
364
-
365
-
366
- prefix = [ nil,
367
- "Build by\t#{__FILE__}",
368
- "Dir:\t\t#{Dir.pwd}",
369
- "Creator:\tDocgenerator #{Docgenerator::VERSION} - http://rubygems.org/gems/docgenerator",
370
- "Target:\t\t#{filename}",
371
- "#{Time.now.strftime('%Y/%m/%d %H:%M:%S')}",
372
- nil,
373
- "#{PREFIX_ENDFLAG}"
374
- ].join("\n\t")
375
-
376
- #Determine the target document type, depending on extension.
377
- extension = File.basename( filename ).split( /\./).last
378
- case extension
379
- when /tex/i
380
- target = :latex
381
- #Take context if requested.
382
- target = :context if options[:target] == :context
383
- when /mk(ii|iv)/i #Mark II and IV
384
- target = :context
385
- when /htm[l]?/i
386
- target = :html
387
- when /txt/
388
- target = :text
389
- when /wiki/
390
- target = :wiki
391
- target = :creole if options[:target] == :creole
392
- when /creole/
393
- target = :creole
394
- else
395
- @log.fatal( "Unknown Extension #{extension} for #{File.basename( filename )}" ) if @log.fatal?
396
- raise "Unknown Extension #{extension}"
397
- end
398
-
399
- #Check if the wanted target makes sense
400
- case options[:target]
401
- when nil #nothing predefined -> no check necessary
402
- when target #Same as determined by extension -> no check necessary
403
- else #Requested target is another one.
404
- @log.warn( "Target #{options[:target]} doesn't match extension. Recommended: #{target}" ) if @log.warn?
405
- target = options[:target]
406
- end
407
-
408
- #Create new version.
409
- new = to_doc( target, {
410
- :template=> @template[target],
411
- :filename => filename,
412
- :replacements => options[:replacements],
413
- :log => @log
414
- })
415
- #Get previous content if available
416
- old = nil
417
- if File.exist?( filename )
418
- #read the file. We expect to have the same encoding.
419
- File.open(filename, 'r', :external_encoding => new.encoding){|f| old = f.read }
420
- old = File.read(filename) unless old.valid_encoding? #
421
- end
422
- prefix.encode!(new.encoding) #for later sub...
423
- case target
424
- when :latex, :context
425
- prefix.gsub!( /^/, '%' )
426
- old.sub!(/\A.*#{PREFIX_ENDFLAG}/m, '<<prefix>>' ) if old
427
- when :html
428
- #Delete prefix (with generation time) for later compare.
429
- old.sub!(/\A.*#{PREFIX_ENDFLAG}/m, "<!--\n<<prefix>>" ) if old
430
- when :text
431
- when :wiki
432
- when :creole
433
- #~ new.squeeze!("\n")
434
- else
435
- @log.fatal( "Unknown target #{target} for #{File.basename( filename )}" ) if @log.fatal?
436
- raise "Unknown target #{target}"
437
- end
438
- #Make it a bit more compact.
439
- #TeX requires at least 2 \n for paragraph changes
440
- new.gsub!(/\n+\n\n/, "\n\n")
441
-
442
- if ! new.kind_of?( String )
443
- @log.error( "New is wrong type: #{new.inspect}" ) if @log.error?
444
- end
445
-
446
- if new != old
447
- new.sub!( '<<prefix>>', prefix)
448
- if ( File.exist?( filename ) and ! options[:overwrite] )
449
- @log.warn("Datei #{filename} exist already.") if @log.warn?
450
- if $stdin.tty? #only when called in a shell
451
- puts "Datei #{filename} exist already \nContinue [yn]?"
452
- answer = $stdin.gets()
453
- if ! ( answer =~ /[YyjJ].*/ )
454
- puts "Bye"
455
- return false
456
- end
359
+ if options[:additional_options].include?(key)
360
+ @log.warn( "unknown option #{key.inspect} for Document.save" ) if @log.warn?
361
+ else
362
+ @log.debug( "Save-Specific option #{key.inspect} in Document.save" ) if @log.debug?
363
+ end
457
364
  end
458
- @log.info( "Overwrite #{filename} after confirmation" ) if @log.info?
459
- end
460
- File.open( filename, 'w', :external_encoding => new.encoding ){|f|
461
- f << new
462
365
  }
463
- @log.INFO( "Save changed\t#{filename}") if @log.INFO?
464
- #Save copy of old version (attention, *.bak makes no control on tex or html)
465
- #~ f = File.new( filename.sub( extension, 'bak'), 'w' )
466
- #~ f << old
467
- #~ f.close
468
- Document.runtex( filename, options[:runtex] ) if options[:runtex] and [:latex, :context].include?(target)
469
- return true
470
- elsif old
471
- @log.INFO("Unchanged\t#{filename}") if @log.INFO?
472
- return false
473
- end
474
- end #Document#save
366
+
367
+ if ! @template
368
+ @log.error( "No template available to create #{filename}" ) if @log.error?
369
+ return false
370
+ end
371
+
372
+
373
+ prefix = [ nil,
374
+ "Build by\t#{__FILE__}",
375
+ "Dir:\t\t#{Dir.pwd}",
376
+ "Creator:\tDocgenerator #{Docgenerator::VERSION} - http://rubygems.org/gems/docgenerator",
377
+ "Target:\t\t#{filename}",
378
+ "#{Time.now.strftime('%Y/%m/%d %H:%M:%S')}",
379
+ nil,
380
+ "#{PREFIX_ENDFLAG}"
381
+ ].join("\n\t")
382
+
383
+ #Determine the target document type, depending on extension.
384
+ extension = File.basename( filename ).split( /\./).last
385
+ case extension
386
+ when /tex/i
387
+ target = :latex
388
+ #Take context if requested.
389
+ target = :context if options[:target] == :context
390
+ when /mk(ii|iv)/i #Mark II and IV
391
+ target = :context
392
+ when /htm[l]?/i
393
+ target = :html
394
+ when /txt/
395
+ target = :text
396
+ when /wiki/
397
+ target = :wiki
398
+ target = :creole if options[:target] == :creole
399
+ when /creole/
400
+ target = :creole
401
+ else
402
+ @log.fatal( "Unknown Extension #{extension} for #{File.basename( filename )}" ) if @log.fatal?
403
+ raise "Unknown Extension #{extension}"
404
+ end
405
+
406
+ #Check if the wanted target makes sense
407
+ case options[:target]
408
+ when nil #nothing predefined -> no check necessary
409
+ when target #Same as determined by extension -> no check necessary
410
+ else #Requested target is another one.
411
+ @log.warn( "Target #{options[:target]} doesn't match extension. Recommended: #{target}" ) if @log.warn?
412
+ target = options[:target]
413
+ end
414
+
415
+ #Create new version.
416
+ new = to_doc( target, {
417
+ :template=> @template[target],
418
+ :filename => filename,
419
+ :replacements => options[:replacements],
420
+ :log => @log
421
+ })
422
+ #Get previous content if available
423
+ old = nil
424
+ if File.exist?( filename )
425
+ #read the file. We expect to have the same encoding.
426
+ File.open(filename, 'r', :external_encoding => new.encoding){|f| old = f.read }
427
+ old = File.read(filename) unless old.valid_encoding? #
428
+ end
429
+ prefix.encode!(new.encoding) #for later sub...
430
+ case target
431
+ when :latex, :context
432
+ prefix.gsub!( /^/, '%' )
433
+ old.sub!(/\A.*#{PREFIX_ENDFLAG}/m, '<<prefix>>' ) if old
434
+ when :html
435
+ #Delete prefix (with generation time) for later compare.
436
+ old.sub!(/\A.*#{PREFIX_ENDFLAG}/m, "<!--\n<<prefix>>" ) if old
437
+ when :text
438
+ when :wiki
439
+ when :creole
440
+ #~ new.squeeze!("\n")
441
+ else
442
+ @log.fatal( "Unknown target #{target} for #{File.basename( filename )}" ) if @log.fatal?
443
+ raise "Unknown target #{target}"
444
+ end
445
+ #Make it a bit more compact.
446
+ #TeX requires at least 2 \n for paragraph changes
447
+ new.gsub!(/\n+\n\n/, "\n\n")
448
+
449
+ if ! new.kind_of?( String )
450
+ @log.error( "New is wrong type: #{new.inspect}" ) if @log.error?
451
+ end
452
+
453
+ if new != old
454
+ new.sub!( '<<prefix>>', prefix)
455
+ if ( File.exist?( filename ) and ! options[:overwrite] )
456
+ @log.warn("Datei #{filename} exist already.") if @log.warn?
457
+ if $stdin.tty? #only when called in a shell
458
+ puts "Datei #{filename} exist already \nContinue [yn]?"
459
+ answer = $stdin.gets()
460
+ if ! ( answer =~ /[YyjJ].*/ )
461
+ puts "Bye"
462
+ return false
463
+ end
464
+ end
465
+ @log.info( "Overwrite #{filename} after confirmation" ) if @log.info?
466
+ end
467
+ File.open( filename, 'w', :external_encoding => new.encoding ){|f|
468
+ f << new
469
+ }
470
+ @log.INFO( "Save changed\t#{filename}") if @log.INFO?
471
+ #Save copy of old version (attention, *.bak makes no control on tex or html)
472
+ #~ f = File.new( filename.sub( extension, 'bak'), 'w' )
473
+ #~ f << old
474
+ #~ f.close
475
+ Document.runtex( filename, options[:runtex] ) if options[:runtex] and [:latex, :context].include?(target)
476
+ return true
477
+ elsif old
478
+ @log.INFO("Unchanged\t#{filename}") if @log.INFO?
479
+ return false
480
+ end
481
+ end #Document#save
475
482
  =begin rdoc
476
483
  Build the content of a document for the target format.
477
484
 
@@ -505,71 +512,75 @@ If the method is called directly to prepare document snipplets, you can use:
505
512
  )
506
513
 
507
514
  =end
508
- def to_doc( target, options )
509
- #~ o = set_option_defaults(options)
510
- options[:log].info( "Build document for #{target.inspect}" ) if options[:log].info?
515
+ def to_doc( target, options )
516
+ #~ o = set_option_defaults(options)
517
+ options[:log].info( "Build document for #{target.inspect}" ) if options[:log].info?
511
518
 
512
- #check target
513
- case target
514
- when :latex
515
- add_option( @language )
516
- when :context
517
- options[:log].warn( "Support for #{target} under development" ) if options[:log].warn?
518
- when :html
519
- when :text
520
- when :wiki
521
- options[:log].warn( "Support for #{target} stopped" ) if options[:log].warn?
522
- when :creole
523
- options[:log].warn( "Support for #{target} under development" ) if options[:log].warn?
524
- else
525
- options[:log].fatal( "Unknown target #{target} for #{options[:filename]}" ) if options[:log].fatal?
526
- return ''
527
- end
528
-
529
- #set template to variable new
530
- case options[:template]
531
- when DocumentTemplate
532
- new = options[:template].template
533
- when String
534
- new = options[:template]
519
+ #check target
520
+ case target
521
+ when :latex
522
+ add_option( @language )
523
+ when :context
524
+ options[:log].warn( "Support for #{target} under development" ) if options[:log].warn?
525
+ when :html
526
+ when :text
527
+ when :wiki
528
+ options[:log].warn( "Support for #{target} stopped" ) if options[:log].warn?
529
+ when :creole
530
+ options[:log].warn( "Support for #{target} under development" ) if options[:log].warn?
535
531
  else
536
- options[:log].error( "No template available to create #{target.inspect} #{self.class}" ) if options[:log].error?
532
+ options[:log].fatal( "Unknown target #{target} for #{options[:filename]}" ) if options[:log].fatal?
537
533
  return ''
538
- end
539
- if ! new.kind_of?( String )
540
- options[:log].fatal( "New is wrong type: #{new.inspect}") if options[:log].fatal?
541
- return ''
542
- end
543
- encoding = new.encoding
534
+ end
535
+
536
+ #set template to variable new
537
+ case options[:template]
538
+ when DocumentTemplate
539
+ new = options[:template].template
540
+ when String
541
+ new = options[:template]
542
+ else
543
+ options[:log].error( "No template available to create #{target.inspect} #{self.class}" ) if options[:log].error?
544
+ return ''
545
+ end
546
+ if ! new.kind_of?( String )
547
+ options[:log].fatal( "New is wrong type: #{new.inspect}") if options[:log].fatal?
548
+ return ''
549
+ end
550
+ encoding = new.encoding
544
551
 
545
- #Set replacements
546
- replacements = options[:replacements] || {}
552
+ #Set replacements
553
+ replacements = options[:replacements] || {}
547
554
 
548
- options[:document] = self
549
-
550
- @head << self.docinfo()
551
- options[:log].debug( "Build header data") if options[:log].debug?
552
- new.sub!( '<<head>>', @head.to_doc(target, options ).encode(encoding))
553
-
554
- options[:log].debug( "Build body") if options[:log].debug?
555
- new.sub!( '<<body>>', @body.to_doc(target, options).encode(encoding))
556
-
557
- new.sub!( '<<classoptions>>', @options.uniq.join(',').encode(encoding))
558
-
559
- #manipulate result
560
- replacements.each{|pattern, replace |
561
- options[:log].info("Replace text #{pattern.source} with #{replace}" ) if options[:log].info?
562
- new.gsub!( pattern, replace ) if replace
563
- }
564
- return new
565
- end #Document#to_doc
555
+ options[:document] = self
556
+
557
+ @head << self.docinfo()
558
+ options[:log].debug( "Build header data") if options[:log].debug?
559
+ new.sub!( '<<head>>', @head.to_doc(target, options ).encode(encoding))
560
+
561
+ options[:log].debug( "Build body") if options[:log].debug?
562
+ new.sub!( '<<body>>', @body.to_doc(target, options).encode(encoding))
563
+
564
+ new.sub!( '<<classoptions>>', @options.uniq.join(',').encode(encoding))
565
+
566
+ #manipulate result
567
+ replacements.each{|pattern, replace |
568
+ options[:log].info("Replace text #{pattern.source} with #{replace}" ) if options[:log].info?
569
+ new.gsub!( pattern, replace ) if replace
570
+ }
571
+ return new
572
+ end #Document#to_doc
566
573
 
574
+ #
575
+ #Eigenclass Document
576
+ class << self
577
+ include Rake::DSL if defined? Rake::DSL #needed for task generation
567
578
  =begin rdoc
568
579
  Call rake4latex to translate the file.
569
580
  =end
570
- def Document.runtex( filename, options = [:touch, :statistic, :clean])
571
- if ! defined? Rake4LaTeX
572
- puts <<warning
581
+ def runtex( filename, options = [:touch, :statistic, :clean])
582
+ if ! defined? Rake4LaTeX
583
+ puts <<warning
573
584
  Rake4LaTeX not loaded!
574
585
  Please use one of the following commands:
575
586
  require 'rake4latex'
@@ -583,45 +594,47 @@ Please use one of the following commands:
583
594
  #:runtex => [:touch, :texerrors_allowed, :statistic, :clean]
584
595
  )
585
596
  warning
586
- begin
587
- #interprete old interface before 1.2.0
588
- gem 'rake4latex', '>= 0.1.2'
597
+ begin
598
+ #interprete old interface before 1.2.0
599
+ gem 'rake4latex', '>= 0.1.3'
600
+ case options
601
+ when :latex; require 'rake4latex_latex'
602
+ when :pdflatex; require 'rake4latex_pdflatex'
603
+ when :xelatex; require 'rake4latex_xelatex'
604
+ else; require 'rake4latex'
605
+ end #format
606
+ options = [:touch, :statistic, :clean]
607
+ rescue LoadError
608
+ puts "Sorry, I didn't find the rake4latex to translate #{filename}"
609
+ return false
610
+ end unless defined? Rake4LaTeX
611
+ end # ! defined? Rake4LaTeX
612
+
589
613
  case options
590
- when :latex; require 'rake4latex_latex'
591
- when :pdflatex; require 'rake4latex_pdflatex'
592
- when :xelatex; require 'rake4latex_xelatex'
593
- else; require 'rake4latex'
594
- end #format
595
- options = [:touch, :statistic, :clean]
596
- rescue LoadError
597
- puts "Sorry, I didn't find the rake4latex to translate #{filename}"
598
- return false
599
- end unless defined? Rake4LaTeX
600
- end # ! defined? Rake4LaTeX
601
-
602
- case options
603
- when Array #ok
604
- when true; options = [:touch, :statistic, :clean]
605
- else
606
- options = [:touch, :statistic, :clean]
607
- puts "Please change runtex-options to: #{options.inspect}"
608
- end
609
- #Taskname must be uniq for this file.
610
- runtex = "Define TeX-task #{filename.ext('pdf')}"
611
- rake4latex = Rake4LaTeX::Basefile.set(filename)#needed for clean...
612
- rake4latex [:texerrors_allowed] = true if options.delete(:texerrors_allowed)
613
- rake4latex[:loglevel] = Log4r::WARN
614
-
615
- if options.delete(:touch)
616
- task :touch => filename.ext('tex')
617
- task runtex => :touch
618
- end #if options.delete(:touch)
619
- task runtex => filename.ext('pdf')
620
- task runtex => options
621
-
622
- Rake.application[runtex].invoke
623
- options.each{|option| Rake.application[option].reenable }
624
- end
614
+ when Array #ok
615
+ when true; options = [:touch, :statistic, :clean]
616
+ else
617
+ options = [:touch, :statistic, :clean]
618
+ puts "Please change runtex-options to: #{options.inspect}"
619
+ end #case options
620
+
621
+ extend Rake::DSL if defined? Rake::DSL #needed for task generation
622
+ #Taskname must be uniq for this file.
623
+ runtex = "Define TeX-task #{filename.ext('pdf')}"
624
+ rake4latex = Rake4LaTeX::Basefile.set(filename)#needed for clean...
625
+ rake4latex [:texerrors_allowed] = true if options.delete(:texerrors_allowed)
626
+ rake4latex[:loglevel] = Log4r::WARN
627
+
628
+ if options.delete(:touch)
629
+ task :touch => filename.ext('tex')
630
+ task runtex => :touch
631
+ end #if options.delete(:touch)
632
+ task runtex => filename.ext('pdf')
633
+ task runtex => options
634
+
635
+ Rake.application[runtex].invoke
636
+ options.each{|option| Rake.application[option].reenable }
637
+ end #Document.runtex
625
638
  =begin rdoc
626
639
  Make some basic replacements for TeX.
627
640
  There is no sense to use it with HTML.
@@ -631,21 +644,22 @@ Better solution:
631
644
  * Use unicode in TeX-Document.
632
645
  * Put string into \path, \verb or similar.
633
646
  =end
634
- def Document.texify( input )
635
- out = input.strip
636
-
637
- #~ out.gsub!( /&/, '\\\&') #geht schief. erzeugt <<body>>...
638
- #~ out.gsub!( /\\/, '\\\\')
639
- out.gsub!( /%/, '\%')
640
- out.gsub!( /\$/, '\$')
641
- out.gsub!( /&/, '\\\\&')
642
- out.gsub!( /_/, '\_')
643
- out.gsub!( /#/, '\#')
644
- #~ out.gsub!( /€/, '\euro ') #regexp is in utf-8 -- may make problems.
645
- return out
646
- end
647
- def inspect()
648
- return "#<Document '#{@title}'>"
649
- end
650
- end #Document
647
+ def texify( input )
648
+ out = input.strip
649
+
650
+ #~ out.gsub!( /&/, '\\\&') #geht schief. erzeugt <<body>>...
651
+ #~ out.gsub!( /\\/, '\\\\')
652
+ out.gsub!( /%/, '\%')
653
+ out.gsub!( /\$/, '\$')
654
+ out.gsub!( /&/, '\\\\&')
655
+ out.gsub!( /_/, '\_')
656
+ out.gsub!( /#/, '\#')
657
+ #~ out.gsub!( /€/, '\euro ') #regexp is in utf-8 -- may make problems.
658
+ return out
659
+ end
660
+ def inspect()
661
+ return "#<Document '#{@title}'>"
662
+ end
663
+ end #Eigenclass Document
664
+ end #Document
651
665
  end #module Docgenerator