deplate 0.7.3 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/AUTHORS.TXT +3 -0
  2. data/CHANGES.TXT +248 -175
  3. data/LICENSE.TXT +0 -0
  4. data/NEWS.TXT +28 -24
  5. data/README.TXT +0 -0
  6. data/TODO.TXT +174 -88
  7. data/VERSION.TXT +1 -1
  8. data/bin/deplate +0 -0
  9. data/bin/deplate.bat +0 -0
  10. data/etc/deplate.ini +91 -3
  11. data/lib/action_view/helpers/deplate.rb +45 -0
  12. data/lib/deplate.rb +6 -1
  13. data/lib/deplate/abstract-class.rb +0 -0
  14. data/lib/deplate/bib.rb +576 -0
  15. data/lib/deplate/builtin.rb +0 -0
  16. data/lib/deplate/cache.rb +55 -5
  17. data/lib/deplate/commands.rb +346 -183
  18. data/lib/deplate/common.rb +209 -48
  19. data/lib/deplate/converter.rb +12 -6
  20. data/lib/deplate/core.rb +777 -378
  21. data/lib/deplate/counters.rb +254 -0
  22. data/lib/deplate/css/article.css +4 -3
  23. data/lib/deplate/css/deplate.css +121 -5
  24. data/lib/deplate/css/heading-navbar.css +0 -0
  25. data/lib/deplate/css/layout-deplate-print.css +0 -0
  26. data/lib/deplate/css/layout-deplate.css +0 -0
  27. data/lib/deplate/css/sans-serif.css +0 -0
  28. data/lib/deplate/css/serif-e.css +0 -0
  29. data/lib/deplate/css/serif-rel.css +0 -0
  30. data/lib/deplate/css/serif.css +9 -3
  31. data/lib/deplate/css/slides.css +0 -0
  32. data/lib/deplate/css/tabbar-left.css +0 -0
  33. data/lib/deplate/css/tabbar-right-ie.css +3 -9
  34. data/lib/deplate/css/tabbar-right.css +51 -18
  35. data/lib/deplate/css/tabbar-top.css +7 -1
  36. data/lib/deplate/css/tabbar.css +0 -0
  37. data/lib/deplate/css/text-sans-serif.css +0 -0
  38. data/lib/deplate/css/text-serif.css +0 -0
  39. data/lib/deplate/define.rb +183 -177
  40. data/lib/deplate/deplate-string.rb +82 -0
  41. data/lib/deplate/docbook.rb +236 -128
  42. data/lib/deplate/elements.rb +584 -417
  43. data/lib/deplate/etc.rb +163 -101
  44. data/lib/deplate/external.rb +42 -11
  45. data/lib/deplate/fmt/dbk-article-4.1.2.rb +0 -0
  46. data/lib/deplate/fmt/dbk-article.rb +0 -0
  47. data/lib/deplate/fmt/dbk-book.rb +0 -0
  48. data/lib/deplate/fmt/dbk-ref.rb +3 -3
  49. data/lib/deplate/fmt/dbk-slides.rb +0 -0
  50. data/lib/deplate/fmt/dbk-snippet.rb +0 -0
  51. data/lib/deplate/fmt/html-snippet.rb +0 -0
  52. data/lib/deplate/fmt/html.rb +783 -550
  53. data/lib/deplate/fmt/htmlsite.rb +192 -199
  54. data/lib/deplate/fmt/htmlslides.rb +0 -0
  55. data/lib/deplate/fmt/htmlwebsite.rb +3 -3
  56. data/lib/deplate/fmt/latex-snippet.rb +0 -0
  57. data/lib/deplate/fmt/latex.rb +242 -83
  58. data/lib/deplate/fmt/null.rb +32 -0
  59. data/lib/deplate/fmt/php.rb +4 -4
  60. data/lib/deplate/fmt/phpsite.rb +6 -5
  61. data/lib/deplate/fmt/plain.rb +160 -106
  62. data/lib/deplate/fmt/template.rb +0 -0
  63. data/lib/deplate/fmt/xhtml10t.rb +0 -0
  64. data/lib/deplate/formatter-snippet.rb +0 -0
  65. data/lib/deplate/formatter.rb +613 -301
  66. data/lib/deplate/input.rb +202 -142
  67. data/lib/deplate/input/deplate-headings.rb +4 -6
  68. data/lib/deplate/input/deplate-restricted.rb +15 -9
  69. data/lib/deplate/input/deplate.rb +2 -4
  70. data/lib/deplate/input/rdoc.rb +39 -38
  71. data/lib/deplate/input/template.rb +0 -0
  72. data/lib/deplate/lib/Makefile.config +29 -0
  73. data/lib/deplate/lib/latex/deplate.sty +54 -0
  74. data/lib/deplate/lib/latex/highlight-extra.sty +0 -0
  75. data/lib/deplate/lib/latex/highlight-typical.sty +0 -0
  76. data/lib/deplate/lib/php/page-comment.inc.php +216 -0
  77. data/lib/deplate/lib/tabmenu.js +0 -0
  78. data/lib/deplate/locale/de.latin1 +155 -17
  79. data/lib/deplate/locale/ru.koi8-r +0 -0
  80. data/lib/deplate/locale/zh_cn.gb2312 +0 -0
  81. data/lib/deplate/macros.rb +133 -82
  82. data/lib/deplate/messages.rb +6 -4
  83. data/lib/deplate/metadata.rb +0 -0
  84. data/lib/deplate/metadata/marshal.rb +0 -0
  85. data/lib/deplate/metadata/xml.rb +0 -0
  86. data/lib/deplate/metadata/yaml.rb +0 -0
  87. data/lib/deplate/mod/anyword.rb +3 -3
  88. data/lib/deplate/mod/babelfish.rb +4 -4
  89. data/lib/deplate/mod/code-gvim.rb +8 -4
  90. data/lib/deplate/mod/code-highlight.rb +3 -3
  91. data/lib/deplate/mod/colored-log.rb +0 -0
  92. data/lib/deplate/mod/de.rb +2 -2
  93. data/lib/deplate/mod/en.rb +0 -0
  94. data/lib/deplate/mod/endnotes.rb +0 -0
  95. data/lib/deplate/mod/fr.rb +0 -0
  96. data/lib/deplate/mod/html-asciimath.rb +0 -0
  97. data/lib/deplate/mod/html-deplate-button.rb +0 -0
  98. data/lib/deplate/mod/html-headings-navbar.rb +5 -13
  99. data/lib/deplate/mod/html-jsmath.rb +39 -0
  100. data/lib/deplate/mod/html-obfuscate-email.rb +3 -3
  101. data/lib/deplate/mod/html-sidebar.rb +0 -0
  102. data/lib/deplate/mod/htmlslides-navbar-fh.rb +3 -3
  103. data/lib/deplate/mod/iconv.rb +0 -0
  104. data/lib/deplate/mod/imgurl.rb +4 -4
  105. data/lib/deplate/mod/inlatex-compound.rb +7 -10
  106. data/lib/deplate/mod/koma.rb +0 -0
  107. data/lib/deplate/mod/latex-emph-table-head.rb +0 -0
  108. data/lib/deplate/mod/latex-styles.rb +7 -4
  109. data/lib/deplate/mod/latex-verbatim-small.rb +0 -0
  110. data/lib/deplate/mod/makefile.rb +23 -7
  111. data/lib/deplate/mod/mark-external-urls.rb +3 -3
  112. data/lib/deplate/mod/markup-1-warn.rb +10 -10
  113. data/lib/deplate/mod/markup-1.rb +0 -0
  114. data/lib/deplate/mod/navbar-png.rb +24 -8
  115. data/lib/deplate/mod/noindent.rb +0 -0
  116. data/lib/deplate/mod/numpara.rb +0 -0
  117. data/lib/deplate/mod/particle-math.rb +4 -4
  118. data/lib/deplate/mod/php-extra.rb +46 -6
  119. data/lib/deplate/mod/pstoedit.rb +0 -0
  120. data/lib/deplate/mod/recode.rb +0 -0
  121. data/lib/deplate/mod/ru_koi8-r.rb +0 -0
  122. data/lib/deplate/mod/smart-dash.rb +26 -0
  123. data/lib/deplate/mod/smiley.rb +69 -7
  124. data/lib/deplate/mod/soffice.rb +0 -0
  125. data/lib/deplate/mod/symbols-latin1.rb +14 -23
  126. data/lib/deplate/mod/symbols-od-utf-8.rb +5 -3
  127. data/lib/deplate/mod/symbols-plain.rb +5 -35
  128. data/lib/deplate/mod/symbols-sgml.rb +8 -9
  129. data/lib/deplate/mod/symbols-utf-8.rb +8 -9
  130. data/lib/deplate/mod/symbols-xml.rb +5 -9
  131. data/lib/deplate/mod/syntax-region-alt.rb +5 -5
  132. data/lib/deplate/mod/utf8.rb +0 -0
  133. data/lib/deplate/mod/validate-html.rb +0 -0
  134. data/lib/deplate/mod/xmlrpc.rb +0 -0
  135. data/lib/deplate/mod/zh-cn-autospace.rb +18 -20
  136. data/lib/deplate/mod/zh-cn.rb +4 -6
  137. data/lib/deplate/nukumi2.rb +71 -0
  138. data/lib/deplate/once-method.rb +0 -0
  139. data/lib/deplate/output.rb +19 -21
  140. data/lib/deplate/particles.rb +178 -116
  141. data/lib/deplate/regions.rb +99 -58
  142. data/lib/deplate/skeletons.rb +122 -0
  143. data/lib/deplate/structured.rb +164 -106
  144. data/lib/deplate/template.rb +67 -43
  145. data/lib/deplate/templates/html-doc.html +0 -0
  146. data/lib/deplate/templates/html-left-tabbar-js.html +0 -0
  147. data/lib/deplate/templates/html-left-tabbar.html +0 -0
  148. data/lib/deplate/templates/html-tabbar-right-pcomments.php +22 -0
  149. data/lib/deplate/templates/html-tabbar-right-step.html +24 -0
  150. data/lib/deplate/templates/html-tabbar-right-table.html +0 -0
  151. data/lib/deplate/templates/html-tabbar-right.html +2 -4
  152. data/lib/deplate/templates/html-tabbar-top.html +0 -9
  153. data/lib/deplate/templates/html-tabbar.html +0 -0
  154. data/lib/deplate/variables.rb +127 -0
  155. data/lib/deplate/wiki-markup.rb +99 -33
  156. data/lib/deplate/xml.rb +18 -18
  157. data/lib/deplate/zh-cn.rb +0 -0
  158. data/lib/ps2ppm.rb +0 -0
  159. data/man/man1/deplate.1 +564 -474
  160. metadata +201 -186
