docgenerator 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/build_test_and_doc.rb +505 -0
- data/examples/creole_example.rb +82 -0
- data/examples/creole_example_footnote.rb +67 -0
- data/examples/creole_example_placeholder.rb +77 -0
- data/examples/creole_example_rail.rb +154 -0
- data/examples/creole_example_rubycode.rb +144 -0
- data/examples/creole_example_struktex.rb +169 -0
- data/examples/docgenerator_example.rb +1 -1
- data/examples/docgenerator_example_footnote.rb +1 -0
- data/examples/docgenerator_example_list.rb +3 -0
- data/examples/docgenerator_example_restrictions.rb +1 -1
- data/examples/docgenerator_example_tabular.rb +1 -1
- data/examples/docgenerator_example_tripfalls.rb +2 -2
- data/examples/results/readme +2 -1
- data/examples/wiki2docgenerator_example.rb +61 -32
- data/lib/creole/creole2doc.rb +57 -58
- data/lib/creole/creole_characters.rb +56 -0
- data/lib/creole/creole_inclusion_and_plugins.rb +59 -284
- data/lib/creole/creole_inclusions.rb +142 -0
- data/lib/creole/creole_placeholder.rb +57 -23
- data/lib/creole/creole_plugins.rb +198 -0
- data/lib/creole/creole_tabular.rb +16 -8
- data/lib/creole/plugins/rail.rb +182 -0
- data/lib/creole/plugins/rubycode4creole.rb +136 -0
- data/lib/creole/plugins/struktex.rb +59 -0
- data/lib/creole/plugins/todonotes.rb +70 -0
- data/lib/docgenerator.rb +161 -71
- data/lib/docgenerator/attribute.rb +189 -156
- data/lib/docgenerator/characters.rb +824 -267
- data/lib/docgenerator/compatibility_v1.rb +249 -0
- data/lib/docgenerator/css.rb +53 -32
- data/lib/docgenerator/document.rb +119 -56
- data/lib/docgenerator/element.rb +304 -351
- data/lib/docgenerator/element_meta.rb +303 -0
- data/lib/docgenerator/elements.rb +1112 -481
- data/lib/docgenerator/environments.rb +153 -62
- data/lib/docgenerator/footnote.rb +30 -9
- data/lib/docgenerator/lists.rb +71 -47
- data/lib/docgenerator/packages/attachfile.rb +136 -0
- data/lib/{packages/docgenerator_caption.rb → docgenerator/packages/caption.rb} +28 -19
- data/lib/docgenerator/packages/hyperref.rb +194 -0
- data/lib/docgenerator/packages/listings.rb +179 -0
- data/lib/docgenerator/packages/pdfpages.rb +43 -0
- data/lib/docgenerator/packages/rubycode4doc.rb +227 -0
- data/lib/{packages/docgenerator_scrlettr2.rb → docgenerator/packages/scrlettr2.rb} +25 -16
- data/lib/docgenerator/packages/scrpage2.rb +410 -0
- data/lib/docgenerator/packages/struktex.rb +447 -0
- data/lib/docgenerator/packages/todonotes.rb +85 -0
- data/lib/{packages/docgenerator_url.rb → docgenerator/packages/url.rb} +7 -6
- data/lib/docgenerator/sections.rb +257 -83
- data/lib/docgenerator/standard.rb +19 -11
- data/lib/docgenerator/tabular.rb +234 -118
- data/lib/{templates → docgenerator/templates}/docgenerator_template.rb +52 -44
- data/lib/{templates → docgenerator/templates}/docgenerator_template.yaml +0 -0
- data/lib/{templates → docgenerator/templates}/docgenerator_template_css.rb +22 -16
- data/lib/wiki2doc/plugins/rubycode4wiki.rb +53 -0
- data/lib/wiki2doc/plugins/struktex.rb +12 -0
- data/lib/wiki2doc/wiki2docgenerator.rb +39 -38
- data/lib/wiki2doc/wikimedia_document.rb +24 -0
- data/manpage_elements.rb +10411 -0
- data/readme.rd +34 -24
- data/unittest/creole_testtext.creole +11 -0
- data/unittest/expected/test_document_usepackage_undefined.log +2 -2
- data/unittest/expected/test_runtex.stdout +0 -1
- data/unittest/expected/test_runtex_2.stdout +0 -1
- data/unittest/expected/toc_css.css +3 -2
- data/unittest/expected_creole/test_creole_characters_all.creole +28 -0
- data/unittest/expected_creole/test_creole_characters_all.html +15 -15
- data/unittest/expected_creole/test_creole_characters_all.latex +15 -15
- data/unittest/expected_creole/test_creole_footnotes_groupid.html +15 -0
- data/unittest/expected_creole/test_creole_links_file.html +2 -2
- data/unittest/expected_creole/test_creole_links_file.latex +2 -2
- data/unittest/expected_creole/test_creole_links_file.text +2 -2
- data/unittest/expected_creole/test_creole_picture_link.html +1 -1
- data/unittest/expected_creole_rail/test_rail_creole_object.tex +33 -0
- data/unittest/expected_creole_rail/test_rail_creole_placeholder.tex +40 -0
- data/unittest/expected_rubycode4doc/creole_complete.html +26 -0
- data/unittest/expected_rubycode4doc/creole_complete.tex +40 -0
- data/unittest/expected_rubycode4doc/creole_in_tab.html +4 -0
- data/unittest/expected_rubycode4doc/creole_in_tab.tex +6 -0
- data/unittest/expected_rubycode4doc/creole_inline_ruby.html +7 -0
- data/unittest/expected_rubycode4doc/creole_output.html +2 -0
- data/unittest/expected_rubycode4doc/creole_output.tex +4 -0
- data/unittest/expected_rubycode4doc/creole_rubycode.html +1 -0
- data/unittest/expected_rubycode4doc/creole_rubycode.tex +3 -0
- data/unittest/expected_rubycode4doc/creole_rubycode_evaluated.html +1 -0
- data/unittest/expected_rubycode4doc/creole_rubycode_evaluated.tex +3 -0
- data/unittest/expected_rubycode4doc/creole_rubycode_evaluated_listings.html +3 -0
- data/unittest/expected_rubycode4doc/creole_rubycode_evaluated_listings.tex +5 -0
- data/unittest/expected_rubycode4doc/wiki_1.html +8 -0
- data/unittest/expected_rubycode4doc/wiki_2.html +8 -0
- data/unittest/expected_rubycode4doc/wiki_3.html +9 -0
- data/unittest/expected_rubycode4doc/wiki_immediate_1.html +5 -0
- data/unittest/expected_rubycode4doc/wiki_immediate_2.html +5 -0
- data/unittest/expected_rubycode4doc/wiki_immediate_3.html +8 -0
- data/unittest/expected_rubycode4doc/wiki_immediate_full.html +21 -0
- data/unittest/expected_struktex/test_struktex_krug.creole +15 -0
- data/unittest/expected_struktex/test_struktex_krug.tex +19 -0
- data/unittest/expected_struktex/test_struktex_krug.wiki +15 -0
- data/unittest/expected_struktex/test_struktex_statement.creole +7 -0
- data/unittest/expected_struktex/test_struktex_statement.tex +9 -0
- data/unittest/expected_struktex/test_struktex_statement.wiki +7 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.html +1 -1
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.latex +1 -1
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.text +1 -1
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_description.wiki +1 -1
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote_2.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_footnote_groupid.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_html_code.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_inline.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_label.html +0 -0
- data/unittest/expected_wikimedia/test_wiki_link.html +8 -0
- data/unittest/expected_wikimedia/test_wiki_link.latex +17 -0
- data/unittest/expected_wikimedia/test_wiki_link.wiki +11 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_after_ul.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ol_ul.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_list_ul_too_much.wiki +0 -0
- data/unittest/expected_wikimedia/test_wiki_picture.html +55 -0
- data/unittest/expected_wikimedia/test_wiki_picture.latex +76 -0
- data/unittest/expected_wikimedia/test_wiki_picture_thumb.html +5 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_tab1.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_tab1.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_tab1.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_textformatting.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_toc.wiki +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.html +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.latex +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.text +0 -0
- data/unittest/{expected_wiki → expected_wikimedia}/test_wiki_ul_multiple_line.wiki +0 -0
- data/unittest/{unittest_creole2doc.rb → unittest_creole.rb} +385 -476
- data/unittest/unittest_creole_placeholders.rb +272 -0
- data/unittest/unittest_creole_plugin_rail.rb +147 -0
- data/unittest/unittest_docgenerator.rb +206 -332
- data/unittest/unittest_docgenerator_characters.rb +650 -0
- data/unittest/unittest_docgenerator_runtex.rb +48 -20
- data/unittest/unittest_packages_struktex.rb +187 -0
- data/unittest/unittest_rubycode4doc.rb +275 -0
- data/unittest/unittest_wikimedia.rb +479 -0
- metadata +245 -172
- data/examples/results_expected/docgenerator_example.html +0 -39
- data/examples/results_expected/docgenerator_example.pdf +0 -0
- data/examples/results_expected/docgenerator_example.tex +0 -56
- data/examples/results_expected/docgenerator_example_footnote.html +0 -40
- data/examples/results_expected/docgenerator_example_footnote.pdf +0 -0
- data/examples/results_expected/docgenerator_example_footnote.tex +0 -50
- data/examples/results_expected/docgenerator_example_list.html +0 -18
- data/examples/results_expected/docgenerator_example_list.pdf +0 -0
- data/examples/results_expected/docgenerator_example_list.tex +0 -46
- data/examples/results_expected/docgenerator_example_restrictions.html +0 -22
- data/examples/results_expected/docgenerator_example_restrictions.pdf +0 -0
- data/examples/results_expected/docgenerator_example_restrictions.tex +0 -31
- data/examples/results_expected/docgenerator_example_tabular.html +0 -37
- data/examples/results_expected/docgenerator_example_tabular.pdf +0 -0
- data/examples/results_expected/docgenerator_example_tabular.tex +0 -41
- data/examples/results_expected/docgenerator_example_tripfalls.html +0 -27
- data/examples/results_expected/docgenerator_example_tripfalls.pdf +0 -0
- data/examples/results_expected/docgenerator_example_tripfalls.tex +0 -31
- data/lib/packages/docgenerator_attachfile.rb +0 -71
- data/lib/packages/docgenerator_hyperref.rb +0 -109
- data/lib/packages/docgenerator_listings.rb +0 -103
- data/lib/packages/docgenerator_pdfpages.rb +0 -24
- data/lib/packages/docgenerator_scrpage2.rb +0 -172
- data/self_docgenerator.rb +0 -163
- data/unittest/expected_wiki/test_wiki_link.html +0 -8
- data/unittest/expected_wiki/test_wiki_link.latex +0 -17
- data/unittest/expected_wiki/test_wiki_link.wiki +0 -11
- data/unittest/expected_wiki/test_wiki_picture.html +0 -55
- data/unittest/expected_wiki/test_wiki_picture.latex +0 -76
- data/unittest/expected_wiki/test_wiki_picture_thumb.html +0 -5
- data/unittest/test_rakefile_docgenerator.rb +0 -43
- data/unittest/unittest_versions.rb +0 -44
- data/unittest/unittest_wiki2doc.rb +0 -464
@@ -0,0 +1,249 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Collection of some "old" coding.
|
4
|
+
|
5
|
+
You can load this code to get:
|
6
|
+
* Element.create - a dynamic command to define a new Element
|
7
|
+
=end
|
8
|
+
|
9
|
+
Docgenerator::DOCGENERATOR_LOGGER.warn("Load compatibility_v1.rb")
|
10
|
+
|
11
|
+
#
|
12
|
+
module Docgenerator
|
13
|
+
=begin rdoc
|
14
|
+
This class defines possible elements of a document.
|
15
|
+
For each type of elements a class is defined.
|
16
|
+
The definition can be done explicite or generic with Element.create.
|
17
|
+
|
18
|
+
All types of elements are stored in a hash,
|
19
|
+
the elements can be created via the method Element.get (or element() ).
|
20
|
+
=end
|
21
|
+
class Element
|
22
|
+
=begin rdoc
|
23
|
+
#Set Element tracing on/off.
|
24
|
+
|
25
|
+
Obsolete. Please use
|
26
|
+
Docgenerator.trace_on
|
27
|
+
=end
|
28
|
+
def self.trace=( val )
|
29
|
+
Docgenerator.trace_on
|
30
|
+
end
|
31
|
+
=begin rdoc
|
32
|
+
Return all id's of the class.
|
33
|
+
@@ids is expanded in Element.add.
|
34
|
+
|
35
|
+
Replaced by Element.element_ids.
|
36
|
+
=end
|
37
|
+
def ids( )
|
38
|
+
myids = []
|
39
|
+
@@ids.each{|k,v| myids << k if v == self.class and k.class != Class }
|
40
|
+
return myids
|
41
|
+
end
|
42
|
+
#Prepares an overview on all Elements.
|
43
|
+
#Can be used for some debugging.
|
44
|
+
def self.overview( list = @@ids.values.uniq )
|
45
|
+
if ! list.kind_of?(Array)
|
46
|
+
list = [ list ]
|
47
|
+
end
|
48
|
+
result = '=' * 10 + "\nElement overview:"
|
49
|
+
list.each{ |k|
|
50
|
+
result += "\n#{k}\n"
|
51
|
+
result += "\tId's:\t\t"
|
52
|
+
result += k.new.element_ids.join("\n\t\t\t")
|
53
|
+
result += "\n\tAttributes:\t"
|
54
|
+
result += "can contain "
|
55
|
+
result += "no " if ! k.new.content?
|
56
|
+
result += "content\n\t\t\t"
|
57
|
+
self.class.attributes.each{ |k2,v|
|
58
|
+
result += "#{k2}:\t#{v.inspect}\n\t\t\t"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return result
|
62
|
+
end
|
63
|
+
|
64
|
+
=begin rdoc
|
65
|
+
Add a new element class or assign another name (synonym) for a class.
|
66
|
+
The initial call is made by Element.inherited.
|
67
|
+
|
68
|
+
Element.add( [:element], Element )
|
69
|
+
|
70
|
+
Replaced by meta method Element.add_id
|
71
|
+
=end
|
72
|
+
def self.add( idlist, elementClass )
|
73
|
+
#~ DOCGENERATOR_LOGGER.warn("Element.add called -> to be replaced") if DOCGENERATOR_LOGGER.warn?
|
74
|
+
if ! elementClass.new.kind_of?( Element )
|
75
|
+
raise "Element.add get no Element-class #{elementClass}"
|
76
|
+
end
|
77
|
+
idlist = [ idlist ] if ! idlist.kind_of?( Array )
|
78
|
+
raise "Empty idlist for #{elementClass}" if idlist.empty?
|
79
|
+
|
80
|
+
idlist.each{|id|
|
81
|
+
elementClass.add_id(id)
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
=begin rdoc
|
86
|
+
Generic creation of a new class to define a new element.
|
87
|
+
- name must be defined.
|
88
|
+
- attr is a hash with all attributes.
|
89
|
+
For details see Element.add_attributes
|
90
|
+
- content is a flag, which defines if the element contains "content".
|
91
|
+
Valid values are:
|
92
|
+
- true: content available and necessary (e.g. <p>)
|
93
|
+
- :empty_ok: content available, but not necessary (e.g. <td> or iframe)
|
94
|
+
- false: no content, no endtag, but tag closed with / (example: <br />)
|
95
|
+
- nil: no content, no endtag, no closing (example: <br>)
|
96
|
+
- output contains a hash with logic, how to handle the output.
|
97
|
+
-:htmltag Tag for html-output.
|
98
|
+
-:latex Template for LaTeX-output
|
99
|
+
-:html Template for HTML-output
|
100
|
+
|
101
|
+
This code is obsolete.
|
102
|
+
Please use Element.create_convert_to_code to get a template to replace your Element#create.
|
103
|
+
=end
|
104
|
+
def self.create( name, attr = {}, content = false, output = {} )
|
105
|
+
DOCGENERATOR_LOGGER.warn("Element.create called -> to be replaced") if DOCGENERATOR_LOGGER.warn?
|
106
|
+
create_convert_to_code( [name].flatten, attr, content, output ) if DOCGENERATOR_LOGGER.warn?
|
107
|
+
#First some checks
|
108
|
+
if ! attr.kind_of?( Hash )
|
109
|
+
raise "Type error Element.create: Expected Hash, get #{attr.class}"
|
110
|
+
end
|
111
|
+
#Generic class creation
|
112
|
+
elementclass = Class.new( Element )
|
113
|
+
#Add the id of the new class to central collection.
|
114
|
+
Element.add( name, elementclass )
|
115
|
+
|
116
|
+
#Set a flag, if the class can contain 'content'.
|
117
|
+
#-true: content available and necessary (e.g. <p>)
|
118
|
+
#-:empty_ok: content available, but not necessary (e.g. <td>)
|
119
|
+
#-false: no content, no endtag, but tag closed with / (example: <br />)
|
120
|
+
#-nil: no content, no endtag, no closing (example: <br>)
|
121
|
+
elementclass.class_eval( %Q|
|
122
|
+
def content?()
|
123
|
+
return #{content.inspect}
|
124
|
+
end|)
|
125
|
+
|
126
|
+
output.each{ |k,v|
|
127
|
+
case k
|
128
|
+
when :latex
|
129
|
+
elementclass.add_output( :latex, v )
|
130
|
+
when :context
|
131
|
+
elementclass.add_output( :context, v )
|
132
|
+
when :html
|
133
|
+
elementclass.add_output( :html, v )
|
134
|
+
when :text
|
135
|
+
elementclass.add_output( :text, v )
|
136
|
+
when :wiki
|
137
|
+
elementclass.add_output( :wiki, v )
|
138
|
+
when :creole
|
139
|
+
elementclass.add_output( :creole, v )
|
140
|
+
when :htmltag
|
141
|
+
if v
|
142
|
+
elementclass.class_eval( "def htmltag()\n'#{v}'\nend" )
|
143
|
+
else
|
144
|
+
elementclass.class_eval( "def htmltag()\nnil\nend" )
|
145
|
+
end
|
146
|
+
else
|
147
|
+
puts "#{__FILE__}##{__LINE__}: Unknown format #{k} for #{name}"
|
148
|
+
end
|
149
|
+
}
|
150
|
+
elementclass.add_attributes( attr )
|
151
|
+
#Return the class.
|
152
|
+
return elementclass
|
153
|
+
end #Element.create
|
154
|
+
=begin rdoc
|
155
|
+
Transformer of old Element.create-Logic to metaprogramming.
|
156
|
+
|
157
|
+
Requires a manual postprocess to define Attributes correct.
|
158
|
+
|
159
|
+
=end
|
160
|
+
def self.create_convert_to_code( name, attr = {}, content = false, output = {} )
|
161
|
+
#First some checks
|
162
|
+
if ! attr.kind_of?( Hash )
|
163
|
+
raise "Type error Element.create: Expected Hash, get #{attr.class}"
|
164
|
+
end
|
165
|
+
#Build code for class creation
|
166
|
+
code = "\n"
|
167
|
+
code << <<comment
|
168
|
+
=begin rdoc
|
169
|
+
Define Element #{name.map{|x|x.inspect}.join(', ')}
|
170
|
+
|
171
|
+
Create an instance with
|
172
|
+
#{name.map{|x|
|
173
|
+
" element( #{x.inspect}, [ attributes, [content]] )"
|
174
|
+
}.join("\n")
|
175
|
+
}
|
176
|
+
or
|
177
|
+
#{name.first.capitalize}.new( [ attributes, [content]] )
|
178
|
+
comment
|
179
|
+
if attr.size == 0
|
180
|
+
code << "Attributes are not defined for this element.\n"
|
181
|
+
else
|
182
|
+
code << "Attributes may be:\n"
|
183
|
+
end
|
184
|
+
attr.each{|key, att|
|
185
|
+
code << "* #{key.inspect}: \n" #fixme #{att.new.allowed_values.inspect}
|
186
|
+
}
|
187
|
+
code << "=end\n"
|
188
|
+
code << "class #{name.first.capitalize} < Element\n"
|
189
|
+
name[1..-1].each{|n|
|
190
|
+
code << " add_id #{n.inspect}\n"
|
191
|
+
}
|
192
|
+
if ! content
|
193
|
+
code << " has_no_content #{content.inspect}\n"
|
194
|
+
end
|
195
|
+
if ( HTML_ATTR_CORE.keys & attr.keys ) == HTML_ATTR_CORE.keys
|
196
|
+
code << " add_attributes HTML_ATTR_CORE\n"
|
197
|
+
end
|
198
|
+
if ( HTML_ATTR_I18N.keys & attr.keys ) == HTML_ATTR_I18N.keys
|
199
|
+
code << " add_attributes HTML_ATTR_I18N\n"
|
200
|
+
end
|
201
|
+
if ( HTML_ATTR_EVENTS.keys & attr.keys ) == HTML_ATTR_EVENTS.keys
|
202
|
+
code << " add_attributes HTML_ATTR_EVENTS\n"
|
203
|
+
end
|
204
|
+
if attr.has_value?(ATTR_LANG)
|
205
|
+
code << " add_attribute #{attr.key(ATTR_LANG).inspect}, ATTR_LANG\n"
|
206
|
+
end
|
207
|
+
if attr.has_value?(HTML_ATTR_ALIGN)
|
208
|
+
code << " add_attribute #{attr.key(HTML_ATTR_ALIGN).inspect}, HTML_ATTR_ALIGN\n"
|
209
|
+
end
|
210
|
+
if attr.has_value?(HTML_ATTR_VALIGN)
|
211
|
+
code << " add_attribute #{attr.key(HTML_ATTR_VALIGN).inspect}, HTML_ATTR_VALIGN\n"
|
212
|
+
end
|
213
|
+
( attr.keys - HTML_ATTR_CORE.keys - HTML_ATTR_I18N.keys - HTML_ATTR_EVENTS.keys
|
214
|
+
).each{|key|
|
215
|
+
code << " add_attribute #{key.inspect}, ?? )\n" #?? - Definition aus Vorlag holen
|
216
|
+
}
|
217
|
+
output.each{ |k,v|
|
218
|
+
case k
|
219
|
+
when :latex
|
220
|
+
code << " add_latex_output '#{v}'\n"
|
221
|
+
when :context
|
222
|
+
code << " add_context_output '#{v}'\n"
|
223
|
+
when :html
|
224
|
+
code << " add_html_output '#{v}'\n"
|
225
|
+
when :text
|
226
|
+
code << " add_text_output '#{v}'\n"
|
227
|
+
when :wiki
|
228
|
+
code << " add_wiki_output '#{v}'\n"
|
229
|
+
when :creole
|
230
|
+
code << " add_creole_output '#{v}'\n"
|
231
|
+
when :htmltag
|
232
|
+
if v
|
233
|
+
code << " add_html_tag '#{v}'\n"
|
234
|
+
else
|
235
|
+
#~ code << " def htmltag(); nil; end\n"
|
236
|
+
end
|
237
|
+
else
|
238
|
+
puts "#{__FILE__}##{__LINE__}: Unknown format #{k} for #{name}"
|
239
|
+
end
|
240
|
+
}
|
241
|
+
code << "end ##{name.first.capitalize}\n"
|
242
|
+
puts code
|
243
|
+
#~ class_eval(code)
|
244
|
+
#Return the class.
|
245
|
+
return code
|
246
|
+
end
|
247
|
+
|
248
|
+
end #Element
|
249
|
+
end
|
data/lib/docgenerator/css.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
end
|
1
|
+
=begin rdoc
|
2
|
+
Define classes to use cascading style sheets (CSS) for HTML-documents.
|
3
|
+
=end
|
4
|
+
|
5
|
+
#
|
6
|
+
module Docgenerator
|
7
|
+
=begin rdoc
|
8
|
+
Define Element ':style'
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#~ :html => "\n<style type=\"text/css\">\n" + '#{@content}' + "</style>\n",
|
10
|
-
#~ :latex => nil
|
11
|
-
#~ } )
|
10
|
+
Create an instance with
|
11
|
+
element( :style, [ attributes, [content]] )
|
12
|
+
|
13
|
+
Style.new( [ attributes, [content]] )
|
12
14
|
|
15
|
+
Only for HTML.
|
16
|
+
=end
|
13
17
|
class Style < Element
|
14
|
-
Element.add( [:style], self)
|
15
18
|
#~ add_attributes( HTML_ATTR_ALL )
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
add_latex_output ''
|
20
|
+
add_text_output ''
|
21
|
+
add_wiki_output ''
|
22
|
+
add_creole_output ''
|
19
23
|
#Prepare HTML-Output for Style-Tag.
|
20
24
|
#The values can be overwritten, if different CSS-Elements are inside.
|
21
25
|
def to_html( options = {} )
|
22
|
-
o =
|
26
|
+
o = set_option_defaults(options)
|
23
27
|
o[:log].debug("Enter style.to_html") if o[:log].debug?
|
24
28
|
res = ""
|
25
29
|
res << "\n" if @crbefore
|
@@ -31,30 +35,36 @@ class Style < Element
|
|
31
35
|
res << "\n" if @crafter
|
32
36
|
return res
|
33
37
|
end
|
34
|
-
end
|
38
|
+
end #Style
|
35
39
|
|
36
40
|
CSS_COLORS = [ /rgb\((\d+%?,?){3,3}\)/,
|
37
41
|
#rgb(R,G,B), rgb(%,%,%) oder #XXXXXX
|
38
42
|
#/gray\d{1,3}/
|
39
|
-
'black','gray','maroon','red', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'purple', 'fuchsia', 'teal', 'aqua', 'silver', 'white',
|
43
|
+
'black','gray', 'grey', 'maroon','red', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'purple', 'fuchsia', 'teal', 'aqua', 'silver', 'white',
|
40
44
|
#Netscape-Farbnamen (120 zus�tzliche Farben)
|
41
45
|
#Falsche Darstellungen, siehe http://www.rzuser.uni-heidelberg.de/~x22/ht/farben2.html
|
42
|
-
'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgreen',
|
46
|
+
'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgreen',
|
47
|
+
'lightgrey', 'lightgray', 'lightslategray', 'lightslategrey', #yes, both are defined
|
48
|
+
'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightsteelblue', 'lightyellow',
|
43
49
|
'greenyellow', 'palegreen', 'darkgreen',
|
44
50
|
'darkred', 'firebrick',
|
45
51
|
'salmon',
|
46
52
|
]
|
47
53
|
CSS_BORDER = [ 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset' ]
|
48
54
|
CSS_WIDTH = [ /\d*(cm|mm|px|em|%)/, 'thin', 'medium', 'thick' ]
|
49
|
-
|
50
|
-
|
55
|
+
|
56
|
+
=begin rdoc
|
57
|
+
Class to collect css-settings for a Element.
|
58
|
+
|
59
|
+
This values can be used inline (style-Attribute) and inside style>-Tags
|
60
|
+
=end
|
51
61
|
class CSS
|
52
62
|
#List of all allowed values.
|
53
63
|
#The first value is a regular expression, coninued by fixed values.
|
54
64
|
@@values = {
|
55
|
-
'font-size' => [
|
65
|
+
'font-size' => [ 'xx-small', 'x-small', 'small', 'medium', 'large','x-large','xx-large','smaller','larger', /\A\d+(pt|px|em)/ ],
|
56
66
|
'font-style' => ['italic', 'oblique', 'normal'],
|
57
|
-
'font-weight' => ['bold'
|
67
|
+
'font-weight' => ['bold', 'bolder', 'lighter', 'normal', /\A\d00\Z/ ],
|
58
68
|
'color' => CSS_COLORS,
|
59
69
|
'background-color' => CSS_COLORS,
|
60
70
|
'visibility' => ['hidden', 'visible' ],
|
@@ -124,7 +134,8 @@ class CSS
|
|
124
134
|
}
|
125
135
|
def initialize( values ={} )
|
126
136
|
@values = {}
|
127
|
-
|
137
|
+
#~ set_option_defaults(values) #guarantee :log
|
138
|
+
@log = values[:log] || DOCGENERATOR_DEFAULT_LOGGER
|
128
139
|
values.delete(:log)
|
129
140
|
|
130
141
|
values.each{|k,v|
|
@@ -132,7 +143,9 @@ class CSS
|
|
132
143
|
}
|
133
144
|
@cr = nil
|
134
145
|
end
|
135
|
-
|
146
|
+
=begin rdoc
|
147
|
+
Make key unique. convert symbol to String...
|
148
|
+
=end
|
136
149
|
def generalize_key( k )
|
137
150
|
key = nil
|
138
151
|
if k.is_a?(Symbol)
|
@@ -145,11 +158,13 @@ class CSS
|
|
145
158
|
def []( k )
|
146
159
|
return @values[generalize_key( k )]
|
147
160
|
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
161
|
+
=begin rdoc
|
162
|
+
Add a setting.
|
163
|
+
|
164
|
+
If an existing value is overwritten, you get a warning.
|
165
|
+
To replace a value, use
|
166
|
+
css[key].replace( value ) (But the you have no check)
|
167
|
+
=end
|
153
168
|
def []=( k, v )
|
154
169
|
key = generalize_key( k )
|
155
170
|
if @values[key]
|
@@ -165,7 +180,9 @@ class CSS
|
|
165
180
|
|
166
181
|
@values[key] = v
|
167
182
|
end
|
168
|
-
|
183
|
+
=begin rdoc
|
184
|
+
Returns the values for a direct css in the style-attribute for a HTML-tag.
|
185
|
+
=end
|
169
186
|
def to_html(options={})
|
170
187
|
o = {
|
171
188
|
:map => "%s;",
|
@@ -175,7 +192,9 @@ class CSS
|
|
175
192
|
def to_s()
|
176
193
|
return self.to_html
|
177
194
|
end
|
178
|
-
|
195
|
+
=begin rdoc
|
196
|
+
Returns a tab with the textes for each characteristic.
|
197
|
+
=end
|
179
198
|
def to_tab()
|
180
199
|
s = []
|
181
200
|
@values.sort.each{|k,v|
|
@@ -183,7 +202,9 @@ class CSS
|
|
183
202
|
}
|
184
203
|
return s
|
185
204
|
end
|
186
|
-
end
|
205
|
+
end #CSS
|
206
|
+
|
207
|
+
end #module Docgenerator
|
187
208
|
|
188
209
|
if __FILE__ == $0
|
189
210
|
#~ DOCGENERATOR_LOGGER.level = Log4r::DEBUG
|
@@ -1,4 +1,27 @@
|
|
1
1
|
#encoding: utf-8
|
2
|
+
|
3
|
+
#
|
4
|
+
module Docgenerator
|
5
|
+
=begin rdoc
|
6
|
+
Extension for Log4r::Logger (#INFO)
|
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?()
|
13
|
+
=begin rdoc
|
14
|
+
INFO is a *important* information.
|
15
|
+
It's like a warning, but outputted as information.
|
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
|
2
25
|
=begin rdoc
|
3
26
|
Container for a document.
|
4
27
|
|
@@ -29,12 +52,14 @@ class Document
|
|
29
52
|
end
|
30
53
|
end
|
31
54
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
55
|
+
=begin rdoc
|
56
|
+
Create a new document.
|
57
|
+
There are different document templates supported.
|
58
|
+
The templates refer to the corresponding TeX-classes.
|
59
|
+
- article
|
60
|
+
- report
|
61
|
+
- book
|
62
|
+
=end
|
38
63
|
def initialize( settings = {} )
|
39
64
|
#Set template defaults
|
40
65
|
@template = {
|
@@ -60,6 +85,8 @@ class Document
|
|
60
85
|
@log = Log4r::Logger.new( 'Doc', Log4r::WARN )
|
61
86
|
@log.outputters = Log4r::StdoutOutputter.new('log_xxx')
|
62
87
|
end
|
88
|
+
@log.extend(Logger_INFO) unless @log.respond_to?(:INFO)
|
89
|
+
|
63
90
|
@meta = {} #some meta-Tags for HTML
|
64
91
|
@body = element( :body, { :log => @log } )
|
65
92
|
@head = element( :head, { :log => @log } )
|
@@ -137,13 +164,15 @@ class Document
|
|
137
164
|
#Define, if there should be a message in case of:
|
138
165
|
#-:change Document changed
|
139
166
|
#-:nochange Document existed, but is unchanged
|
140
|
-
#
|
167
|
+
#Please provide an array with the wanted values.
|
141
168
|
def Document.givemessage=( value = [:change, :nochange] )
|
142
169
|
@@givemessage = value
|
143
170
|
end
|
144
171
|
@@givemessage = [:change, :nochange]
|
145
172
|
def Document.givemessage(); @@givemessage; end
|
146
|
-
|
173
|
+
=begin rdoc
|
174
|
+
Add a meta-tag-information for the HTML-Output.
|
175
|
+
=end
|
147
176
|
def meta( key, content )
|
148
177
|
key = key.to_s
|
149
178
|
|
@@ -219,12 +248,13 @@ class Document
|
|
219
248
|
toccnt = 0
|
220
249
|
toc_ids = [ :chapter, :section,:subsection, :subsubsection, :paragraph, :subparagraph,:minisec]
|
221
250
|
@body.content.flatten.each{|el|
|
222
|
-
if ! el.respond_to?(:
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
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])
|
228
258
|
next if ! depth #Element is no header
|
229
259
|
|
230
260
|
opt[:log].debug("Toc: Found entry on level #{depth}: <#{el.content}>") if opt[:log].debug?
|
@@ -271,11 +301,14 @@ end
|
|
271
301
|
=begin rdoc
|
272
302
|
Save the file.
|
273
303
|
The type of the document is determined by the file extensison.
|
304
|
+
|
274
305
|
Supported document types are:
|
275
|
-
- tex
|
276
|
-
-
|
277
|
-
- (
|
306
|
+
- tex (*.tex)
|
307
|
+
- context (*.mkiv)
|
308
|
+
- html (*.htm[l])
|
309
|
+
- (wiki wikimedia/creole)
|
278
310
|
- (text)
|
311
|
+
|
279
312
|
Depending on a template, different results are created.
|
280
313
|
|
281
314
|
There is a comparison between an already existing file and the new one.
|
@@ -288,7 +321,7 @@ Valid options:
|
|
288
321
|
allows to overwrite
|
289
322
|
- target
|
290
323
|
In most cases this is defined by the extension.
|
291
|
-
|
324
|
+
This attribute allows to set :context for tex-files.
|
292
325
|
- :additional_options
|
293
326
|
List of options.
|
294
327
|
If you want to give parameters to specific 'Element'-objects you can define the keys here.
|
@@ -329,10 +362,11 @@ Valid options:
|
|
329
362
|
return false
|
330
363
|
end
|
331
364
|
|
365
|
+
|
332
366
|
prefix = [ nil,
|
333
367
|
"Build by\t#{__FILE__}",
|
334
368
|
"Dir:\t\t#{Dir.pwd}",
|
335
|
-
"Creator:\
|
369
|
+
"Creator:\tDocgenerator #{Docgenerator::VERSION} - http://rubygems.org/gems/docgenerator",
|
336
370
|
"Target:\t\t#{filename}",
|
337
371
|
"#{Time.now.strftime('%Y/%m/%d %H:%M:%S')}",
|
338
372
|
nil,
|
@@ -346,7 +380,7 @@ Valid options:
|
|
346
380
|
target = :latex
|
347
381
|
#Take context if requested.
|
348
382
|
target = :context if options[:target] == :context
|
349
|
-
when /
|
383
|
+
when /mk(ii|iv)/i #Mark II and IV
|
350
384
|
target = :context
|
351
385
|
when /htm[l]?/i
|
352
386
|
target = :html
|
@@ -412,19 +446,21 @@ Valid options:
|
|
412
446
|
if new != old
|
413
447
|
new.sub!( '<<prefix>>', prefix)
|
414
448
|
if ( File.exist?( filename ) and ! options[:overwrite] )
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
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
|
421
457
|
end
|
458
|
+
@log.info( "Overwrite #{filename} after confirmation" ) if @log.info?
|
422
459
|
end
|
423
460
|
File.open( filename, 'w', :external_encoding => new.encoding ){|f|
|
424
461
|
f << new
|
425
462
|
}
|
426
|
-
@log.
|
427
|
-
puts "Save changed\t#{filename}" if @@givemessage.include?(:change)
|
463
|
+
@log.INFO( "Save changed\t#{filename}") if @log.INFO?
|
428
464
|
#Save copy of old version (attention, *.bak makes no control on tex or html)
|
429
465
|
#~ f = File.new( filename.sub( extension, 'bak'), 'w' )
|
430
466
|
#~ f << old
|
@@ -432,38 +468,48 @@ Valid options:
|
|
432
468
|
Document.runtex( filename, options[:runtex] ) if options[:runtex] and [:latex, :context].include?(target)
|
433
469
|
return true
|
434
470
|
elsif old
|
435
|
-
@log.
|
436
|
-
puts "Unchanged\t#{filename}" if @@givemessage.include?(:nochange)
|
471
|
+
@log.INFO("Unchanged\t#{filename}") if @log.INFO?
|
437
472
|
return false
|
438
473
|
end
|
439
474
|
end #Document#save
|
440
475
|
=begin rdoc
|
441
|
-
Build the content for the target format.
|
476
|
+
Build the content of a document for the target format.
|
477
|
+
|
442
478
|
Supported target formats are:
|
443
479
|
- :latex
|
444
480
|
- :html
|
445
481
|
- :text
|
482
|
+
- :wiki
|
483
|
+
- :creole
|
484
|
+
|
485
|
+
Options are passed in a Hash:
|
486
|
+
* :log [required]: a logger
|
487
|
+
* :template [required]: a Docgenerator::DocumentTemplate-instance
|
488
|
+
* :filename [recommended]: used in logging informations
|
489
|
+
* :replacements [optional]: Hash with regexp/result pairs to modify the output.
|
490
|
+
|
446
491
|
If the standard templates are used, there is a <<prefix>> left
|
447
492
|
(used from Document#save to include some additional information).
|
448
493
|
|
494
|
+
You may use a String as dummy template.
|
495
|
+
|
449
496
|
If the method is called directly to prepare document snipplets, you can use:
|
450
|
-
|
497
|
+
doc = Document.new()
|
498
|
+
# ... fill doc
|
499
|
+
puts doc.to_doc( :latex,
|
500
|
+
:log => Log4r::Logger.new('testlog'),
|
501
|
+
:template=> '<<body>>',
|
502
|
+
#~ :template=> doc.template[:latex],
|
503
|
+
:filename => 'dummy',
|
504
|
+
#~ :replacements => { /xxx/ => 'cc' }
|
505
|
+
)
|
451
506
|
|
452
|
-
It is possible to give pairs of RegExp (pattern) and a replacement to the result.
|
453
507
|
=end
|
454
508
|
def to_doc( target, options )
|
455
|
-
#~ o =
|
509
|
+
#~ o = set_option_defaults(options)
|
456
510
|
options[:log].info( "Build document for #{target.inspect}" ) if options[:log].info?
|
457
|
-
template = options[:template]
|
458
|
-
if ! template
|
459
|
-
options[:log].error( "No template available to create #{target.inspect} #{self.class}" ) if options[:log].error?
|
460
|
-
return ''
|
461
|
-
end
|
462
|
-
replacements = options[:replacements] || {}
|
463
|
-
options[:log].warn( "No filename given " ) if options[:log].warn? and ! options[:filename]
|
464
511
|
|
465
|
-
|
466
|
-
encoding = template.template.encoding
|
512
|
+
#check target
|
467
513
|
case target
|
468
514
|
when :latex
|
469
515
|
add_option( @language )
|
@@ -472,37 +518,52 @@ It is possible to give pairs of RegExp (pattern) and a replacement to the result
|
|
472
518
|
when :html
|
473
519
|
when :text
|
474
520
|
when :wiki
|
521
|
+
options[:log].warn( "Support for #{target} stopped" ) if options[:log].warn?
|
475
522
|
when :creole
|
476
523
|
options[:log].warn( "Support for #{target} under development" ) if options[:log].warn?
|
477
524
|
else
|
478
525
|
options[:log].fatal( "Unknown target #{target} for #{options[:filename]}" ) if options[:log].fatal?
|
479
526
|
return ''
|
480
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]
|
535
|
+
else
|
536
|
+
options[:log].error( "No template available to create #{target.inspect} #{self.class}" ) if options[:log].error?
|
537
|
+
return ''
|
538
|
+
end
|
481
539
|
if ! new.kind_of?( String )
|
482
|
-
options[:log].
|
540
|
+
options[:log].fatal( "New is wrong type: #{new.inspect}") if options[:log].fatal?
|
541
|
+
return ''
|
483
542
|
end
|
543
|
+
encoding = new.encoding
|
544
|
+
|
545
|
+
#Set replacements
|
546
|
+
replacements = options[:replacements] || {}
|
484
547
|
|
485
548
|
options[:document] = self
|
549
|
+
|
486
550
|
@head << self.docinfo()
|
487
551
|
options[:log].debug( "Build header data") if options[:log].debug?
|
488
552
|
new.sub!( '<<head>>', @head.to_doc(target, options ).encode(encoding))
|
553
|
+
|
489
554
|
options[:log].debug( "Build body") if options[:log].debug?
|
490
555
|
new.sub!( '<<body>>', @body.to_doc(target, options).encode(encoding))
|
491
|
-
new.sub!( '<<classoptions>>', @options.uniq.join(',').encode(encoding))
|
492
556
|
|
557
|
+
new.sub!( '<<classoptions>>', @options.uniq.join(',').encode(encoding))
|
493
558
|
|
559
|
+
#manipulate result
|
494
560
|
replacements.each{|pattern, replace |
|
495
561
|
options[:log].info("Replace text #{pattern.source} with #{replace}" ) if options[:log].info?
|
496
562
|
new.gsub!( pattern, replace ) if replace
|
497
563
|
}
|
498
564
|
return new
|
499
565
|
end #Document#to_doc
|
500
|
-
|
501
|
-
#Needed by Element#to_s to decide which method is used to prepare the output.
|
502
|
-
#
|
503
|
-
#The usage of this technic makes similar processing unposibble.
|
504
|
-
#Set in Document#save.
|
505
|
-
attr_reader :target
|
566
|
+
|
506
567
|
=begin rdoc
|
507
568
|
Call rake4latex to translate the file.
|
508
569
|
=end
|
@@ -534,8 +595,6 @@ warning
|
|
534
595
|
options = [:touch, :statistic, :clean]
|
535
596
|
rescue LoadError
|
536
597
|
puts "Sorry, I didn't find the rake4latex to translate #{filename}"
|
537
|
-
puts "I try to use the old 'RunTeX'"
|
538
|
-
runtex_old( filename, options[:format] )
|
539
598
|
return false
|
540
599
|
end unless defined? Rake4LaTeX
|
541
600
|
end # ! defined? Rake4LaTeX
|
@@ -567,10 +626,14 @@ warning
|
|
567
626
|
Make some basic replacements for TeX.
|
568
627
|
There is no sense to use it with HTML.
|
569
628
|
|
570
|
-
Better solution:
|
629
|
+
Better solution:
|
630
|
+
* use elements from Docgenerator::Characters
|
631
|
+
* Use unicode in TeX-Document.
|
632
|
+
* Put string into \path, \verb or similar.
|
571
633
|
=end
|
572
634
|
def Document.texify( input )
|
573
635
|
out = input.strip
|
636
|
+
|
574
637
|
#~ out.gsub!( /&/, '\\\&') #geht schief. erzeugt <<body>>...
|
575
638
|
#~ out.gsub!( /\\/, '\\\\')
|
576
639
|
out.gsub!( /%/, '\%')
|
@@ -578,11 +641,11 @@ Better solution: Puts String into \path, \verb or similar.
|
|
578
641
|
out.gsub!( /&/, '\\\\&')
|
579
642
|
out.gsub!( /_/, '\_')
|
580
643
|
out.gsub!( /#/, '\#')
|
581
|
-
out.gsub!( /€/, '\euro ')
|
644
|
+
#~ out.gsub!( /€/, '\euro ') #regexp is in utf-8 -- may make problems.
|
582
645
|
return out
|
583
646
|
end
|
584
647
|
def inspect()
|
585
648
|
return "#<Document '#{@title}'>"
|
586
|
-
#~ return "#<Document '#{@title} #{@body.inspect}>'"
|
587
649
|
end
|
588
650
|
end #Document
|
651
|
+
end #module Docgenerator
|