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.
- 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
data/lib/docgenerator/element.rb
CHANGED
|
@@ -1,239 +1,46 @@
|
|
|
1
1
|
#encoding: utf-8
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Docgenerator
|
|
6
|
+
=begin rdoc
|
|
7
|
+
This class defines possible elements of a document.
|
|
8
|
+
For each type of elements a class is defined.
|
|
9
|
+
The definition can be done explicite or generic with Element.create.
|
|
10
|
+
|
|
11
|
+
All types of elements are stored in a hash,
|
|
12
|
+
the elements can be created via the method Element.get (or element() ).
|
|
13
|
+
|
|
14
|
+
Tracing
|
|
15
|
+
Often there is the problem, that you get an error when you write the element.
|
|
16
|
+
But the error is done, when the element is created.
|
|
17
|
+
When you redefine ELEMENTS_TRACE, some tracing information are stored during creation.
|
|
18
|
+
=end
|
|
13
19
|
class Element
|
|
14
20
|
include Docgenerator #get VERSION
|
|
15
|
-
#Hash with all ids and their corresponding classes.
|
|
16
|
-
@@ids = Hash.new( )
|
|
17
|
-
#All attributes are stored in this hash.
|
|
18
|
-
#The key is the corresponding class.
|
|
19
|
-
@@attr = { Element => {} }
|
|
20
|
-
|
|
21
|
-
#Flag, if the calling stack should be analysed for each Element
|
|
22
|
-
#Only for document debbuging
|
|
23
|
-
@@trace = nil
|
|
24
|
-
#Set Element tracing on/off
|
|
25
|
-
def Element.trace=( val )
|
|
26
|
-
@@trace = val
|
|
27
|
-
end
|
|
28
21
|
|
|
29
22
|
SUPPORTED_TARGETS = [ :latex, :html, :wiki, :text, :debug ]
|
|
30
23
|
SUPPORTED_TARGETS << :context #Added later
|
|
31
24
|
SUPPORTED_TARGETS << :creole #Added later
|
|
32
|
-
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
#There is no possibility to give a list of id's or names to a 'inherit'-method.
|
|
48
|
-
#So a special method Element.add is used.
|
|
49
|
-
Element.add( [subclass], subclass )
|
|
50
|
-
end
|
|
51
|
-
#Add a new element class or assign another name (synonym) for a class.
|
|
52
|
-
#The initial call is made by Element.inherited.
|
|
53
|
-
#
|
|
54
|
-
#Element.add( [:element], Element )
|
|
55
|
-
def Element.add( idlist, elementClass )
|
|
56
|
-
if ! elementClass.new.kind_of?( Element )
|
|
57
|
-
raise "Element.add get no Element-class #{elementClass}"
|
|
58
|
-
end
|
|
59
|
-
idlist = [ idlist ] if ! idlist.kind_of?( Array )
|
|
60
|
-
raise "Empty idlist for #{elementClass}" if idlist.empty?
|
|
61
|
-
|
|
62
|
-
idlist.each{|id|
|
|
63
|
-
if @@ids[ id ] == nil
|
|
64
|
-
DOCGENERATOR_LOGGER.debug("Element class '#{id}' is new: #{elementClass}") if DOCGENERATOR_LOGGER.debug?
|
|
65
|
-
#All new ids are collected
|
|
66
|
-
@@ids[ id ] = elementClass
|
|
67
|
-
elsif @@ids[ id ] == elementClass
|
|
68
|
-
DOCGENERATOR_LOGGER.warn("Element class '#{id}' is defined double: #{elementClass}") if DOCGENERATOR_LOGGER.warn?
|
|
69
|
-
else
|
|
70
|
-
DOCGENERATOR_LOGGER.error("Error: ID '#{id}' is redefined #{@@ids[id]} -> #{elementClass}") if DOCGENERATOR_LOGGER.error?
|
|
71
|
-
@@ids[id] = elementClass
|
|
72
|
-
end
|
|
73
|
-
}
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
#Generic creation of a new class to define a new element.
|
|
77
|
-
#- name must be defined.
|
|
78
|
-
#- attr is a hash with all attributes.
|
|
79
|
-
# For details see Element.add_attributes
|
|
80
|
-
#- content is a flag, which defines if the element contains "content".
|
|
81
|
-
# Valid values are:
|
|
82
|
-
# - true: content available and necessary (e.g. <p>)
|
|
83
|
-
# - :empty_ok: content available, but not necessary (e.g. <td> or iframe)
|
|
84
|
-
# - false: no content, no endtag, but tag closed with / (example: <br />)
|
|
85
|
-
# - nil: no content, no endtag, no closing (example: <br>)
|
|
86
|
-
#- output contains a hash with logic, how to handle the output.
|
|
87
|
-
# -:htmltag Tag for html-output.
|
|
88
|
-
# -:latex Template for LaTeX-output
|
|
89
|
-
# -:html Template for HTML-output
|
|
90
|
-
def Element.create( name, attr = {}, content = false, output = {} )
|
|
91
|
-
#First some checks
|
|
92
|
-
if ! attr.kind_of?( Hash )
|
|
93
|
-
raise "Type error Element.create: Expected Hash, get #{attr.class}"
|
|
94
|
-
end
|
|
95
|
-
#Generic class creation
|
|
96
|
-
elementclass = Class.new( Element )
|
|
97
|
-
#Add the id of the new class to central collection.
|
|
98
|
-
Element.add( name, elementclass )
|
|
99
|
-
|
|
100
|
-
#Set a flag, if the class can contain 'content'.
|
|
101
|
-
#-true: content available and necessary (e.g. <p>)
|
|
102
|
-
#-:empty_ok: content available, but not necessary (e.g. <td>)
|
|
103
|
-
#-false: no content, no endtag, but tag closed with / (example: <br />)
|
|
104
|
-
#-nil: no content, no endtag, no closing (example: <br>)
|
|
105
|
-
elementclass.class_eval( %Q|
|
|
106
|
-
def content?()
|
|
107
|
-
return #{content.inspect}
|
|
108
|
-
end|)
|
|
109
|
-
|
|
110
|
-
output.each{ |k,v|
|
|
111
|
-
case k
|
|
112
|
-
when :latex
|
|
113
|
-
elementclass.add_output( :latex, v )
|
|
114
|
-
when :context
|
|
115
|
-
elementclass.add_output( :context, v )
|
|
116
|
-
when :html
|
|
117
|
-
elementclass.add_output( :html, v )
|
|
118
|
-
when :text
|
|
119
|
-
elementclass.add_output( :text, v )
|
|
120
|
-
when :wiki
|
|
121
|
-
elementclass.add_output( :wiki, v )
|
|
122
|
-
when :creole
|
|
123
|
-
elementclass.add_output( :creole, v )
|
|
124
|
-
when :htmltag
|
|
125
|
-
if v
|
|
126
|
-
elementclass.class_eval( "def htmltag()\n'#{v}'\nend" )
|
|
127
|
-
else
|
|
128
|
-
elementclass.class_eval( "def htmltag()\nnil\nend" )
|
|
129
|
-
end
|
|
130
|
-
else
|
|
131
|
-
puts "#{__FILE__}##{__LINE__}: Unknown format #{k} for #{name}"
|
|
132
|
-
end
|
|
133
|
-
}
|
|
134
|
-
elementclass.add_attributes( attr )
|
|
135
|
-
#Return the class.
|
|
136
|
-
return elementclass
|
|
137
|
-
end
|
|
138
|
-
#Return all id's of the class.
|
|
139
|
-
#@@ids is expanded in Element.add.
|
|
140
|
-
def ids( )
|
|
141
|
-
myids = []
|
|
142
|
-
@@ids.each{|k,v| myids << k if v == self.class and k.class != Class }
|
|
143
|
-
return myids
|
|
144
|
-
end
|
|
145
|
-
#Prepares an overview on all Elements.
|
|
146
|
-
#Can be used for some debugging.
|
|
147
|
-
def Element.overview( list = @@ids.values.uniq )
|
|
148
|
-
if ! list.kind_of?(Array)
|
|
149
|
-
list = [ list ]
|
|
150
|
-
end
|
|
151
|
-
result = '=' * 10 + "\nElement overview:"
|
|
152
|
-
list.each{ |k|
|
|
153
|
-
result += "\n#{k}\n"
|
|
154
|
-
result += "\tId's:\t\t"
|
|
155
|
-
result += k.new.ids.join("\n\t\t\t")
|
|
156
|
-
result += "\n\tAttributes:\t"
|
|
157
|
-
result += "can contain "
|
|
158
|
-
result += "no " if ! k.new.content?
|
|
159
|
-
result += "content\n\t\t\t"
|
|
160
|
-
@@attr[k].each{ |k2,v|
|
|
161
|
-
result += "#{k2}:\t#{v.inspect}\n\t\t\t"
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result
|
|
165
|
-
end
|
|
166
|
-
#Add possible attributes to an element class.
|
|
167
|
-
#Attributes are defined in a hash, each key get a array with values.
|
|
168
|
-
#The values can be:
|
|
169
|
-
#- OBLIGATORY/OPTIONAL
|
|
170
|
-
#- Alias (this allows the usage of a position and a name for a parameter).
|
|
171
|
-
#- allowed elements ( e.g. list content only list items)
|
|
172
|
-
#Problem: Attributes are not inherited. See Element.get_attribute_list
|
|
173
|
-
#
|
|
174
|
-
#This method is called from a subclass.
|
|
175
|
-
#Fixme: add_attributes overwrites everything.
|
|
176
|
-
def Element.add_attributes( attr )
|
|
177
|
-
elattr = @@attr[self] #self is the class
|
|
178
|
-
attr.each{ |k,a |
|
|
179
|
-
elattr[k] = a
|
|
180
|
-
}
|
|
181
|
-
end
|
|
182
|
-
#Returns list of attributes.
|
|
183
|
-
#Can be used for copying attributes from one class to another class.
|
|
184
|
-
def Element.get_attribute_list( elementclass )
|
|
185
|
-
return @@attr[elementclass]
|
|
186
|
-
end
|
|
187
|
-
#Add an output routine.
|
|
188
|
-
def Element.add_output( target, string )
|
|
189
|
-
case target
|
|
190
|
-
when :latex
|
|
191
|
-
cmd = "def to_latex(options = {})\n"
|
|
192
|
-
when :context
|
|
193
|
-
cmd = "def to_context(options = {})\n"
|
|
194
|
-
when :html
|
|
195
|
-
cmd = "def to_html(options = {})\n"
|
|
196
|
-
when :text
|
|
197
|
-
cmd = "def to_text(options = {})\n"
|
|
198
|
-
when :wiki
|
|
199
|
-
cmd = "def to_wiki(options = {})\n"
|
|
200
|
-
when :creole
|
|
201
|
-
cmd = "def to_creole(options = {})\n"
|
|
202
|
-
else
|
|
203
|
-
puts "#{self}: Undefined target format #{target}"
|
|
204
|
-
end
|
|
205
|
-
if ! string.kind_of?( String )
|
|
206
|
-
puts "Error element <#{self.new.ids}>: #{string.inspect} is no String"
|
|
207
|
-
end
|
|
208
|
-
cmd << <<code
|
|
209
|
-
o = Docgenerator_logger.set_option_defaults(options)
|
|
210
|
-
o[:log].debug("enter to_doc(#{target}) for #{self.inspect}, options: \#{options.keys.inspect}") if o[:log].debug?
|
|
211
|
-
code
|
|
212
|
-
template = string.gsub(/\\/, '\\\\\\')
|
|
213
|
-
template.gsub!(/"/, '\"')
|
|
214
|
-
template.gsub!(/@content\}/, "@content.to_doc(#{target.inspect}, o)}")
|
|
215
|
-
cmd << " \"#{template}\"\n"
|
|
216
|
-
cmd << "end\n"
|
|
217
|
-
class_eval( cmd )
|
|
218
|
-
cmd #return cmd for unit test
|
|
219
|
-
end
|
|
220
|
-
#Defines an element.
|
|
221
|
-
#
|
|
222
|
-
#There are two ways to add values:
|
|
223
|
-
#- "named" values in an hash.
|
|
224
|
-
# This named values can be attributes of a HTML-Tag or Parameters of a TeX-Makro.
|
|
225
|
-
# There is a check, if the attribute exist.
|
|
226
|
-
#- Content. Values "inside" the element.
|
|
227
|
-
# The content can be the content of a HTML-Tag or the content of a TeX-Environment.
|
|
228
|
-
# There is a check, if this class allows content.
|
|
229
|
-
#:log is the default attribute for the logger.
|
|
230
|
-
#In Element#to_doc you can give another logger!
|
|
26
|
+
=begin rdoc
|
|
27
|
+
Defines an element.
|
|
28
|
+
|
|
29
|
+
There are two ways to add values:
|
|
30
|
+
- "named" values in an hash.
|
|
31
|
+
This named values can be attributes of a HTML-Tag or Parameters of a TeX-Makro.
|
|
32
|
+
There is a check, if the attribute exist.
|
|
33
|
+
- Content. Values "inside" the element.
|
|
34
|
+
The content can be the content of a HTML-Tag or the content of a TeX-Environment.
|
|
35
|
+
There is a check, if this class allows content.
|
|
36
|
+
:log is the default attribute for the logger.
|
|
37
|
+
In Elementto_doc you can give another logger!
|
|
38
|
+
=end
|
|
231
39
|
def initialize( attr={}, content = nil)
|
|
232
40
|
#@attr is a hash containing the values for each attribute.
|
|
233
41
|
@attr = Hash.new( )
|
|
234
|
-
#~ @log = DOCGENERATOR_LOGGER
|
|
235
42
|
#Attention! in to_doc another logger may be given.
|
|
236
|
-
@log = attr[:log]
|
|
43
|
+
@log = attr[:log] || DOCGENERATOR_DEFAULT_LOGGER
|
|
237
44
|
attr.delete(:log) #remove from attr-interface
|
|
238
45
|
#attr alias
|
|
239
46
|
@attr_alias = Hash.new( )
|
|
@@ -252,7 +59,7 @@ code
|
|
|
252
59
|
@suppressed_targets = []
|
|
253
60
|
|
|
254
61
|
#Initialize the attribute hash.
|
|
255
|
-
|
|
62
|
+
self.class.attributes.each{ |k,a|
|
|
256
63
|
#type check on Attribute does not work .
|
|
257
64
|
if a.kind_of?( Symbol )
|
|
258
65
|
#Filled in the second run
|
|
@@ -264,7 +71,7 @@ code
|
|
|
264
71
|
end
|
|
265
72
|
}
|
|
266
73
|
#Assign Alias-Attributes
|
|
267
|
-
|
|
74
|
+
self.class.attributes.each{ |k,a|
|
|
268
75
|
next if !a.kind_of?( Symbol )
|
|
269
76
|
if @attr[a]
|
|
270
77
|
@attr_alias[k] = @attr[a]
|
|
@@ -279,20 +86,59 @@ code
|
|
|
279
86
|
elsif @attr_alias[k]
|
|
280
87
|
@attr_alias[k] << v
|
|
281
88
|
else
|
|
282
|
-
@log.warn("Usage of unknown attribute '#{k}' in
|
|
89
|
+
@log.warn("Usage of unknown attribute '#{k}' in #{self.inspect}") if @log.warn?
|
|
90
|
+
#~ @log.debug(caller) if @log.debug?
|
|
283
91
|
end
|
|
284
92
|
}
|
|
285
|
-
|
|
93
|
+
#store info, where the element was created
|
|
94
|
+
@creation_caller = prepare_tracing_info() if Docgenerator.trace_on?
|
|
286
95
|
self << content if content
|
|
287
96
|
end
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
97
|
+
=begin rdoc
|
|
98
|
+
Only for debbuging reasons.
|
|
99
|
+
|
|
100
|
+
This method analyse the caller-stack and provides
|
|
101
|
+
the first "no lib/docgenerator-place".
|
|
102
|
+
This should be the location, where the element is created.
|
|
103
|
+
|
|
104
|
+
Via Element#inspect you get access to this information.
|
|
105
|
+
=end
|
|
106
|
+
def prepare_tracing_info()
|
|
107
|
+
caller().each{|c|
|
|
108
|
+
next if ( /lib\/(docgenerator|creole|wiki2doc)/ =~ c )
|
|
109
|
+
return c
|
|
110
|
+
}
|
|
111
|
+
#--> No calling stack outside lib/docgenerator found --> Error
|
|
112
|
+
@log.error('Element#prepare_tracing_info: Found no starting place in caller stack') if @log.error?
|
|
113
|
+
caller().each{|c| @log.debug("\t#{c}") } if @log.debug?
|
|
114
|
+
return caller()
|
|
115
|
+
end
|
|
116
|
+
=begin rdoc
|
|
117
|
+
Set a text for the inspect command.
|
|
118
|
+
|
|
119
|
+
Nil if the information was not collected at Element#new.
|
|
120
|
+
=end
|
|
121
|
+
def inspect_creation_caller
|
|
122
|
+
if @creation_caller
|
|
123
|
+
", created at #{@creation_caller}"
|
|
124
|
+
else
|
|
125
|
+
nil #'unknown. Please set Elements.trace if needed'
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
def inspect()
|
|
129
|
+
return "<#{self.class}#{inspect_creation_caller}>"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
=begin rdoc
|
|
133
|
+
List (array) of targets, where the element can be used.
|
|
134
|
+
Default are all supported targets.
|
|
135
|
+
|
|
136
|
+
With restrictions of this attribute, elements can be restricted on special documents.
|
|
137
|
+
=end
|
|
292
138
|
def restrict_to( *argv )
|
|
293
139
|
@targets = []
|
|
294
140
|
@suppressed_targets = SUPPORTED_TARGETS.dup
|
|
295
|
-
@log.
|
|
141
|
+
@log.info("Element#restrict_to: #{self.inspect} restrict to #{argv.inspect}") if @log.warn?
|
|
296
142
|
argv.each{ |arg|
|
|
297
143
|
#~ if ! SUPPORTED_TARGETS.include?( arg )
|
|
298
144
|
if ! @suppressed_targets.delete( arg )
|
|
@@ -302,149 +148,176 @@ code
|
|
|
302
148
|
}
|
|
303
149
|
self
|
|
304
150
|
end
|
|
305
|
-
#Only for debbuging reasons.
|
|
306
|
-
#Should contain the first "no docgenerator.rb-place, where part is called
|
|
307
|
-
#if @@trace is on, some tracing information is stored during creation.
|
|
308
|
-
def prepare_tracing_info( doit = @@trace )
|
|
309
|
-
return nil if ! doit
|
|
310
|
-
caller().each{|c|
|
|
311
|
-
next if ( /DocumentGenerator/ =~ c )
|
|
312
|
-
return c
|
|
313
|
-
}
|
|
314
|
-
#--> No calling stack found --> Error
|
|
315
|
-
puts '----'*10
|
|
316
|
-
puts 'Element#prepare_tracing_info: Found no starting place in caller stack'
|
|
317
|
-
caller().each{|c| puts c }
|
|
318
|
-
puts '----'*10
|
|
319
|
-
return caller()
|
|
320
|
-
end
|
|
321
|
-
def inspect()
|
|
322
|
-
if @@trace
|
|
323
|
-
called_by = ", Created in #{@called_by}"
|
|
324
|
-
else
|
|
325
|
-
called_by = nil #'unknown. Please set Elements.trace if needed'
|
|
326
|
-
end
|
|
327
|
-
return "<Class Element(#{self.ids.join(',')})#{called_by}>"
|
|
328
|
-
#~ if @content
|
|
329
|
-
#~ return "<Class Element(#{self.ids.join(',')}) @content=#{@content.inspect}>"
|
|
330
|
-
#~ else
|
|
331
|
-
#~ return "<Class Element(#{self.ids.join(',')}) @attr=#{@attr.inspect}>"
|
|
332
|
-
#~ end
|
|
333
|
-
end
|
|
334
151
|
#Accessor on content
|
|
335
152
|
attr_reader :content
|
|
336
|
-
#
|
|
337
|
-
|
|
153
|
+
#Logger of the element
|
|
154
|
+
attr_reader :log
|
|
155
|
+
=begin rdoc
|
|
156
|
+
Add something to the content.
|
|
157
|
+
Only possible on elements, which supports "content".
|
|
158
|
+
=end
|
|
338
159
|
def << ( content )
|
|
339
160
|
if @content
|
|
340
161
|
@content << content
|
|
341
162
|
else
|
|
342
|
-
@log.warn("Add content to an element without this feature #{self.
|
|
163
|
+
@log.warn("Add content to an element without this feature #{self.inspect}, #{content.inspect}") if @log.warn?
|
|
343
164
|
end
|
|
344
165
|
end
|
|
345
166
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
167
|
+
=begin rdoc
|
|
168
|
+
Add content after a target (other content)
|
|
169
|
+
insertafter(target,*obj)
|
|
170
|
+
Requires the ability of "content".
|
|
171
|
+
=end
|
|
172
|
+
def insertafter(target,*obj)
|
|
173
|
+
self.insert(target, 1, obj)
|
|
174
|
+
end
|
|
175
|
+
=begin rdoc
|
|
176
|
+
Add content before a target (other content)
|
|
177
|
+
insertbefore(target,*obj)
|
|
178
|
+
Requires the ability of "content".
|
|
179
|
+
=end
|
|
180
|
+
def insertbefore(target,*obj)
|
|
181
|
+
self.insert(target, 0, obj)
|
|
182
|
+
end
|
|
183
|
+
=begin rdoc
|
|
184
|
+
Insert content relative to a given target.
|
|
185
|
+
The target must exist, pos defines the relative position (0=before, 1=one after the element).
|
|
186
|
+
Method called by Element#insertbefore and Element#insertafter.
|
|
187
|
+
=end
|
|
361
188
|
def insert(target,pos,*obj )
|
|
362
189
|
if @content
|
|
363
190
|
if @content.include?( target )
|
|
364
191
|
@content[@content.index(target)+pos ,0] = obj
|
|
365
192
|
else
|
|
366
193
|
@log.warn("Insert content not possible. Reference object does not exist (#{target.inspect})") if @log.warn?
|
|
367
|
-
end
|
|
194
|
+
end
|
|
368
195
|
else
|
|
369
196
|
@log.warn("Add content to an element without this feature") if @log.warn?
|
|
370
197
|
end
|
|
371
|
-
self
|
|
198
|
+
self
|
|
372
199
|
end
|
|
373
|
-
|
|
200
|
+
=begin rdoc
|
|
201
|
+
Delete the given object from content.
|
|
202
|
+
=end
|
|
374
203
|
def delete(target )
|
|
375
204
|
if @content
|
|
376
205
|
@content.delete( target )
|
|
377
206
|
else
|
|
378
207
|
@log.warn("Delete content of an element without this feature") if @log.warn?
|
|
379
208
|
end
|
|
380
|
-
self
|
|
209
|
+
self
|
|
381
210
|
end
|
|
382
|
-
|
|
211
|
+
=begin rdoc
|
|
212
|
+
Insert an empty line after the last entry.
|
|
213
|
+
|
|
214
|
+
Example:
|
|
215
|
+
<tag>content</tag>[CR]
|
|
216
|
+
=end
|
|
383
217
|
def cr()
|
|
384
218
|
@crafter = true
|
|
385
219
|
self
|
|
386
220
|
end
|
|
387
|
-
|
|
221
|
+
=begin rdoc
|
|
222
|
+
Insert an empty line before and after the last entry.
|
|
223
|
+
|
|
224
|
+
Example:
|
|
225
|
+
[CR]<tag>content</tag>[CR]
|
|
226
|
+
=end
|
|
388
227
|
def Cr()
|
|
389
228
|
@crbefore = true
|
|
390
229
|
@crafter = true
|
|
391
230
|
self
|
|
392
231
|
end
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
232
|
+
=begin rdoc
|
|
233
|
+
Insert an empty line after the last entry and after the opening of the tag.
|
|
234
|
+
|
|
235
|
+
Example:
|
|
236
|
+
<tag>[CR]content</tag>[CR]
|
|
237
|
+
|
|
238
|
+
This feature has it reason for lists, when each :li-tag gets a cr.
|
|
239
|
+
The first item gets also a cR.
|
|
240
|
+
|
|
241
|
+
Example:
|
|
242
|
+
<ul>
|
|
243
|
+
<li>item with cR</li>
|
|
244
|
+
<li>item with cr</li>
|
|
245
|
+
</ul>
|
|
246
|
+
=end
|
|
396
247
|
def cR()
|
|
397
248
|
@crbefore = false
|
|
398
249
|
@crmid = true
|
|
399
250
|
@crafter = true
|
|
400
251
|
self
|
|
401
252
|
end
|
|
402
|
-
|
|
253
|
+
=begin rdoc
|
|
254
|
+
Insert an empty line before and after the last entry and after the opening of the tag.
|
|
255
|
+
|
|
256
|
+
Example:
|
|
257
|
+
[CR]<tag>[CR]content</tag>[CR]
|
|
258
|
+
=end
|
|
403
259
|
def CR()
|
|
404
260
|
@crbefore = true
|
|
405
261
|
@crmid = true
|
|
406
262
|
@crafter = true
|
|
407
263
|
self
|
|
408
264
|
end
|
|
409
|
-
|
|
265
|
+
=begin rdoc
|
|
266
|
+
Accessor on attribute list
|
|
267
|
+
=end
|
|
410
268
|
attr_reader :attr
|
|
411
|
-
|
|
269
|
+
=begin rdoc
|
|
270
|
+
Return an attribute to add content.
|
|
271
|
+
|
|
272
|
+
Example:
|
|
273
|
+
sec = element(:section, {}, 'title' )
|
|
274
|
+
sec[:shorttitle] << 'shorttitle'
|
|
275
|
+
|
|
276
|
+
Normally, this is the better solution:
|
|
277
|
+
sec = element(:section, { :shorttitle => 'shorttitle'}, 'title' )
|
|
278
|
+
=end
|
|
412
279
|
def [] (key)
|
|
413
280
|
attr = @attr[key]
|
|
414
281
|
#If Attribute does not exist, take a look, if it is an alias-name.
|
|
415
282
|
attr = @attr_alias[key] if !attr
|
|
416
|
-
if !attr
|
|
417
|
-
|
|
283
|
+
if ! attr
|
|
284
|
+
@log.warn("Request unknown attribute '#{key}', return a dummy (#{self.inspect})") if @log.warn?
|
|
418
285
|
attr = Attribute.create( ).new(key, self)
|
|
419
286
|
end
|
|
420
287
|
return attr
|
|
421
288
|
end
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
289
|
+
=begin rdoc
|
|
290
|
+
Default setting, each element class may contain contents.
|
|
291
|
+
Can be redefined by meta-method Elements.has_no_content
|
|
292
|
+
- true: content available and necessary (e.g. Docgenerator::Elements::Paragraph)
|
|
293
|
+
- :empty_ok: content available, but not necessary (e.g. Docgenerator::Tables::Column)
|
|
294
|
+
- false: no content, no endtag, but tag closed with / (example: Docgenerator::Elements::Newline as < br/>)
|
|
295
|
+
- nil: no content, no endtag, no closing (example: Docgenerator::Elements::Newline as < br>)
|
|
296
|
+
=end
|
|
428
297
|
def content?()
|
|
429
298
|
return true
|
|
430
299
|
end
|
|
431
|
-
|
|
300
|
+
=begin rdoc
|
|
301
|
+
check if there is content assigned.
|
|
302
|
+
=end
|
|
432
303
|
def empty?()
|
|
433
304
|
return @content.empty?
|
|
434
305
|
end
|
|
435
306
|
@@level = 0
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
307
|
+
=begin rdoc
|
|
308
|
+
Build a String to be used for the target document.
|
|
309
|
+
Calls
|
|
310
|
+
* Element#to_latex (target :latex),
|
|
311
|
+
* Element#to_context (target :context)
|
|
312
|
+
* Element#to_html (target :html)
|
|
313
|
+
* Element#to_wiki (target :wiki) (support stopped)
|
|
314
|
+
* Element#to_creole (target :creole) (not really good results)
|
|
315
|
+
* Element#to_text (target :text) (not really good results)
|
|
316
|
+
|
|
317
|
+
Via the options-hash, you can transport additional information.
|
|
318
|
+
=end
|
|
446
319
|
def to_doc( target, options = {} )
|
|
447
|
-
o =
|
|
320
|
+
o = set_option_defaults(options)
|
|
448
321
|
o[:log].debug("enter to_doc(#{target}) for #{self.inspect}, options: #{options.keys.inspect}") if o[:log].debug?
|
|
449
322
|
#Return empty string, if target is not requested.
|
|
450
323
|
if ! @targets.include?( target )
|
|
@@ -458,7 +331,7 @@ code
|
|
|
458
331
|
#Some checks
|
|
459
332
|
@attr.each{|k,v|
|
|
460
333
|
if v.required? and v.to_s == '' and v.settings.include?(target)
|
|
461
|
-
o[:log].error "#{self.
|
|
334
|
+
o[:log].error "#{self.inspect}: Attribut '#{k}' without required value" if o[:log].error?
|
|
462
335
|
end
|
|
463
336
|
}
|
|
464
337
|
#Build the string.
|
|
@@ -485,82 +358,131 @@ code
|
|
|
485
358
|
#~ result << "\n" if @crafter
|
|
486
359
|
return result
|
|
487
360
|
end
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
361
|
+
=begin rdoc
|
|
362
|
+
This is a dummy method, called from Element#to_s for the target format LaTeX.
|
|
363
|
+
This method must be overwritten from the element class.
|
|
364
|
+
|
|
365
|
+
By default, the concatenation of all ids and the content is taken.
|
|
366
|
+
=end
|
|
492
367
|
def to_latex(options = {})
|
|
493
|
-
o =
|
|
494
|
-
o[:log].error("Missing output routine for LaTeX (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
|
|
368
|
+
o = set_option_defaults(options)
|
|
495
369
|
makroname = 'dummy'
|
|
496
|
-
self.
|
|
370
|
+
self.element_ids.each{|id|
|
|
497
371
|
makroname = id if id.is_a?(Symbol) or id.is_a?(String)
|
|
498
372
|
}
|
|
373
|
+
o[:log].error("Missing output routine for LaTeX, use \\#{makroname} (#{self.inspect})")
|
|
499
374
|
cmd = ''
|
|
500
375
|
cmd << "\n" if @crbefore
|
|
501
|
-
cmd << "\\#{makroname}{#{@content}}"
|
|
376
|
+
cmd << "\\#{makroname}{#{@content.to_latex(options)}}"
|
|
502
377
|
cmd << "\n" if @crafter
|
|
503
378
|
return cmd
|
|
504
379
|
end
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
380
|
+
=begin rdoc
|
|
381
|
+
Create context-output.
|
|
382
|
+
|
|
383
|
+
ConTeXt-support is added later and there are a lot of gaps (2009-07-01)
|
|
384
|
+
=end
|
|
508
385
|
def to_context(options = {})
|
|
509
|
-
o =
|
|
510
|
-
o[:log].error("Missing output routine for ConTeXt (#{self.ids.join(',')}) [#{@called_by}]") if o[:log].error?
|
|
386
|
+
o = set_option_defaults(options)
|
|
511
387
|
makroname = 'dummy'
|
|
512
|
-
self.
|
|
388
|
+
self.element_ids.each{|id|
|
|
513
389
|
makroname = id if id.is_a?(Symbol) or id.is_a?(String)
|
|
514
390
|
}
|
|
391
|
+
o[:log].error("Missing output routine for ConTeXt, use \\#{makroname} (#{self.inspect})")
|
|
392
|
+
|
|
515
393
|
cmd = ''
|
|
516
394
|
cmd << "\n" if @crbefore
|
|
517
|
-
cmd << "\\#{makroname}{#{@content}}"
|
|
395
|
+
cmd << "\\#{makroname}{#{@content.to_context(options)}}"
|
|
518
396
|
cmd << "\n" if @crafter
|
|
519
397
|
return cmd
|
|
520
398
|
end
|
|
521
|
-
|
|
399
|
+
=begin rdoc
|
|
400
|
+
Method for definition inside Element.create.
|
|
401
|
+
=end
|
|
522
402
|
def linebreak( flag = true )
|
|
523
403
|
flag ? "\n" : ''
|
|
524
404
|
end
|
|
525
|
-
|
|
405
|
+
=begin rdoc
|
|
406
|
+
Prints the optional attribut key inside []. If empty, nil is returned
|
|
407
|
+
=end
|
|
526
408
|
def texoptional(key)
|
|
527
|
-
return nil
|
|
409
|
+
return nil unless @attr[key].filled?
|
|
528
410
|
return "[#{@attr[key]}]"
|
|
529
411
|
end
|
|
530
|
-
|
|
531
|
-
|
|
412
|
+
=begin rdoc
|
|
413
|
+
Build key-val options from attributs.
|
|
414
|
+
Used e.g. by includegraphics.
|
|
415
|
+
|
|
416
|
+
If the value is true, the value is added without '='.
|
|
417
|
+
false-values are ignored.
|
|
418
|
+
|
|
419
|
+
If you need a "value=true", then add 'true' as a string.
|
|
420
|
+
|
|
421
|
+
Example (Packages::IncludePDF):
|
|
422
|
+
class IncludePDF < Element
|
|
423
|
+
add_attribute :pages, Attribute.create( [ :texkeyval], [ String ] )
|
|
424
|
+
add_attribute :nup, Attribute.create( [ :texkeyval], [ /\d+x\d+/ ] ) #multiple logical pages onto each sheet of paper.
|
|
425
|
+
add_attribute :landscape, Attribute.create( [ :texkeyval], [ true, false ] ) #multiple logical pages onto each sheet of paper.
|
|
426
|
+
#...
|
|
427
|
+
add_output( :latex, '#{linebreak(@crbefore)}\includepdf[#{texkeyval()}]{#{@content}}#{linebreak(@crafter)}')
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
x = element(:includepdf, { :pages => '1-5', :nup => '2x2', :landscape => true }, 'filename')
|
|
431
|
+
puts x.texkeyval #pages={1-5}, nup={2x2}, landscape
|
|
432
|
+
|
|
433
|
+
x = element(:includepdf, { :pages => '1-5', :nup => '2x2', :landscape => false }, 'filename')
|
|
434
|
+
puts x.texkeyval #pages={1-5}, nup={2x2}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
=end
|
|
532
438
|
def texkeyval()
|
|
533
439
|
keyval = []
|
|
534
440
|
@attr.sort_by{|k,v| v.sortkey }.each{|k,v|
|
|
535
|
-
|
|
441
|
+
next unless v.texkeyval?
|
|
442
|
+
case v.content
|
|
443
|
+
when true, [true]; keyval << "#{k}"
|
|
444
|
+
when false, [false] #ignore
|
|
445
|
+
else #take the value
|
|
446
|
+
keyval << "#{k}={#{v}}" unless v.to_s.empty?
|
|
447
|
+
end
|
|
536
448
|
}
|
|
537
449
|
return keyval.join(', ')
|
|
538
450
|
end
|
|
539
|
-
|
|
540
|
-
|
|
451
|
+
=begin rdoc
|
|
452
|
+
Define the tag for html-output.
|
|
453
|
+
|
|
454
|
+
If the method is redefined, the result is taken as a tag.
|
|
455
|
+
Redfinition is made by Element.add_html_tag.
|
|
456
|
+
|
|
457
|
+
htmltag nil/false supress the output.
|
|
458
|
+
=end
|
|
541
459
|
def htmltag()
|
|
542
460
|
''
|
|
543
461
|
end
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
462
|
+
=begin rdoc
|
|
463
|
+
This is a dummy method, called from Element#to_doc for the target format HTML.
|
|
464
|
+
|
|
465
|
+
The tag from Element#htmltag is taken and all attributes and the content are used.
|
|
466
|
+
If Element#htmltag is nil/false, nothing '' is returned.
|
|
467
|
+
|
|
468
|
+
This method can be overwritten from the element class.
|
|
469
|
+
=end
|
|
548
470
|
def to_html(options = {})
|
|
549
|
-
o =
|
|
471
|
+
o = set_option_defaults(options)
|
|
550
472
|
tag = htmltag()
|
|
551
473
|
if ! tag
|
|
552
|
-
o[:log].error("No HTML element available (#{self.
|
|
474
|
+
o[:log].error("No HTML element available (#{self.inspect})") if o[:log].error?
|
|
553
475
|
return ''
|
|
554
476
|
elsif tag == ''
|
|
555
477
|
tag = 'span'
|
|
556
|
-
o[:log].error("Missing output routine for HTML (#{self.
|
|
478
|
+
o[:log].error("Missing output routine for HTML (#{self.inspect})") if o[:log].error?
|
|
557
479
|
end
|
|
558
480
|
#Test if the HTML-Tag should contain something, but there is nothing.
|
|
559
481
|
#If :empty_ok it is ok, that there is no content (e.g <td>)
|
|
560
482
|
#May make problems, if an empty tag is used to set a id-mark.
|
|
561
483
|
if content?() and content? != :empty_ok and
|
|
562
484
|
( ! @content or @content == [] or @content == [nil] )
|
|
563
|
-
o[:log].warn("HTML-Tag #{tag} without content -> ignored #{self.inspect
|
|
485
|
+
o[:log].warn("HTML-Tag #{tag} without content -> ignored #{self.inspect}") if o[:log].warn?
|
|
564
486
|
return ''
|
|
565
487
|
end
|
|
566
488
|
html = String.new()
|
|
@@ -583,19 +505,29 @@ code
|
|
|
583
505
|
html << "\n" if @crafter
|
|
584
506
|
return html
|
|
585
507
|
end #to_html
|
|
508
|
+
=begin rdoc
|
|
509
|
+
Return content in Wikimedia-Syntax.
|
|
510
|
+
Support stopped.
|
|
511
|
+
=end
|
|
586
512
|
def to_wiki(options = {})
|
|
587
|
-
o =
|
|
588
|
-
o[:log].error("Missing output routine for Wiki (#{self.
|
|
513
|
+
o = set_option_defaults(options)
|
|
514
|
+
o[:log].error("Missing output routine for Wiki (#{self.inspect})") if o[:log].error?
|
|
589
515
|
return "#{@content.to_wiki(options)}\n"
|
|
590
516
|
end
|
|
517
|
+
=begin rdoc
|
|
518
|
+
Return content in creole-Syntax.
|
|
519
|
+
=end
|
|
591
520
|
def to_creole(options = {})
|
|
592
|
-
o =
|
|
593
|
-
o[:log].error("Missing output routine for creole (#{self.
|
|
521
|
+
o = set_option_defaults(options)
|
|
522
|
+
o[:log].error("Missing output routine for creole (#{self.inspect})") if o[:log].error?
|
|
594
523
|
return "#{@content.to_creole(options)}\n"
|
|
595
524
|
end
|
|
525
|
+
=begin rdoc
|
|
526
|
+
Make an Text-Representation of the content.
|
|
527
|
+
=end
|
|
596
528
|
def to_text(options = {})
|
|
597
|
-
o =
|
|
598
|
-
o[:log].error("Missing output routine for Text (#{self.
|
|
529
|
+
o = set_option_defaults(options)
|
|
530
|
+
o[:log].error("Missing output routine for Text (#{self.inspect})") if o[:log].error?
|
|
599
531
|
text = String.new()
|
|
600
532
|
text << "\n" if @crbefore
|
|
601
533
|
text = "#{@content.to_text(options)}".strip
|
|
@@ -605,4 +537,25 @@ code
|
|
|
605
537
|
def to_s()
|
|
606
538
|
return self.inspect
|
|
607
539
|
end
|
|
608
|
-
end #Element
|
|
540
|
+
end #Element
|
|
541
|
+
end #module Docgenerator
|
|
542
|
+
|
|
543
|
+
=begin rdoc
|
|
544
|
+
Returns an element of a type "name".
|
|
545
|
+
Attributes and content are optional parameter.
|
|
546
|
+
|
|
547
|
+
This method is defined global (outside Docgenerator-module)
|
|
548
|
+
|
|
549
|
+
If you call element with an undefined 'name',
|
|
550
|
+
you get an error message and an anonymous dummy class is created.
|
|
551
|
+
=end
|
|
552
|
+
def element( name, attr = {}, content = nil )
|
|
553
|
+
elementclass = Docgenerator::Element.get( name )
|
|
554
|
+
if ! elementclass #Create a dummy element.
|
|
555
|
+
#~ element = Docgenerator::Element.create( name, {}, true ).new(attr, content )
|
|
556
|
+
Docgenerator::DOCGENERATOR_LOGGER.error( "Usage of undefined element #{name}. Create an anonymous class")
|
|
557
|
+
elementclass = Class.new(Docgenerator::Element)
|
|
558
|
+
elementclass.add_id name
|
|
559
|
+
end
|
|
560
|
+
return elementclass.new(attr, content )
|
|
561
|
+
end
|