File without changes
@@ -3,23 +3,69 @@
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 21-Aug-2005.
6
- # @Last Change: 23-Okt-2005.
7
- # @Revision: 0.25
6
+ # @Last Change: 08-Apr-2006.
7
+ # @Revision: 0.46
8
8
 
9
9
  # = Description
10
10
  # This class provides a cache for dynamically generated classes.
11
11
  class Deplate::Cache
12
12
  @@custom_particles = {}
13
+ @@custom_macros = {}
14
+ @@custom_elements = {}
15
+ @@custom_regions = {}
16
+ @@custom_commands = {}
13
17
 
14
18
  attr_reader :cls
15
19
 
16
20
  class << self
17
21
  def particle(deplate, body, args)
18
22
  register = args[:register]
19
- new(@@custom_particles, Deplate::Particle, deplate, body, args) do |cls|
23
+ parent = args[:super] || Deplate::Particle
24
+ new(@@custom_particles, parent, deplate, body, args) do |cls|
20
25
  if register
21
26
  args[:id] = body
22
- deplate.register_particle(cls, args)
27
+ deplate.input.register_particle(cls, args)
28
+ end
29
+ end
30
+ end
31
+
32
+ def element(deplate, body, args)
33
+ register = args[:register]
34
+ parent = args[:super] || Deplate::Element
35
+ new(@@custom_elements, parent, deplate, body, args) do |cls|
36
+ if register
37
+ args[:id] = body
38
+ deplate.input.register_element(cls, args)
39
+ end
40
+ end
41
+ end
42
+
43
+ def command(deplate, body, args)
44
+ register = args[:register]
45
+ parent = args[:super] || Deplate::Command
46
+ new(@@custom_commands, parent, deplate, body, args) do |cls|
47
+ if register
48
+ deplate.input.register_command(cls, args)
49
+ end
50
+ end
51
+ end
52
+
53
+ def region(deplate, body, args)
54
+ register = args[:register]
55
+ parent = args[:super] || Deplate::Region
56
+ new(@@custom_regions, parent, deplate, body, args) do |cls|
57
+ if register
58
+ deplate.input.register_region(cls, args)
59
+ end
60
+ end
61
+ end
62
+
63
+ def macro(deplate, body, args)
64
+ register = args[:register]
65
+ parent = args[:super] || Deplate::Region
66
+ new(@@custom_macros, parent, deplate, body, args) do |cls|
67
+ if register
68
+ deplate.input.register_macro(cls, args)
23
69
  end
