deplate 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS.TXT +26 -0
- data/CHANGES.TXT +177 -0
- data/LICENSE.TXT +340 -0
- data/NEWS.TXT +29 -0
- data/README.TXT +86 -0
- data/TODO.TXT +202 -0
- data/VERSION.TXT +1 -0
- data/bin/deplate +3 -0
- data/bin/deplate.bat +2 -0
- data/etc/deplate.ini +361 -0
- data/lib/deplate.rb +31 -0
- data/lib/deplate/abstract-class.rb +30 -0
- data/lib/deplate/builtin.rb +11 -0
- data/lib/deplate/cache.rb +59 -0
- data/lib/deplate/commands.rb +693 -0
- data/lib/deplate/common.rb +335 -0
- data/lib/deplate/converter.rb +99 -0
- data/lib/deplate/core.rb +2705 -0
- data/lib/deplate/css/article.css +545 -0
- data/lib/deplate/css/deplate.css +699 -0
- data/lib/deplate/css/heading-navbar.css +29 -0
- data/lib/deplate/css/layout-deplate-print.css +540 -0
- data/lib/deplate/css/layout-deplate.css +764 -0
- data/lib/deplate/css/sans-serif.css +160 -0
- data/lib/deplate/css/serif-e.css +170 -0
- data/lib/deplate/css/serif-rel.css +121 -0
- data/lib/deplate/css/serif.css +190 -0
- data/lib/deplate/css/slides.css +11 -0
- data/lib/deplate/css/tabbar-left.css +91 -0
- data/lib/deplate/css/tabbar-right-ie.css +14 -0
- data/lib/deplate/css/tabbar-right.css +118 -0
- data/lib/deplate/css/tabbar-top.css +64 -0
- data/lib/deplate/css/tabbar.css +81 -0
- data/lib/deplate/css/text-sans-serif.css +154 -0
- data/lib/deplate/css/text-serif.css +175 -0
- data/lib/deplate/define.rb +439 -0
- data/lib/deplate/docbook.rb +738 -0
- data/lib/deplate/elements.rb +1355 -0
- data/lib/deplate/etc.rb +199 -0
- data/lib/deplate/external.rb +135 -0
- data/lib/deplate/fmt/dbk-article-4.1.2.rb +21 -0
- data/lib/deplate/fmt/dbk-article.rb +46 -0
- data/lib/deplate/fmt/dbk-book.rb +46 -0
- data/lib/deplate/fmt/dbk-ref.rb +105 -0
- data/lib/deplate/fmt/dbk-slides.rb +47 -0
- data/lib/deplate/fmt/dbk-snippet.rb +21 -0
- data/lib/deplate/fmt/html-snippet.rb +21 -0
- data/lib/deplate/fmt/html.rb +1696 -0
- data/lib/deplate/fmt/htmlsite.rb +419 -0
- data/lib/deplate/fmt/htmlslides.rb +21 -0
- data/lib/deplate/fmt/htmlwebsite.rb +70 -0
- data/lib/deplate/fmt/latex-snippet.rb +22 -0
- data/lib/deplate/fmt/latex.rb +1242 -0
- data/lib/deplate/fmt/php.rb +19 -0
- data/lib/deplate/fmt/phpsite.rb +19 -0
- data/lib/deplate/fmt/plain.rb +598 -0
- data/lib/deplate/fmt/template.rb +34 -0
- data/lib/deplate/fmt/xhtml10t.rb +41 -0
- data/lib/deplate/formatter-snippet.rb +17 -0
- data/lib/deplate/formatter.rb +1210 -0
- data/lib/deplate/input.rb +492 -0
- data/lib/deplate/input/deplate-headings.rb +48 -0
- data/lib/deplate/input/deplate-restricted.rb +70 -0
- data/lib/deplate/input/deplate.rb +28 -0
- data/lib/deplate/input/rdoc.rb +277 -0
- data/lib/deplate/input/template.rb +29 -0
- data/lib/deplate/lib/latex/highlight-extra.sty +15 -0
- data/lib/deplate/lib/latex/highlight-typical.sty +15 -0
- data/lib/deplate/lib/tabmenu.js +146 -0
- data/lib/deplate/locale/de.latin1 +708 -0
- data/lib/deplate/locale/ru.koi8-r +48 -0
- data/lib/deplate/locale/zh_cn.gb2312 +35 -0
- data/lib/deplate/macros.rb +639 -0
- data/lib/deplate/messages.rb +120 -0
- data/lib/deplate/metadata.rb +77 -0
- data/lib/deplate/metadata/marshal.rb +24 -0
- data/lib/deplate/metadata/xml.rb +42 -0
- data/lib/deplate/metadata/yaml.rb +26 -0
- data/lib/deplate/mod/anyword.rb +56 -0
- data/lib/deplate/mod/babelfish.rb +27 -0
- data/lib/deplate/mod/code-gvim.rb +52 -0
- data/lib/deplate/mod/code-highlight.rb +91 -0
- data/lib/deplate/mod/colored-log.rb +17 -0
- data/lib/deplate/mod/de.rb +19 -0
- data/lib/deplate/mod/en.rb +17 -0
- data/lib/deplate/mod/endnotes.rb +60 -0
- data/lib/deplate/mod/fr.rb +46 -0
- data/lib/deplate/mod/html-asciimath.rb +40 -0
- data/lib/deplate/mod/html-deplate-button.rb +15 -0
- data/lib/deplate/mod/html-headings-navbar.rb +39 -0
- data/lib/deplate/mod/html-obfuscate-email.rb +47 -0
- data/lib/deplate/mod/html-sidebar.rb +232 -0
- data/lib/deplate/mod/htmlslides-navbar-fh.rb +32 -0
- data/lib/deplate/mod/iconv.rb +35 -0
- data/lib/deplate/mod/imgurl.rb +30 -0
- data/lib/deplate/mod/inlatex-compound.rb +69 -0
- data/lib/deplate/mod/koma.rb +109 -0
- data/lib/deplate/mod/latex-emph-table-head.rb +38 -0
- data/lib/deplate/mod/latex-styles.rb +461 -0
- data/lib/deplate/mod/latex-verbatim-small.rb +29 -0
- data/lib/deplate/mod/makefile.rb +194 -0
- data/lib/deplate/mod/mark-external-urls.rb +38 -0
- data/lib/deplate/mod/markup-1-warn.rb +37 -0
- data/lib/deplate/mod/markup-1.rb +41 -0
- data/lib/deplate/mod/navbar-png.rb +33 -0
- data/lib/deplate/mod/noindent.rb +32 -0
- data/lib/deplate/mod/numpara.rb +40 -0
- data/lib/deplate/mod/particle-math.rb +34 -0
- data/lib/deplate/mod/php-extra.rb +44 -0
- data/lib/deplate/mod/pstoedit.rb +71 -0
- data/lib/deplate/mod/recode.rb +57 -0
- data/lib/deplate/mod/ru_koi8-r.rb +20 -0
- data/lib/deplate/mod/smiley.rb +50 -0
- data/lib/deplate/mod/soffice.rb +23 -0
- data/lib/deplate/mod/symbols-latin1.rb +58 -0
- data/lib/deplate/mod/symbols-od-utf-8.rb +16 -0
- data/lib/deplate/mod/symbols-plain.rb +58 -0
- data/lib/deplate/mod/symbols-sgml.rb +97 -0
- data/lib/deplate/mod/symbols-utf-8.rb +81 -0
- data/lib/deplate/mod/symbols-xml.rb +34 -0
- data/lib/deplate/mod/syntax-region-alt.rb +37 -0
- data/lib/deplate/mod/utf8.rb +49 -0
- data/lib/deplate/mod/validate-html.rb +35 -0
- data/lib/deplate/mod/xmlrpc.rb +233 -0
- data/lib/deplate/mod/zh-cn-autospace.rb +108 -0
- data/lib/deplate/mod/zh-cn.rb +59 -0
- data/lib/deplate/once-method.rb +44 -0
- data/lib/deplate/output.rb +249 -0
- data/lib/deplate/particles.rb +815 -0
- data/lib/deplate/regions.rb +1076 -0
- data/lib/deplate/structured.rb +763 -0
- data/lib/deplate/template.rb +430 -0
- data/lib/deplate/templates/html-doc.html +28 -0
- data/lib/deplate/templates/html-left-tabbar-js.html +37 -0
- data/lib/deplate/templates/html-left-tabbar.html +31 -0
- data/lib/deplate/templates/html-tabbar-right-table.html +43 -0
- data/lib/deplate/templates/html-tabbar-right.html +23 -0
- data/lib/deplate/templates/html-tabbar-top.html +43 -0
- data/lib/deplate/templates/html-tabbar.html +31 -0
- data/lib/deplate/wiki-markup.rb +117 -0
- data/lib/deplate/xml.rb +109 -0
- data/lib/deplate/zh-cn.rb +59 -0
- data/lib/ps2ppm.rb +239 -0
- data/man/man1/deplate.1 +692 -0
- metadata +210 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
# zh-cn-autospace.rb
|
2
|
+
# @Author: Thomas Link
|
3
|
+
# @Website: http://deplate.sf.net/
|
4
|
+
# @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
5
|
+
# @Created: 01-Aug-2004.
|
6
|
+
# @Last Change: 23-Okt-2005.
|
7
|
+
# @Revision: 0.222
|
8
|
+
|
9
|
+
require "deplate/zh-cn"
|
10
|
+
|
11
|
+
class Deplate::Formatter
|
12
|
+
attr_reader :cjk_space, :cjk_nospace
|
13
|
+
def hook_pre_setup_zh_cn_autospace
|
14
|
+
@cjk_space = " "
|
15
|
+
@cjk_nospace = ""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Deplate::Formatter::LaTeX
|
20
|
+
def hook_pre_setup_zh_cn_autospace
|
21
|
+
@cjk_space = "~"
|
22
|
+
@cjk_nospace = " "
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Deplate::Core
|
27
|
+
@cjk_nonchars = "%c-%c" % [33, 0xA0]
|
28
|
+
@cjk_rx_C = Regexp.new("[^%s]" % @cjk_nonchars)
|
29
|
+
@cjk_rx_a = Regexp.new("[%s]" % @cjk_nonchars)
|
30
|
+
class << self
|
31
|
+
attr_reader :cjk_nonchars, :cjk_rx_a, :cjk_rx_C
|
32
|
+
end
|
33
|
+
|
34
|
+
def module_initialize_zh_cn_autospace
|
35
|
+
class << self
|
36
|
+
def join_particles(particles)
|
37
|
+
acc = []
|
38
|
+
prev = ""
|
39
|
+
prev_cjk = false
|
40
|
+
particles.delete("")
|
41
|
+
particles.each_with_index do |e, i|
|
42
|
+
if e == " "
|
43
|
+
enext = particles[i + 1]
|
44
|
+
if prev == " " or enext == " "
|
45
|
+
elsif @formatter.cjk_smart_blanks and prev =~ Deplate::Core.cjk_rx_C and enext =~ Deplate::Core.cjk_rx_C
|
46
|
+
acc << @formatter.cjk_nospace
|
47
|
+
else
|
48
|
+
acc << @formatter.cjk_space
|
49
|
+
end
|
50
|
+
else
|
51
|
+
acc << e
|
52
|
+
prev = e
|
53
|
+
end
|
54
|
+
end
|
55
|
+
return acc.join
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def hook_pre_setup_zh_cn_particles
|
61
|
+
register_particle(Deplate::Particle::Space)
|
62
|
+
register_particle(Deplate::Particle::NonCJK)
|
63
|
+
end
|
64
|
+
|
65
|
+
def hook_late_require_zh_cn
|
66
|
+
module_initialize_zh_cn_autospace
|
67
|
+
call_methods_matching(@formatter, /^hook_pre_setup_zh_cn/)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Deplate::Element
|
72
|
+
def join_lines(accum)
|
73
|
+
accum.join(" ")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Deplate::Particle::Space < Deplate::Particle
|
78
|
+
# @@particles << self
|
79
|
+
@rx = /^ /
|
80
|
+
def setup
|
81
|
+
@elt = " "
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Deplate::Particle::NonCJK < Deplate::Particle
|
86
|
+
# @@particles << self
|
87
|
+
@rx = /^([#{Deplate::Core.cjk_nonchars}])/o
|
88
|
+
@part = nil
|
89
|
+
|
90
|
+
class << self
|
91
|
+
attr_accessor :part
|
92
|
+
end
|
93
|
+
|
94
|
+
def setup
|
95
|
+
@elt = @match[0]
|
96
|
+
end
|
97
|
+
|
98
|
+
def process
|
99
|
+
unless self.class.part
|
100
|
+
particles = @@particles + @@particles_extended
|
101
|
+
particles.delete(self.class)
|
102
|
+
self.class.part = particles
|
103
|
+
end
|
104
|
+
@elt = @deplate.parse_with_particles(@container, @elt, self.class.part)
|
105
|
+
@elt = @deplate.format_particles(@elt)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# zh-cn.rb
|
2
|
+
# @Author: Thomas Link
|
3
|
+
# @Website: http://deplate.sf.net/
|
4
|
+
# @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
5
|
+
# @Created: 01-Aug-2004.
|
6
|
+
# @Last Change: 23-Okt-2005.
|
7
|
+
# @Revision: 0.161
|
8
|
+
|
9
|
+
require "deplate/zh-cn"
|
10
|
+
|
11
|
+
class Deplate::Element
|
12
|
+
alias join_lines_re_zh_cn join_lines
|
13
|
+
def join_lines(accum)
|
14
|
+
if @deplate.formatter.matches?("latex")
|
15
|
+
return accum.join
|
16
|
+
else
|
17
|
+
return join_lines_re_zh_cn(accum)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Deplate::Particle::SwallowedSpace < Deplate::Particle
|
23
|
+
# @@particles << self
|
24
|
+
@rx = /^ +/
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@elt = @deplate.formatter.cjk_smart_blanks ? "" : " "
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Deplate::Particle::Space < Deplate::Particle
|
32
|
+
# @@particles << self
|
33
|
+
@rx = /^~/
|
34
|
+
|
35
|
+
def setup
|
36
|
+
@elt = "~"
|
37
|
+
end
|
38
|
+
|
39
|
+
def process
|
40
|
+
if @deplate.formatter.matches?("latex")
|
41
|
+
super
|
42
|
+
else
|
43
|
+
@elt = " "
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Deplate::Core
|
49
|
+
def hook_post_input_initialize_zh_cn_particles
|
50
|
+
register_particle(Deplate::Particle::Space)
|
51
|
+
register_particle(Deplate::Particle::SwallowedSpace)
|
52
|
+
end
|
53
|
+
|
54
|
+
def hook_late_require_zh_cn
|
55
|
+
call_methods_matching(self, /^hook_post_input_initialize_zh_cn_/)
|
56
|
+
call_methods_matching(@formatter, /^hook_pre_setup_zh_cn/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# once-method.rb
|
2
|
+
# @Author: Thomas Link (samul AT web.de)
|
3
|
+
# @Website: http://deplate.sf.net/
|
4
|
+
# @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
5
|
+
# @Created: 25-M�r-2005.
|
6
|
+
# @Last Change: 23-Okt-2005.
|
7
|
+
# @Revision: 0.22
|
8
|
+
#
|
9
|
+
# = Description
|
10
|
+
# Provide poor-man's once methods vor Module class.
|
11
|
+
|
12
|
+
class Module
|
13
|
+
def once_method(*args)
|
14
|
+
for sym in args
|
15
|
+
module_eval <<-CODE
|
16
|
+
alias :#{sym}__once :#{sym}
|
17
|
+
private :#{sym}__once
|
18
|
+
def #{sym}(*args)
|
19
|
+
@@__once ||= {}
|
20
|
+
if (rv = @@__once["#{sym}"])
|
21
|
+
return rv
|
22
|
+
else
|
23
|
+
return (@@__once["#{sym}"] = #{sym}__once(*args))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
CODE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if __FILE__ == $0
|
32
|
+
class TestOnce
|
33
|
+
def foo(x)
|
34
|
+
puts "This is foo being executed"
|
35
|
+
return "bar" * x
|
36
|
+
end
|
37
|
+
once_method :foo
|
38
|
+
end
|
39
|
+
t = TestOnce.new
|
40
|
+
p t.foo(2)
|
41
|
+
p t.foo(3)
|
42
|
+
p t.foo(3)
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,249 @@
|
|
1
|
+
# output.rb
|
2
|
+
# @Author: Thomas Link (samul AT web.de)
|
3
|
+
# @Website: http://deplate.sf.net/
|
4
|
+
# @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
5
|
+
# @Created: 04-Dez-2004.
|
6
|
+
# @Last Change: 02-Nov-2005.
|
7
|
+
# @Revision: 0.245
|
8
|
+
|
9
|
+
require 'forwardable'
|
10
|
+
require 'deplate/metadata'
|
11
|
+
|
12
|
+
# Description:
|
13
|
+
#
|
14
|
+
# Usage:
|
15
|
+
#
|
16
|
+
# TODO:
|
17
|
+
#
|
18
|
+
# CHANGES:
|
19
|
+
#
|
20
|
+
|
21
|
+
class Deplate::Output
|
22
|
+
extend Forwardable
|
23
|
+
|
24
|
+
attr_accessor :pre_matter, :body, :post_matter
|
25
|
+
attr_accessor :top_heading, :index
|
26
|
+
attr_accessor :destination
|
27
|
+
# , :metadata
|
28
|
+
|
29
|
+
def_delegator(:@deplate, :slot_by_name)
|
30
|
+
def_delegator(:@deplate, :log)
|
31
|
+
def_delegator(:@deplate, :call_methods_matching)
|
32
|
+
|
33
|
+
def_delegator(:@meta, :merge_metadata)
|
34
|
+
def_delegator(:@meta, :push_metadata)
|
35
|
+
def_delegator(:@meta, :metadata_available?)
|
36
|
+
def_delegator(:@meta, :metadata_destination)
|
37
|
+
def_delegator(:@meta, :format_metadata)
|
38
|
+
def_delegator(:@meta, :metadata)
|
39
|
+
def_delegator(:@meta, :metadata=)
|
40
|
+
|
41
|
+
class << self
|
42
|
+
def reset
|
43
|
+
@@pre_matter_template = Array.new
|
44
|
+
@@body_template = Array.new
|
45
|
+
@@post_matter_template = Array.new
|
46
|
+
@@idx = 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(deplate, inherited_output=nil)
|
51
|
+
@@idx += 1
|
52
|
+
@deplate = deplate
|
53
|
+
@formatter = deplate.formatter
|
54
|
+
@options = deplate.options
|
55
|
+
@variables = deplate.variables
|
56
|
+
@templates = deplate.templates
|
57
|
+
@meta = Deplate::Metadata.new(deplate, self)
|
58
|
+
# @metadata = {}
|
59
|
+
@destination = nil
|
60
|
+
@index = nil
|
61
|
+
if inherited_output
|
62
|
+
@pre_matter = inherited_output.pre_matter.dup
|
63
|
+
@body = @@body_template.dup
|
64
|
+
@post_matter = inherited_output.post_matter.dup
|
65
|
+
else
|
66
|
+
@pre_matter = @@pre_matter_template.dup
|
67
|
+
@body = @@body_template.dup
|
68
|
+
@post_matter = @@post_matter_template.dup
|
69
|
+
end
|
70
|
+
@top_heading = nil
|
71
|
+
@body_empty_done = false
|
72
|
+
end
|
73
|
+
|
74
|
+
def body_flush
|
75
|
+
call_methods_matching(@formatter, /^hook_pre_body_flush_/)
|
76
|
+
save!
|
77
|
+
log(["Flushing formatted elements", @destination], :debug)
|
78
|
+
process
|
79
|
+
call_methods_matching(@formatter, /^hook_post_body_flush_/)
|
80
|
+
end
|
81
|
+
|
82
|
+
def save!
|
83
|
+
if do_i_feel_empty?
|
84
|
+
@output = nil
|
85
|
+
else
|
86
|
+
call_methods_matching(@formatter, /^hook_pre_output_save_/)
|
87
|
+
@index ||= @top_heading.top_index
|
88
|
+
@destination ||= @top_heading.destination
|
89
|
+
@pre_matter = @pre_matter.dup
|
90
|
+
@body = @body.dup
|
91
|
+
@post_matter = @post_matter.dup
|
92
|
+
call_methods_matching(@formatter, /^hook_post_output_save_/)
|
93
|
+
end
|
94
|
+
log(["Save output", destination], :debug)
|
95
|
+
end
|
96
|
+
|
97
|
+
def process
|
98
|
+
if @options.included
|
99
|
+
peel!
|
100
|
+
else
|
101
|
+
tmpl = @options.template || @variables["template"]
|
102
|
+
if tmpl
|
103
|
+
@variables["@idx"] = @index[0].to_s
|
104
|
+
if File.exist?(tmpl)
|
105
|
+
fill_in_template(tmpl)
|
106
|
+
else
|
107
|
+
template_file = @templates[tmpl]
|
108
|
+
if template_file
|
109
|
+
log(["Using template", template_file], :debug)
|
110
|
+
fill_in_template(template_file)
|
111
|
+
else
|
112
|
+
log(["Unknown template", tmpl], :error)
|
113
|
+
flatten!
|
114
|
+
end
|
115
|
+
end
|
116
|
+
else
|
117
|
+
flatten!
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def body_empty?
|
123
|
+
@body_empty = @body.compact.flatten.empty?
|
124
|
+
log(["Body is empty", caller[0..5]], :debug) if @body_empty
|
125
|
+
@body_empty
|
126
|
+
end
|
127
|
+
|
128
|
+
def do_i_feel_empty?
|
129
|
+
if @body_empty_done
|
130
|
+
@body_empty
|
131
|
+
else
|
132
|
+
@body_empty_done = true
|
133
|
+
body_empty?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
private :do_i_feel_empty?
|
137
|
+
|
138
|
+
def peel!
|
139
|
+
unless do_i_feel_empty?
|
140
|
+
@output = @body.flatten.compact
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def flatten!
|
145
|
+
unless do_i_feel_empty?
|
146
|
+
@output = [@pre_matter, @body, @post_matter].flatten.compact
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def fill_in_template(template_file)
|
151
|
+
@deplate.maintain_current_top(@top_heading) do
|
152
|
+
unless do_i_feel_empty?
|
153
|
+
t = Deplate::Template.new(:file => template_file)
|
154
|
+
@output = t.fill_in(@deplate,
|
155
|
+
:pre => @pre_matter,
|
156
|
+
:body => @body,
|
157
|
+
:post => @post_matter)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def join(sep)
|
163
|
+
@output.join(sep) if @output
|
164
|
+
end
|
165
|
+
|
166
|
+
def pos_and_array(type, pos)
|
167
|
+
if type == :array
|
168
|
+
arr = [pos]
|
169
|
+
pos = 0
|
170
|
+
else
|
171
|
+
pos = slot_by_name(pos)
|
172
|
+
unless pos or pos == 0
|
173
|
+
log(["Undefined slot", pos, type, text], :error) if pos.nil?
|
174
|
+
return
|
175
|
+
end
|
176
|
+
case type
|
177
|
+
when :body, "body"
|
178
|
+
arr = @body
|
179
|
+
when :pre, "preMatter", "pre"
|
180
|
+
arr = @pre_matter
|
181
|
+
when :post, "postMatter", "post"
|
182
|
+
arr = @post_matter
|
183
|
+
when :array
|
184
|
+
else
|
185
|
+
raise "Unknown type: #{type}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
return pos, arr
|
189
|
+
end
|
190
|
+
|
191
|
+
def empty_at?(type, pos)
|
192
|
+
pos, arr = pos_and_array(type, pos)
|
193
|
+
slot = arr[pos]
|
194
|
+
return slot.nil? || slot.empty?
|
195
|
+
end
|
196
|
+
|
197
|
+
def add_at(type, pos, *text)
|
198
|
+
text = text.compact
|
199
|
+
unless text.empty?
|
200
|
+
negative = false
|
201
|
+
pos, arr = pos_and_array(type, pos)
|
202
|
+
if pos
|
203
|
+
negative = pos ? pos < 0 : false
|
204
|
+
if text.first == :prepend
|
205
|
+
negative = true
|
206
|
+
text.shift
|
207
|
+
end
|
208
|
+
pos = pos.abs
|
209
|
+
if arr[pos].nil?
|
210
|
+
arr[pos] = text
|
211
|
+
else
|
212
|
+
for t in text
|
213
|
+
if block_given?
|
214
|
+
arr[pos] = yield(arr[pos], t)
|
215
|
+
elsif negative
|
216
|
+
arr[pos].unshift(t)
|
217
|
+
else
|
218
|
+
arr[pos] << t
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
@formatter.join_blocks(text)
|
223
|
+
else
|
224
|
+
log(["No slot", text], :error)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def union_at(type, pos, *text)
|
230
|
+
add_at(type, pos, *text) do |arr, t|
|
231
|
+
if !arr.include?(t)
|
232
|
+
arr << t
|
233
|
+
else
|
234
|
+
arr
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def set_at(type, pos, *text)
|
240
|
+
add_at(type, pos, *text) do |arr, t|
|
241
|
+
t
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
Deplate::Output.reset
|
248
|
+
|
249
|
+
|