24
70
  end
25
71
  end
@@ -32,7 +78,11 @@ class Deplate::Cache
32
78
  retrieve_particle(body, specific)
33
79
  unless @cls
34
80
  @cls = Class.new(super_class)
35
- @cls.class_eval(body)
81
+ if body.kind_of?(Proc)
82
+ @cls.class_eval(&body)
83
+ else
84
+ @cls.class_eval(body)
85
+ end
36
86
  store_particle(body, specific)
37
87
  end
38
88
  if @cls and block_given?
@@ -3,8 +3,8 @@
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 08-Mai-2004.
6
- # @Last Change: 02-Nov-2005.
7
- # @Revision: 0.932
6
+ # @Last Change: 02-Mai-2006.
7
+ # @Revision: 0.1164
8
8
 
9
9
  # Description:
10
10
  #
@@ -40,15 +40,20 @@ class Deplate::Command < Deplate::Element
40
40
  @@commands
41
41
  end
42
42
 
43
+ def register_as(name, c=self)
44
+ @@commands[name] = self
45
+ end
46
+
43
47
  def update_variables(hash, opts, args)
44
48
  if args
45
- d = args["date"]
46
- args["date"] = get_date(d, args) if d
47
- if opts["add"]
48
- if opts["add"].kind_of?(String)
49
- sep = opts["add"]
49
+ opts ||= {}
50
+ d = args['date']
51
+ args['date'] = get_date(d, args) if d
52
+ if opts['add']
53
+ if opts['add'].kind_of?(String)
54
+ sep = opts['add']
50
55
  else
51
- sep = " "
56
+ sep = ' '
52
57
  end
53
58
  args.each_pair do |k,v|
54
59
  if hash[k]
@@ -60,14 +65,13 @@ class Deplate::Command < Deplate::Element
60
65
  hash.update(args)
61
66
  end
62
67
  else
63
- Deplate::Core.log(["No arguments", opts], :error, src)
68
+ Deplate::Core.log(['No arguments', opts], :error, src)
64
69
  end
65
70
  end
66
71
  end
67
72
 
68
73
  def setup(args, cmd)
69
- @multiliner = false
70
- @collapse = false
74
+ # @collapse = false
71
75
  @name = cmd
72
76
  @accum = [@text]
73
77
  @can_be_labelled = false
@@ -91,26 +95,23 @@ class Deplate::Command < Deplate::Element
91
95
  end
92
96
 
93
97
  def format_special
94
- format_unknown(self)
98
+ @deplate.formatter.format_unknown(self)
95
99
  end
96
100
  end
97
101
 
98
102
 
99
103
  class Deplate::Command::CAP < Deplate::Command
100
- @@commands["CAP"] = self
101
- @@commands["CAPTION"] = self
104
+ register_as 'CAP'
105
+ register_as 'CAPTION'
102
106
 
103
107
  class << self
104
108
  def accumulate(src, array, deplate, text, match, args, cmd)
105
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
106
- elt = deplate.parse_with_source(src, text, false)
107
- last = array.last
108
- if last.caption
109
- Deplate::Core.log('Element already has a caption', :error, src)
109
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
110
+ last = array.last
111
+ if last
112
+ last.set_caption(Deplate::CaptionDef.new(text, args, src))
110
113
  else
111
- last.level_as_string = deplate.get_current_heading
112
- last.caption = Deplate::CaptionDef.new(elt, args)
113
- last.register_caption
114
+ Deplate::Core.log(["Can't attach caption to", nil], :error, src)
114
115
  end
115
116
  end
116
117
  end
@@ -118,23 +119,23 @@ end
118
119
 
119
120
 
120
121
  class Deplate::Command::LANG < Deplate::Command
121
- @@commands["LANG"] = self
122
- @@commands["LANGUAGE"] = self
122
+ register_as 'LANG'
123
+ register_as 'LANGUAGE'
124
+ self.volatile = true
123
125
 
124
126
  def self.accumulate(src, array, deplate, text, match, args, cmd)
125
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
127
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
126
128
  deplate.set_lang(text)
127
129
  end
128
130
  end
129
131
 
130
132
 
131
133
  class Deplate::Command::INC < Deplate::Command
132
- @@commands["INC"] = self
133
- @@commands["INCLUDE"] = self
134
+ register_as 'INC'
135
+ register_as 'INCLUDE'
134
136
 
135
137
  def self.accumulate(src, array, deplate, text, match, args, cmd)
136
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
137
- formatter_name = deplate.formatter.formatter_name
138
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
138
139
  doc = args['doc'] || args['var'] || args['val']
139
140
  if args.has_key?('file')
140
141
  if text
@@ -164,39 +165,17 @@ class Deplate::Command::INC < Deplate::Command
164
165
  if strings
165
166
  deplate.include_stringarray(strings, array, nil, src.file)
166
167
  else
167
- Deplate::Core.log(["Unknown doc variable", doc], :error, src)
168
+ Deplate::Core.log(['Unknown doc variable', doc], :error, src)
168
169
  end
169
170
  elsif !text or text == ''
170
- Deplate::Core.log(["Malformed command", cmd, text], :error, src)
171
+ Deplate::Core.log(['Malformed command', cmd, text], :error, src)
171
172
  else
172
- pwd = File.dirname(deplate.current_source || "")
173
- dirs = [
174
- File.join(pwd, "deplate.rc", formatter_name, text),
175
- File.join(pwd, "deplate.rc", text),
176
- File.join(pwd, text),
177
- ]
178
- dirs += Deplate::Core.library_directories("lib", formatter_name, text)
179
- dirs += Deplate::Core.library_directories("lib", text)
180
- dirs += Deplate::Core.library_directories(text)
181
- # dirs = [
182
- # File.join(pwd, "deplate.rc", formatter_name, text),
183
- # File.join(pwd, "deplate.rc", text),
184
- # File.join(pwd, text),
185
- # File.join(Deplate::Core::CfgDir, "lib", formatter_name, text),
186
- # File.join(Deplate::Core::CfgDir, "lib", text),
187
- # File.join(Deplate::Core::CfgDir, text),
188
- # File.join(Deplate::Core::LibDir, "lib", formatter_name, text),
189
- # File.join(Deplate::Core::LibDir, "lib", text),
190
- # File.join(Deplate::Core::DataDir, "lib", formatter_name, text),
191
- # File.join(Deplate::Core::DataDir, "lib", text),
192
- # ]
193
- for fn in dirs
194
- if !File.directory?(fn) and File.exists?(fn)
195
- deplate.include_file(array, fn)
196
- return
197
- end
173
+ fn = deplate.find_in_lib(text, :pwd => true)
174
+ if fn
175
+ deplate.include_file(array, fn)
176
+ else
177
+ Deplate::Core.log(['File not found', text], :error, src)
198
178
  end
199
- Deplate::Core.log(["File not found", text], :error, src)
200
179
  end
201
180
  ensure
202
181
  deplate.variables['embeddedTextRx'] = embeddedTextRx_orig if embeddedTextRx
@@ -208,28 +187,62 @@ class Deplate::Command::INC < Deplate::Command
208
187
  end
209
188
 
210
189
 
211
- class Deplate::Command::DOC < Deplate::Command
212
- @@commands["DOC"] = self
213
- @@commands["VAR"] = self
214
- def self.accumulate(src, array, deplate, text, match, args, cmd)
215
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
216
- opts, text = deplate.input.parse_args(text, nil, false)
217
- for k, v in opts
218
- deplate.register_metadata(src,
219
- "type" => "variable",
220
- "name" => k,
221
- "value" => v
222
- )
190
+ class Deplate::Command::VAR < Deplate::Command
191
+ register_as 'DOC'
192
+ register_as 'VAR'
193
+ self.volatile = true
194
+
195
+ class << self
196
+ def set_variable(deplate, var, value, args={}, src=nil)
197
+ if deplate.input.allow_set_variable(var)
198
+ deplate.register_metadata(src,
199
+ 'type' => 'variable',
200
+ 'name' => var,
201
+ 'value' => value
202
+ )
203
+ update_variables(deplate.variables, args, var => value)
204
+ return true
205
+ else
206
+ Deplate::Core.log(['Disabled', var], :error, src)
207
+ return false
208
+ end
209
+ end
210
+
211
+ def accumulate(src, array, deplate, text, match, args, cmd)
212
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
213
+ id = args['id']
214
+ if id
215
+ if deplate.input.allow_set_variable(id)
216
+ set_variable(deplate, id, text, args, src)
217
+ end
218
+ else
219
+ opts, text = deplate.input.parse_args(text, nil, false)
220
+ for k, v in opts
221
+ unless set_variable(deplate, k, v, args, src)
222
+ opts.delete(k)
223
+ end
224
+ end
225
+ end
223
226
  end
224
- update_variables(deplate.variables, args, opts)
227
+ end
228
+ end
229
+
230
+
231
+ class Deplate::Command::KEYWORDS < Deplate::Command::VAR
232
+ register_as 'KEYWORDS'
233
+ self.volatile = true
234
+ def self.accumulate(src, array, deplate, text, match, args, cmd)
235
+ args['id'] = 'keywords'
236
+ super
225
237
  end
226
238
  end
227
239
 
228
240
 
229
241
  class Deplate::Command::OPT < Deplate::Command
230
- @@commands["OPT"] = self
242
+ register_as 'OPT'
243
+ self.volatile = true
231
244
  def self.accumulate(src, array, deplate, text, match, args, cmd)
232
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
245
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
233
246
  elt = array.last
234
247
  if elt
235
248
  opts, text = deplate.input.parse_args(text, nil, false)
@@ -244,25 +257,25 @@ end
244
257
 
245
258
 
246
259
  class Deplate::Command::PUT < Deplate::Command
247
- @@commands["PUT"] = self
248
- @@commands["CLIP"] = self
249
- @@commands["SET"] = self
260
+ register_as 'PUT'
261
+ register_as 'CLIP'
262
+ register_as 'SET'
250
263
  def self.accumulate(src, array, deplate, text, match, args, cmd)
251
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
264
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
252
265
  id = args["id"]
253
266
  if id
254
267
  text = deplate.parse_with_source(src, text, false)
255
268
  deplate.set_clip(id, Deplate::Element::Clip.new(text, deplate, src))
256
269
  else
257
- Deplate::Core.log(["No clip-id given", text], :error, src)
270
+ Deplate::Core.log(["No ID given", text], :error, src)
258
271
  end
259
272
  end
260
273
  end
261
274
 
262
275
 
263
276
  class Deplate::Command::GET < Deplate::Command
264
- @@commands["GET"] = self
265
- @formatter = :format_GET
277
+ register_as 'GET'
278
+ set_formatter :format_GET
266
279
 
267
280
  def setup_command
268
281
  @id = @args["id"] || @accum[0]
@@ -281,13 +294,16 @@ end
281
294
 
282
295
 
283
296
  class Deplate::Command::XARG < Deplate::Command
284
- @@commands["XARG"] = self
285
- @@commands["XVAL"] = self
297
+ register_as 'XARG'
298
+ register_as 'XVAL'
299
+ self.volatile = true
286
300
 
287
301
  def setup_command
288
302
  id = args["id"] || @accum[0]
289
- @elt = @deplate.variables[id]
303
+ @elt = @deplate.variables[id] || @args["default"]
290
304
  if @elt
305
+ @elt = Deplate::Core.escape_characters(@elt, @args)
306
+ @elt = post_process_text(@elt)
291
307
  @elt = @elt.split(/[\n\r]/).each {|l| l.chomp!}
292
308
  else
293
309
  log(["Unknown variable", id, @name], :error)
@@ -301,21 +317,25 @@ end
301
317
 
302
318
 
303
319
  class Deplate::Command::ARG < Deplate::Command
304
- @@commands["ARG"] = self
305
- @@commands["VAL"] = self
320
+ register_as 'ARG'
321
+ register_as 'VAL'
322
+ self.volatile = true
306
323
 
307
324
  class << self
308
325
  def accumulate(src, array, deplate, text, match, args, cmd)
309
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
310
- id = args["id"] || text
311
- val = deplate.variables[id]
326
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
327
+ id = args['id'] || text
328
+ val = deplate.variables[id] || args['default']
312
329
  if val
330
+ val = Deplate::Core.escape_characters(val, args)
331
+ val = Deplate::CommonGround.post_process_text(val, args)
332
+ # val.gsub!(/\\/, '\\\\\\\\')
313
333
  acc = val.split(/[\n\r]/)
314
334
  acc.each {|l| l.chomp!}
315
335
  d = deplate.options.master ? deplate.options.master : deplate
316
336
  d.include_stringarray(acc, array, src.begin, src.file)
317
337
  else
318
- Deplate::Core.log(["Unknown variable", id, cmd], :error, src)
338
+ Deplate::Core.log(['Unknown variable', id, cmd], :error, src)
319
339
  end
320
340
  end
321
341
  end
@@ -323,10 +343,11 @@ end
323
343
 
324
344
 
325
345
  class Deplate::Command::BIB < Deplate::Command
326
- @@commands["BIB"] = self
346
+ register_as 'BIB'
347
+ self.volatile = true
327
348
  class << self
328
349
  def accumulate(src, array, deplate, text, match, args, cmd)
329
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
350
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
330
351
  bibs = text.strip.split(/\s*\|\s*/)
331
352
  deplate.options.bib += bibs
332
353
  deplate.formatter.read_bib(bibs)
@@ -336,10 +357,11 @@ end
336
357
 
337
358
 
338
359
  class Deplate::Command::TITLE < Deplate::Command
339
- @@commands["TITLE"] = self
340
- @@commands["TI"] = self
360
+ register_as 'TITLE'
361
+ register_as 'TI'
362
+ self.volatile = true
341
363
  def self.accumulate(src, array, deplate, text, match, args, cmd)
342
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
364
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
343
365
  c = deplate.parse_with_source(src, text, false)
344
366
  deplate.set_clip("title", Deplate::Element::Clip.new(c, deplate, src))
345
367
  deplate.register_metadata(src,
@@ -352,11 +374,12 @@ end
352
374
 
353
375
 
354
376
  class Deplate::Command::AUTHOR < Deplate::Command
355
- @@commands["AUTHOR"] = self
356
- @@commands["AU"] = self
377
+ register_as 'AUTHOR'
378
+ register_as 'AU'
379
+ self.volatile = true
357
380
  class << self
358
381
  def accumulate(src, array, deplate, text, match, args, cmd)
359
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
382
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
360
383
  deplate.options.author ||= []
361
384
  for this in text.split(/([;\/]|\s+(&|and))\s+/)
362
385
  unless this =~ /^\s*([;\/&]|and)\s*$/
@@ -391,10 +414,11 @@ end
391
414
 
392
415
 
393
416
  class Deplate::Command::AUTHORNOTE < Deplate::Command
394
- @@commands["AUTHORNOTE"] = self
395
- @@commands["AN"] = self
417
+ register_as 'AUTHORNOTE'
418
+ register_as 'AN'
419
+ self.volatile = true
396
420
  def self.accumulate(src, array, deplate, text, match, args, cmd)
397
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
421
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
398
422
  unless text.empty?
399
423
  author = deplate.options.author.last
400
424
  if author
@@ -403,7 +427,7 @@ class Deplate::Command::AUTHORNOTE < Deplate::Command
403
427
  end
404
428
  ans = deplate.options.author.collect {|h| h[:note]}
405
429
  sep = deplate.variables["authorSep"] || "; "
406
- ans = ans.join(sep)
430
+ ans = ans.compact.join(sep)
407
431
  parsed = deplate.parse_with_source(src, ans, false)
408
432
  deplate.set_clip("authornote", Deplate::Element::Clip.new(parsed, deplate, src))
409
433
  deplate.register_metadata(src,
@@ -416,9 +440,10 @@ end
416
440
 
417
441
 
418
442
  class Deplate::Command::DATE < Deplate::Command
419
- @@commands["DATE"] = self
443
+ register_as 'DATE'
444
+ self.volatile = true
420
445
  def self.accumulate(src, array, deplate, text, match, args, cmd)
421
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
446
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
422
447
  d = get_date(text, args)
423
448
  c = deplate.parse_with_source(src, d, false)
424
449
  deplate.set_clip(cmd.downcase, Deplate::Element::Clip.new(c, deplate, src))
@@ -432,11 +457,11 @@ end
432
457
 
433
458
 
434
459
  class Deplate::Command::IMG < Deplate::Command
435
- @@commands['IMG'] = self
436
- @@commands['IMAGE'] = self
437
- @@commands['FIG'] = self
438
- @@commands['FIGURE'] = self
439
- @formatter = :format_IMG
460
+ register_as 'IMG'
461
+ register_as 'IMAGE'
462
+ register_as 'FIG'
463
+ register_as 'FIGURE'
464
+ set_formatter :format_IMG
440
465
 
441
466
  def register_caption
442
467
  register_figure
@@ -445,25 +470,97 @@ end
445
470
 
446
471
 
447
472
  class Deplate::Command::MAKETITLE < Deplate::Command
448
- @@commands['MAKETITLE'] = self
449
- @formatter = :format_title
473
+ register_as 'MAKETITLE'
474
+ set_formatter :format_title
450
475
  end
451
476
 
452
477
 
453
478
  class Deplate::Command::MAKEBIB < Deplate::Command
454
- @@commands['MAKEBIB'] = self
455
- @formatter = :format_MAKEBIB
479
+ register_as 'MAKEBIB'
480
+ set_formatter :format_MAKEBIB
481
+ def setup_command
482
+ unless @text.nil? or @text.empty? or @deplate.variables['bibStyle']
483
+ log(['Setting variable', 'bibStyle', @text], :anyway)
484
+ @deplate.variables['bibStyle'] = @text
485
+ end
486
+ end
456
487
  end
457
488
 
458
489
 
459
490
  class Deplate::Command::LIST < Deplate::Command
460
- @@commands['LIST'] = self
461
- @formatter = :format_LIST
491
+ register_as 'LIST'
492
+ set_formatter :format_LIST
493
+ end
494
+
495
+ class Deplate::Command::DEFLIST < Deplate::Command
496
+ register_as 'DEFLIST'
497
+ self.volatile = true
498
+ def self.accumulate(src, array, deplate, text, match, args, cmd)
499
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
500
+ list = args['id'] || args['list'] || text
501
+ deplate.options.listings.def_listing(list, nil, args)
502
+ i = deplate.current_heading
503
+ p = args['parent']
504
+ deplate.options.counters.def_counter(list, :parent => p)
505
+ end
506
+ end
507
+
508
+ class Deplate::Command::REGISTER < Deplate::Command
509
+ register_as 'REGISTER'
510
+ self.volatile = true
511
+ def self.accumulate(src, array, deplate, text, match, args, cmd)
512
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
513
+ list = args['id'] || args['list']
514
+ if list
515
+ elt = array.last
516
+ if elt
517
+ name = args['name'] || text
518
+ if name and !name.empty?
519
+ cap = Deplate::CaptionDef.new(name, args, src)
520
+ elt.set_caption(cap)
521
+ end
522
+ elt.register_in_listing(list, args)
523
+ return
524
+ end
525
+ end
526
+ Deplate::Core.log(['Nothing to register', list], :error, src)
527
+ end
528
+ end
529
+
530
+
531
+ class Deplate::Command::DEFCOUNTER < Deplate::Command
532
+ register_as 'DEFCOUNTER'
533
+ self.volatile = true
534
+ def self.accumulate(src, array, deplate, text, match, args, cmd)
535
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
536
+ c = args['id'] || args['counter'] || text
537
+ # i = deplate.current_heading
538
+ p = args['parent']
539
+ deplate.options.counters.def_counter(c, :parent => p)
540
+ end
541
+ end
542
+
543
+ class Deplate::Command::COUNTER < Deplate::Command
544
+ register_as 'COUNTER'
545
+ self.volatile = true
546
+ def self.accumulate(src, array, deplate, text, match, args, cmd)
547
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
548
+ c = args['id'] || args['counter'] || text
549
+ if args['reset']
550
+ # <+TBD+>
551
+ elsif (by = args['increase'])
552
+ by = by.to_i
553
+ l = args['level']
554
+ # <+TBD+>
555
+ else
556
+ Deplate::Core.log(['#COUNTER', 'Missing directive'], :error, src)
557
+ end
558
+ end
462
559
  end
463
560
 
464
561
 
465
562
  class Deplate::Command::TABLE < Deplate::Command
466
- @@commands['TABLE'] = self
563
+ register_as 'TABLE'
467
564
  def setup_command
468
565
  if File.exist?(@text)
469
566
  File.open(@text) {|io| @accum = io.read.split(/[\r\n]+/)}
@@ -473,14 +570,17 @@ class Deplate::Command::TABLE < Deplate::Command
473
570
  end
474
571
 
475
572
  def finish
476
- return Deplate::Regions::Table.make_char_separated(self, @accum, @args['sep'])
573
+ rv = Deplate::Regions::Table.make_char_separated(self, @accum, @args['sep'])
574
+ rv.unify_props(self)
575
+ rv
477
576
  end
478
577
  end
479
578
 
480
579
 
481
580
  class Deplate::Command::IDX < Deplate::Command
482
- @@commands['IDX'] = self
483
- @formatter = :format_IDX
581
+ register_as 'IDX'
582
+ self.volatile = true
583
+ set_formatter :format_IDX
484
584
 
485
585
  class << self
486
586
  def accumulate(src, array, deplate, text, match, args, cmd)
@@ -512,7 +612,8 @@ class Deplate::Command::IDX < Deplate::Command
512
612
  auto = args['auto']
513
613
  auto = deplate.variables['autoindex'] if auto.nil?
514
614
  for i in text.split(/\s*;\s*/)
515
- idx = deplate.add_index(nil, i, deplate.get_current_heading)
615
+ # <+TBD IDX+>idx = deplate.add_index(nil, i, deplate.get_current_heading)
616
+ idx = deplate.add_index(container, i)
516
617
  Deplate::Particle.auto_indexing(deplate, idx) if auto
517
618
  accum << idx
518
619
  container.add_metadata(source,
@@ -546,10 +647,11 @@ end
546
647
 
547
648
 
548
649
  class Deplate::Command::AUTOIDX < Deplate::Command
549
- @@commands["AUTOIDX"] = self
650
+ register_as 'AUTOIDX'
651
+ self.volatile = true
550
652
  def self.accumulate(src, array, deplate, text, match, args, cmd)
551
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
552
- hd = deplate.get_current_heading
653
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
654
+ hd = deplate.get_current_heading
553
655
  for i in text.split(/\s*;\s*/)
554
656
  Deplate::Particle.auto_indexing(deplate, deplate.add_index(nil, i, hd))
555
657
  end
@@ -558,9 +660,10 @@ end
558
660
 
559
661
 
560
662
  class Deplate::Command::NOIDX < Deplate::Command
561
- @@commands["NOIDX"] = self
663
+ register_as 'NOIDX'
664
+ self.volatile = true
562
665
  def self.accumulate(src, array, deplate, text, match, args, cmd)
563
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
666
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
564
667
  for i in text.split(/\s*;\s*/)
565
668
  deplate.remove_index(self, i)
566
669
  end
@@ -569,26 +672,31 @@ end
569
672
 
570
673
 
571
674
  class Deplate::Command::DONTIDX < Deplate::Command
572
- @@commands["DONTIDX"] = self
675
+ register_as 'DONTIDX'
676
+ self.volatile = true
573
677
  def self.accumulate(src, array, deplate, text, match, args, cmd)
574
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
678
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
575
679
  deplate.options.dont_index += text.split(/\s*;\s*/)
576
680
  end
577
681
  end
578
682
 
579
683
 
580
684
  class Deplate::Command::WITH < Deplate::Command
581
- @@commands["WITH"] = self
685
+ register_as 'WITH'
582
686
  def self.accumulate(src, array, deplate, text, match, args, cmd)
583
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
687
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
584
688
  file = args["file"]
585
689
  body = nil
586
690
  if file
587
691
  File.open(file) {|io| body = io.readlines}
588
692
  else
589
- arg = args["arg"]
693
+ arg = args["arg"] || args["var"]
590
694
  if arg
591
- body = deplate.variables[arg].split(/[\n\r]/)
695
+ body = deplate.variables[arg]
696
+ case body
697
+ when String
698
+ body = body.split(/[\n\r]/)
699
+ end
592
700
  end
593
701
  end
594
702
  if body
@@ -604,68 +712,97 @@ end
604
712
 
605
713
 
606
714
  class Deplate::Command::ABBREV < Deplate::Command
607
- @@commands["ABBREV"] = self
715
+ register_as 'ABBREV'
716
+ self.volatile = true
608
717
  @@abbrevn = 0
609
-
610
- def self.accumulate(src, array, deplate, text, match, args, cmd)
611
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
612
- rx = nil
613
- tx = nil
614
- cmd = nil
615
- catch(:exit) do
616
- w = args["word"] || args["w"] || args["wd"]
617
- if w
618
- rx = Regexp.new(%{\\b%s\\b} % Regexp.escape(w))
619
- tx = "%{#{text}}"
620
- throw :exit
621
- end
622
- s = args["symbol"] || args["sym"]
623
- if s
624
- rx = Regexp.new(%{`%s} % Regexp.escape(s))
625
- tx = "%{#{text}}"
626
- throw :exit
627
- end
628
- r = args["regexp"] || args["rx"]
629
- if r
630
- rx = Regexp.new(r)
631
- tx = %{@match[0].gsub(/#{r}/, %{#{text}})}
632
- throw :exit
718
+
719
+ class << self
720
+ def accumulate(src, array, deplate, text, match, args, cmd)
721
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
722
+ rx = nil
723
+ rs = nil
724
+ tx = nil
725
+ cmd = nil
726
+ deplate.options.abbrevs ||= {}
727
+ catch(:exit) do
728
+ w = args['word'] || args['w'] || args['wd']
729
+ if w
730
+ rs = %{\\b%s\\b} % Regexp.escape(w)
731
+ # tx = "#{Deplate::Core.remove_backslashes(text.inspect)}"
732
+ # tx = "#{text.inspect}"
733
+ # tx = text.inspect
734
+ tx = text
735
+ throw :exit
736
+ end
737
+ s = args['symbol'] || args['sym']
738
+ if s
739
+ rs = %{`%s} % Regexp.escape(s)
740
+ # tx = "#{Deplate::Core.remove_backslashes(text.inspect)}"
741
+ # tx = text.inspect
742
+ tx = text
743
+ throw :exit
744
+ end
745
+ r = args['regexp'] || args['rx']
746
+ if r
747
+ rs = r
748
+ tx = lambda {|p| p.match[0].gsub(Regexp.new(r), text)}
749
+ throw :exit
750
+ end
633
751
  end
634
- end
635
- if rx
636
- if args["plain"]
637
- cmd = %{@deplate.formatter.plain_text(#{tx})}
638
- specific = false
639
- elsif args["native"] or args["ins"]
640
- cmd = tx
641
- specific = true
752
+ if rs
753
+ if args['plain']
754
+ # cmd = %{@deplate.formatter.plain_text(#{tx})}
755
+ cmd = lambda {|c, t| c.deplate.formatter.plain_text(t)}
756
+ specific = false
757
+ elsif args['native'] or args['ins']
758
+ cmd = tx
759
+ specific = true
760
+ else
761
+ # cmd = %{@deplate.parse_and_format(@container, #{tx}, false)}
762
+ cmd = lambda {|c, t| c.deplate.parse_and_format(c, t, false)}
763
+ specific = false
764
+ end
765
+ deplate.options.abbrevs[rs] = [tx, cmd]
766
+ rx = Regexp.new("^#{rs}")
767
+ # body = <<-EOR
768
+ # set_rx(#{rx.inspect})
769
+ # def setup
770
+ # @elt = #{cmd}
771
+ # end
772
+ # EOR
773
+ body = <<-EOR
774
+ set_rx(#{rx.inspect})
775
+ def setup
776
+ tx, cmd = @deplate.options.abbrevs[#{rs.inspect}]
777
+ case cmd
778
+ when Proc
779
+ tx = tx.call(self) if tx.kind_of?(Proc)
780
+ @elt = cmd.call(@container, tx)
781
+ when String
782
+ @elt = cmd
783
+ else
784
+ log(['Internal error', 'ABBREV', #{rs.inspect}, cmd.class], :error)
785
+ end
786
+ end
787
+ EOR
788
+ cls = Deplate::Cache.particle(deplate, body,
789
+ :register => true,
790
+ :specific => specific
791
+ )
642
792
  else
643
- cmd = %{@deplate.parse_and_format(@container, #{tx}, false)}
644
- specific = false
793
+ Deplate::Core.log(["No pattern specified", args], :error, src)
645
794
  end
646
- body = <<-EOR
647
- @rx = /^#{rx}/
648
- def setup
649
- @elt = #{cmd}
650
- end
651
- EOR
652
- cls = Deplate::Cache.particle(deplate, body,
653
- :register => true,
654
- :specific => specific
655
- )
656
- else
657
- Deplate::Core.log(["No pattern specified", args], :error, src)
658
795
  end
659
796
  end
660
797
  end
661
798
 
662
799
 
663
800
  class Deplate::Command::MODULE < Deplate::Command
664
- @@commands["MODULE"] = self
665
- @@commands["MOD"] = self
801
+ register_as 'MODULE'
802
+ register_as 'MOD'
666
803
  class << self
667
804
  def accumulate(src, array, deplate, text, match, args, cmd)
668
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
805
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
669
806
  deplate.require_module(text)
670
807
  deplate.call_methods_matching(deplate, /^hook_late_require_/)
671
808
  # deplate.initialize_particles(false, :always => true)
@@ -675,11 +812,11 @@ end
675
812
 
676
813
 
677
814
  class Deplate::Command::LTX < Deplate::Command
678
- @@commands["LTX"] = self
679
- @@commands["INLATEX"] = self
815
+ register_as 'LTX'
816
+ register_as 'INLATEX'
680
817
  class << self
681
818
  def accumulate(src, array, deplate, text, match, args, cmd)
682
- Deplate::Core.log("%s: %s" % [cmd, text], :debug)
819
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
683
820
  m = []
684
821
  m[Deplate::Element::Region.rxi_name] = 'Ltx'
685
822
  m[Deplate::Element::Region.rxi_args] = match[2]
@@ -691,3 +828,29 @@ class Deplate::Command::LTX < Deplate::Command
691
828
  end
692
829
  end
693
830
 
831
+ class Deplate::Element::PAGE < Deplate::Command
832
+ register_as 'PAGE'
833
+ class << self
834
+ def accumulate(src, array, deplate, text, match, args, cmd)
835
+ Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
836
+ m = []
837
+ Deplate::Element::Break.accumulate(src, array, deplate, text, m)
838
+ end
839
+ end
840
+ end
841
+
842
+ class Deplate::Command::NOP < Deplate::Command
843
+ register_as 'NOP'
844
+
845
+ def setup_command
846
+ @embedable = false
847
+ end
848
+
849
+ def finish
850
+ return self
851
+ end
852
+
853
+ def process
854
+ end
855
+ end
856
+