deplate 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/AUTHORS.TXT +26 -0
  2. data/CHANGES.TXT +177 -0
  3. data/LICENSE.TXT +340 -0
  4. data/NEWS.TXT +29 -0
  5. data/README.TXT +86 -0
  6. data/TODO.TXT +202 -0
  7. data/VERSION.TXT +1 -0
  8. data/bin/deplate +3 -0
  9. data/bin/deplate.bat +2 -0
  10. data/etc/deplate.ini +361 -0
  11. data/lib/deplate.rb +31 -0
  12. data/lib/deplate/abstract-class.rb +30 -0
  13. data/lib/deplate/builtin.rb +11 -0
  14. data/lib/deplate/cache.rb +59 -0
  15. data/lib/deplate/commands.rb +693 -0
  16. data/lib/deplate/common.rb +335 -0
  17. data/lib/deplate/converter.rb +99 -0
  18. data/lib/deplate/core.rb +2705 -0
  19. data/lib/deplate/css/article.css +545 -0
  20. data/lib/deplate/css/deplate.css +699 -0
  21. data/lib/deplate/css/heading-navbar.css +29 -0
  22. data/lib/deplate/css/layout-deplate-print.css +540 -0
  23. data/lib/deplate/css/layout-deplate.css +764 -0
  24. data/lib/deplate/css/sans-serif.css +160 -0
  25. data/lib/deplate/css/serif-e.css +170 -0
  26. data/lib/deplate/css/serif-rel.css +121 -0
  27. data/lib/deplate/css/serif.css +190 -0
  28. data/lib/deplate/css/slides.css +11 -0
  29. data/lib/deplate/css/tabbar-left.css +91 -0
  30. data/lib/deplate/css/tabbar-right-ie.css +14 -0
  31. data/lib/deplate/css/tabbar-right.css +118 -0
  32. data/lib/deplate/css/tabbar-top.css +64 -0
  33. data/lib/deplate/css/tabbar.css +81 -0
  34. data/lib/deplate/css/text-sans-serif.css +154 -0
  35. data/lib/deplate/css/text-serif.css +175 -0
  36. data/lib/deplate/define.rb +439 -0
  37. data/lib/deplate/docbook.rb +738 -0
  38. data/lib/deplate/elements.rb +1355 -0
  39. data/lib/deplate/etc.rb +199 -0
  40. data/lib/deplate/external.rb +135 -0
  41. data/lib/deplate/fmt/dbk-article-4.1.2.rb +21 -0
  42. data/lib/deplate/fmt/dbk-article.rb +46 -0
  43. data/lib/deplate/fmt/dbk-book.rb +46 -0
  44. data/lib/deplate/fmt/dbk-ref.rb +105 -0
  45. data/lib/deplate/fmt/dbk-slides.rb +47 -0
  46. data/lib/deplate/fmt/dbk-snippet.rb +21 -0
  47. data/lib/deplate/fmt/html-snippet.rb +21 -0
  48. data/lib/deplate/fmt/html.rb +1696 -0
  49. data/lib/deplate/fmt/htmlsite.rb +419 -0
  50. data/lib/deplate/fmt/htmlslides.rb +21 -0
  51. data/lib/deplate/fmt/htmlwebsite.rb +70 -0
  52. data/lib/deplate/fmt/latex-snippet.rb +22 -0
  53. data/lib/deplate/fmt/latex.rb +1242 -0
  54. data/lib/deplate/fmt/php.rb +19 -0
  55. data/lib/deplate/fmt/phpsite.rb +19 -0
  56. data/lib/deplate/fmt/plain.rb +598 -0
  57. data/lib/deplate/fmt/template.rb +34 -0
  58. data/lib/deplate/fmt/xhtml10t.rb +41 -0
  59. data/lib/deplate/formatter-snippet.rb +17 -0
  60. data/lib/deplate/formatter.rb +1210 -0
  61. data/lib/deplate/input.rb +492 -0
  62. data/lib/deplate/input/deplate-headings.rb +48 -0
  63. data/lib/deplate/input/deplate-restricted.rb +70 -0
  64. data/lib/deplate/input/deplate.rb +28 -0
  65. data/lib/deplate/input/rdoc.rb +277 -0
  66. data/lib/deplate/input/template.rb +29 -0
  67. data/lib/deplate/lib/latex/highlight-extra.sty +15 -0
  68. data/lib/deplate/lib/latex/highlight-typical.sty +15 -0
  69. data/lib/deplate/lib/tabmenu.js +146 -0
  70. data/lib/deplate/locale/de.latin1 +708 -0
  71. data/lib/deplate/locale/ru.koi8-r +48 -0
  72. data/lib/deplate/locale/zh_cn.gb2312 +35 -0
  73. data/lib/deplate/macros.rb +639 -0
  74. data/lib/deplate/messages.rb +120 -0
  75. data/lib/deplate/metadata.rb +77 -0
  76. data/lib/deplate/metadata/marshal.rb +24 -0
  77. data/lib/deplate/metadata/xml.rb +42 -0
  78. data/lib/deplate/metadata/yaml.rb +26 -0
  79. data/lib/deplate/mod/anyword.rb +56 -0
  80. data/lib/deplate/mod/babelfish.rb +27 -0
  81. data/lib/deplate/mod/code-gvim.rb +52 -0
  82. data/lib/deplate/mod/code-highlight.rb +91 -0
  83. data/lib/deplate/mod/colored-log.rb +17 -0
  84. data/lib/deplate/mod/de.rb +19 -0
  85. data/lib/deplate/mod/en.rb +17 -0
  86. data/lib/deplate/mod/endnotes.rb +60 -0
  87. data/lib/deplate/mod/fr.rb +46 -0
  88. data/lib/deplate/mod/html-asciimath.rb +40 -0
  89. data/lib/deplate/mod/html-deplate-button.rb +15 -0
  90. data/lib/deplate/mod/html-headings-navbar.rb +39 -0
  91. data/lib/deplate/mod/html-obfuscate-email.rb +47 -0
  92. data/lib/deplate/mod/html-sidebar.rb +232 -0
  93. data/lib/deplate/mod/htmlslides-navbar-fh.rb +32 -0
  94. data/lib/deplate/mod/iconv.rb +35 -0
  95. data/lib/deplate/mod/imgurl.rb +30 -0
  96. data/lib/deplate/mod/inlatex-compound.rb +69 -0
  97. data/lib/deplate/mod/koma.rb +109 -0
  98. data/lib/deplate/mod/latex-emph-table-head.rb +38 -0
  99. data/lib/deplate/mod/latex-styles.rb +461 -0
  100. data/lib/deplate/mod/latex-verbatim-small.rb +29 -0
  101. data/lib/deplate/mod/makefile.rb +194 -0
  102. data/lib/deplate/mod/mark-external-urls.rb +38 -0
  103. data/lib/deplate/mod/markup-1-warn.rb +37 -0
  104. data/lib/deplate/mod/markup-1.rb +41 -0
  105. data/lib/deplate/mod/navbar-png.rb +33 -0
  106. data/lib/deplate/mod/noindent.rb +32 -0
  107. data/lib/deplate/mod/numpara.rb +40 -0
  108. data/lib/deplate/mod/particle-math.rb +34 -0
  109. data/lib/deplate/mod/php-extra.rb +44 -0
  110. data/lib/deplate/mod/pstoedit.rb +71 -0
  111. data/lib/deplate/mod/recode.rb +57 -0
  112. data/lib/deplate/mod/ru_koi8-r.rb +20 -0
  113. data/lib/deplate/mod/smiley.rb +50 -0
  114. data/lib/deplate/mod/soffice.rb +23 -0
  115. data/lib/deplate/mod/symbols-latin1.rb +58 -0
  116. data/lib/deplate/mod/symbols-od-utf-8.rb +16 -0
  117. data/lib/deplate/mod/symbols-plain.rb +58 -0
  118. data/lib/deplate/mod/symbols-sgml.rb +97 -0
  119. data/lib/deplate/mod/symbols-utf-8.rb +81 -0
  120. data/lib/deplate/mod/symbols-xml.rb +34 -0
  121. data/lib/deplate/mod/syntax-region-alt.rb +37 -0
  122. data/lib/deplate/mod/utf8.rb +49 -0
  123. data/lib/deplate/mod/validate-html.rb +35 -0
  124. data/lib/deplate/mod/xmlrpc.rb +233 -0
  125. data/lib/deplate/mod/zh-cn-autospace.rb +108 -0
  126. data/lib/deplate/mod/zh-cn.rb +59 -0
  127. data/lib/deplate/once-method.rb +44 -0
  128. data/lib/deplate/output.rb +249 -0
  129. data/lib/deplate/particles.rb +815 -0
  130. data/lib/deplate/regions.rb +1076 -0
  131. data/lib/deplate/structured.rb +763 -0
  132. data/lib/deplate/template.rb +430 -0
  133. data/lib/deplate/templates/html-doc.html +28 -0
  134. data/lib/deplate/templates/html-left-tabbar-js.html +37 -0
  135. data/lib/deplate/templates/html-left-tabbar.html +31 -0
  136. data/lib/deplate/templates/html-tabbar-right-table.html +43 -0
  137. data/lib/deplate/templates/html-tabbar-right.html +23 -0
  138. data/lib/deplate/templates/html-tabbar-top.html +43 -0
  139. data/lib/deplate/templates/html-tabbar.html +31 -0
  140. data/lib/deplate/wiki-markup.rb +117 -0
  141. data/lib/deplate/xml.rb +109 -0
  142. data/lib/deplate/zh-cn.rb +59 -0
  143. data/lib/ps2ppm.rb +239 -0
  144. data/man/man1/deplate.1 +692 -0
  145. metadata +210 -0
@@ -0,0 +1,97 @@
1
+ # symbols-sgml.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: 27-Aug-2004.
6
+ # @Last Change: 01-Nov-2005.
7
+ # @Revision: 0.41
8
+
9
+ module Deplate::Symbols::SGML
10
+ def symbol_quote(invoker)
11
+ """ #"""
12
+ end
13
+
14
+ def symbol_gt(invoker)
15
+ ">" #">"
16
+ end
17
+
18
+ def symbol_lt(invoker)
19
+ "<" #"<"
20
+ end
21
+
22
+ def symbol_amp(invoker)
23
+ "&" #"&"
24
+ end
25
+
26
+ def doublequote_open(invoker)
27
+ "“" #"“"
28
+ end
29
+
30
+ def doublequote_close(invoker)
31
+ "”" #"”"
32
+ end
33
+
34
+ def singlequote_open(invoker)
35
+ "‘" #"‘"
36
+ end
37
+
38
+ def singlequote_close(invoker)
39
+ "’" #"’"
40
+ end
41
+
42
+ def nonbreakingspace(invoker)
43
+ " " #%{ }
44
+ end
45
+
46
+ def symbol_paragraph(invoker)
47
+ %{�}
48
+ end
49
+
50
+ def format_symbol(invoker, sym)
51
+ case sym
52
+ when "<-"
53
+ return "&#8592;" #"&larr;"
54
+ when "->"
55
+ return "&#8594;" #"&rarr;"
56
+ when "<=", "<<<"
57
+ return "&#8656;" #"&lArr;"
58
+ when "=>", ">>>"
59
+ return "&#8658;" #"&rArr;"
60
+ when "<->"
61
+ return "&#8596;" #"&harr;"
62
+ when "<=>"
63
+ return "&#8660;" #"&hArr;"
64
+ when "!="
65
+ return "&#8800;" #"&ne;"
66
+ when "~~"
67
+ return "&#8776;" #&asymp;"
68
+ when "..."
69
+ return "&#8230;" #"&hellip;"
70
+ when "--"
71
+ return "&#8211;" #"&ndash;"
72
+ when "=="
73
+ return "&#8801;" #"&equiv;"
74
+ when "+++", "###", "???", "!!!"
75
+ m = formatted_inline("sidebar", formatted_inline("para", plain_text(sym)))
76
+ if defined?(invoker.epilogue)
77
+ invoker.epilogue << m
78
+ return ""
79
+ else
80
+ return m
81
+ end
82
+ # when "<~"
83
+ # return ""
84
+ # when "~>"
85
+ # return ""
86
+ # when "<~>"
87
+ # return ""
88
+ else
89
+ return plain_text(sym)
90
+ end
91
+ end
92
+ end
93
+
94
+ class Deplate::Core
95
+ @@symbols[:sgml] = Deplate::Symbols::SGML
96
+ end
97
+
@@ -0,0 +1,81 @@
1
+ # symbols-sgml.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: 27-Aug-2004.
6
+ # @Last Change: 01-Nov-2005.
7
+ # @Revision: 0.35
8
+
9
+ module Deplate::Symbols::Utf8
10
+ def doublequote_open(invoker)
11
+ %{“}
12
+ end
13
+
14
+ def doublequote_close(invoker)
15
+ %{”}
16
+ end
17
+
18
+ def singlequote_open(invoker)
19
+ %{‘}
20
+ end
21
+
22
+ def singlequote_close(invoker)
23
+ %{’}
24
+ end
25
+
26
+ def nonbreakingspace(invoker)
27
+ %{ }
28
+ end
29
+
30
+ def symbol_paragraph(invoker)
31
+ %{§}
32
+ end
33
+
34
+ def format_symbol(invoker, sym)
35
+ case sym
36
+ when "<-"
37
+ return "←"
38
+ when "->"
39
+ return "→"
40
+ when "<=", "<<<"
41
+ return "◄"
42
+ when "=>", ">>>"
43
+ return "►"
44
+ when "<->"
45
+ return "↔"
46
+ when "<=>"
47
+ return "◄►"
48
+ when "!="
49
+ return "≠"
50
+ when "~~"
51
+ return "≈"
52
+ when "..."
53
+ return "…"
54
+ when "--"
55
+ return "—"
56
+ when "=="
57
+ return "≡"
58
+ when "+++", "###", "???", "!!!"
59
+ m = formatted_inline("sidebar", formatted_inline("para", plain_text(sym)))
60
+ if defined?(invoker.epilogue)
61
+ invoker.epilogue << m
62
+ return ""
63
+ else
64
+ return m
65
+ end
66
+ # when "<~"
67
+ # return ""
68
+ # when "~>"
69
+ # return ""
70
+ # when "<~>"
71
+ # return ""
72
+ else
73
+ return plain_text(sym)
74
+ end
75
+ end
76
+ end
77
+
78
+ class Deplate::Core
79
+ @@symbols["utf-8"] = Deplate::Symbols::Utf8
80
+ end
81
+
@@ -0,0 +1,34 @@
1
+ # symbols-sgml.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: 27-Aug-2004.
6
+ # @Last Change: 01-Nov-2005.
7
+ # @Revision: 0.29
8
+
9
+ require "deplate/mod/symbols-utf-8"
10
+
11
+ module Deplate::Symbols::XML
12
+ include Deplate::Symbols::Utf8
13
+
14
+ def symbol_quote(invoker)
15
+ "&quot;"
16
+ end
17
+
18
+ def symbol_gt(invoker)
19
+ "&gt;"
20
+ end
21
+
22
+ def symbol_lt(invoker)
23
+ "&lt;"
24
+ end
25
+
26
+ def symbol_amp(invoker)
27
+ "&amp;"
28
+ end
29
+ end
30
+
31
+ class Deplate::Core
32
+ @@symbols[:xml] = Deplate::Symbols::XML
33
+ end
34
+
@@ -0,0 +1,37 @@
1
+ # syntax-alt-region.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: 27-Aug-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.15
8
+ #
9
+ # Description:
10
+ # This module provides an alternative syntax for regions, like:
11
+ #
12
+ # ==== Region
13
+ # content
14
+ # ====
15
+ #
16
+
17
+ class Deplate::Element::RegionSyntaxAlt < Deplate::Element::Region
18
+ @@elements << self
19
+ @rx = /^(\s*)(={4,})\s*([A-Z][A-Za-z]*)(.*)$/
20
+
21
+ def get_endrx
22
+ /^#{Regexp.escape(@match[1])}\s*\b.*$/
23
+ end
24
+
25
+ def get_name
26
+ @match[3]
27
+ end
28
+
29
+ def get_args
30
+ @match[4]
31
+ end
32
+
33
+ def get_indent
34
+ @match[1]
35
+ end
36
+ end
37
+
@@ -0,0 +1,49 @@
1
+ # utf8.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: 10-Apr-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.25
8
+ #
9
+ # = Description
10
+ # This file provides improved utf-8 support.
11
+
12
+ class Deplate::Formatter
13
+ def multibyte_leader?(ch)
14
+ ch && ch >= 0b11000000
15
+ end
16
+
17
+ alias :get_first_char_re_utf8 :get_first_char
18
+
19
+ def get_first_char(string, upcase=false)
20
+ ch = string[0]
21
+ if multibyte_leader?(ch)
22
+ if ch >= 0b11110000
23
+ string[0..3]
24
+ elsif ch >= 0b11100000
25
+ string[0..2]
26
+ else
27
+ string[0..1]
28
+ end
29
+ # acc = "" << ch
30
+ # string[1..-1].each_byte do |ch|
31
+ # if ch >= 0b10000000 and !multibyte_leader?(ch)
32
+ # acc << ch
33
+ # else
34
+ # break
35
+ # end
36
+ # end
37
+ # acc
38
+ else
39
+ get_first_char_re_utf8(string, upcase)
40
+ end
41
+ end
42
+ end
43
+
44
+ class Deplate::Core
45
+ def module_initialize_utf8
46
+ @variables['encoding'] = 'UTF-8'
47
+ end
48
+ end
49
+
@@ -0,0 +1,35 @@
1
+ # validate-html.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: 05-Sep-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.21
8
+ #
9
+ # Description:
10
+ #
11
+ # Usage:
12
+ #
13
+ # TODO:
14
+ #
15
+ # CHANGES:
16
+ #
17
+
18
+ class Deplate::Formatter::HTML
19
+ def prepare_validate_html
20
+ valid = []
21
+ unless @deplate.variables["noHtmlValid"]
22
+ valid << %{<a href="http://validator.w3.org/check?uri=referer"><img border="0"
23
+ src="http://www.w3.org/Icons/valid-html401"
24
+ alt="Valid HTML 4.01!" height="31" width="88"></a>}
25
+ end
26
+ unless @deplate.variables["noCssValid"]
27
+ valid << %{<a href="http://jigsaw.w3.org/css-validator/">
28
+ <img style="border:0;width:88px;height:31px"
29
+ src="http://jigsaw.w3.org/css-validator/images/vcss"
30
+ alt="Valid CSS!"></a>}
31
+ end
32
+ output_at(:post, :html_pageicons, valid) unless valid.empty?
33
+ end
34
+ end
35
+
@@ -0,0 +1,233 @@
1
+ # xmlrpc.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: 27-J�n-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.240
8
+ #
9
+ # = Description
10
+ #
11
+ # = Usage
12
+ # In theory, it should work like this:
13
+ #
14
+ # a> deplate -m xmlrpc -&
15
+ # b> irb
16
+ # irb(main):001:0> require 'xmlrpc/client'
17
+ # irb(main):001:0> deplate = XMLRPC::Client.new("localhost", "/deplate", 2000)
18
+ # irb(main):002:0> puts deplate.call("convert", "html", "Some text and more and so on ...")
19
+ # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
20
+ # <html lang="en">
21
+ # <head>
22
+ # [...]
23
+ # irb(main):003:0>
24
+ #
25
+ # = TODO
26
+ # = CHANGES
27
+
28
+ require 'deplate/converter'
29
+ require 'ostruct'
30
+ require 'tmpdir'
31
+ require 'fileutils'
32
+ require 'webrick'
33
+ require 'xmlrpc/server'
34
+
35
+ class Deplate::Core
36
+ def go_now
37
+ @variables["xmlrpcID"] ||= "deplate"
38
+ @xmlrpc_converters = {}
39
+ @xmlrpc_timeout = @variables["xmlrpcTimeout"]
40
+ if @xmlrpc_timeout
41
+ @xmlrpc_timeout = @xmlrpc_timeout.to_i
42
+ else
43
+ @xmlrpc_timeout = 300
44
+ end
45
+
46
+ xml_servlet = XMLRPC::WEBrickServlet.new
47
+ xml_servlet.add_handler("convert") do |format, text|
48
+ xmlrpc_convert_string(format, text)
49
+ end
50
+ xml_servlet.add_handler("shutdown") do |code|
51
+ xmlrpc_shutdown(code)
52
+ end
53
+ xml_servlet.add_handler("convert_string") do |format, text|
54
+ xmlrpc_convert_string(format, text)
55
+ end
56
+ xml_servlet.add_handler("convert_file") do |format, filename|
57
+ xmlrpc_convert_file(format, filename)
58
+ end
59
+ xml_servlet.add_handler("string_to_fileset") do |format, filename, text|
60
+ xmlrpc_string_to_fileset(format, filename, text)
61
+ end
62
+ xml_servlet.add_handler("fileset_to_fileset") do |format, filename, fileset|
63
+ xmlrpc_fileset_to_fileset(format, filename, fileset)
64
+ end
65
+ xml_servlet.add_multicall
66
+
67
+ uri = URI.parse(@sources.first) || OpenStruct.new
68
+ port = uri.port
69
+ unless port
70
+ port = @variables["xmlrpcPort"]
71
+ port = port ? port.to_i : 2000
72
+ end
73
+
74
+ path = uri.path
75
+ if !path or path == "-"
76
+ path = @variables["xmlrpcPath"] || "/deplate"
77
+ end
78
+
79
+ valid_ips = @variables["xmlrpcAllow"]
80
+ if valid_ips
81
+ valid_ips = valid_ips.split(/\s+/)
82
+ valid_ips.collect! do |s|
83
+ if s =~ /^\d+\.\d+\.\d+\.\d+\$/
84
+ s = Regexp.escape(s)
85
+ end
86
+ Regexp.new(s)
87
+ end
88
+ set_valid_ip(valid_ips)
89
+ end
90
+
91
+ log("XMLRPC: Starting server", :anyway)
92
+ # @@log_destination = File.open(@variables["logFile"] || "deplate.log", "w")
93
+ begin
94
+ @xmlrpc_server = WEBrick::HTTPServer.new(:Port => port)
95
+ @xmlrpc_server.mount(path, xml_servlet)
96
+ @xmlrpc_server.logger.level = 1
97
+ trap("INT") { @xmlrpc_server.shutdown }
98
+ @xmlrpc_server.start
99
+ ensure
100
+ # @@log_destination.close
101
+ end
102
+ end
103
+
104
+ def xmlrpc_shutdown(code)
105
+ if @variables['xmlrpcAllowShutdown']
106
+ @xmlrpc_server.shutdown
107
+ return true
108
+ else
109
+ log('Ignored: shutdown', :anyway)
110
+ return false
111
+ end
112
+ end
113
+
114
+ def xmlrpc_convert_string(format, text)
115
+ cvt = get_converter(format)
116
+ if cvt
117
+ return cvt.convert_string(text)
118
+ else
119
+ raise FaultException
120
+ end
121
+ end
122
+
123
+ def xmlrpc_convert_file(format, filename)
124
+ cvt = get_converter(format)
125
+ if cvt
126
+ return cvt.convert_file(filename)
127
+ else
128
+ raise FaultException
129
+ end
130
+ end
131
+
132
+ def xmlrpc_string_to_fileset(format, filename, text)
133
+ convert_to_fileset(filename) do
134
+ convert_and_collect(format, filename, text)
135
+ end
136
+ end
137
+
138
+ def xmlrpc_fileset_to_fileset(format, filename, fileset)
139
+ convert_to_fileset(filename) do
140
+ definition = fileset.delete(filename)
141
+ text = definition["contents"]
142
+ convert_and_collect(format, filename, text) do
143
+ write_fileset(fileset)
144
+ end
145
+ end
146
+ end
147
+
148
+ private
149
+ def convert_to_fileset(fileset_id, &block)
150
+ unless defined?(@tmpdir)
151
+ @tmpdir = @variables["tmpDir"]
152
+ unless @tmpdir
153
+ if Dir.tmpdir
154
+ @tmpdir = File.join(Dir.tmpdir, @variables["xmlrpcID"], fileset_id)
155
+ end
156
+ end
157
+ @lockdir = File.join(Dir.tmpdir,"deplate_locks")
158
+ end
159
+ if @tmpdir
160
+ if File.exists?(@tmpdir)
161
+ FileUtils.rm(Dir[File.join(@tmpdir, "*")])
162
+ else
163
+ FileUtils.mkdir(@tmpdir)
164
+ end
165
+ unless File.exists?(@lockdir)
166
+ FileUtils.mkdir(@lockdir)
167
+ end
168
+ lockfile = File.join(@lockdir, fileset_id)
169
+ if File.exists?(lockfile)
170
+ timeout = File.mtime(lockfile) + @xmlrpc_timeout
171
+ if timeout > Time.now
172
+ log(["XMLRPC: Fileset is locked", fileset_id, timeout], :error)
173
+ raise FaultException
174
+ end
175
+ end
176
+ File.open(lockfile, "w") {|io|}
177
+ begin
178
+ Dir.chdir(@tmpdir)
179
+ return block.call
180
+ ensure
181
+ Dir.chdir(pwd)
182
+ FileUtils.rm(lockfile)
183
+ end
184
+ else
185
+ log("XMLRPC: No writable temporary directory", :error)
186
+ raise FaultException
187
+ end
188
+ end
189
+
190
+ def convert_and_collect(format, filename, text)
191
+ yield if block_given?
192
+ rv = {filename => xmlrpc_convert_string(format, text)}
193
+ collect_fileset(rv)
194
+ return rv
195
+ end
196
+
197
+ def write_fileset(fileset)
198
+ for fname, definition in fileset
199
+ if File.exists?(fname)
200
+ changed = definition["changed"]
201
+ mtime = definition["mtime"]
202
+ size = definition["size"]
203
+ if !changed and mtime and size and mtime == File.mtime(fname) and size == File.size(fname)
204
+ next
205
+ end
206
+ end
207
+ fname = @formatter.encode_id(fname)
208
+ contents = definition["contents"]
209
+ File.open(fname, "w") {|io| io.puts(contents)}
210
+ end
211
+ end
212
+
213
+ def collect_fileset(hash)
214
+ for f in Dir["*"]
215
+ f = @formatter.encode_id(f)
216
+ definition = {}
217
+ definition["mtime"] = File.mtime(f)
218
+ definition["size"] = File.size(f)
219
+ definition["contents"] = File.open(f) {|io| io.read}
220
+ hash[f] = definition
221
+ end
222
+ end
223
+
224
+ def get_converter(format)
225
+ if @variables["xmlrpcReuseInterpreter"]
226
+ cvt = @xmlrpc_converters[format] ||= Deplate::Converter.new(format, :master => self)
227
+ else
228
+ cvt = Deplate::Converter.new(format, :master => self)
229
+ end
230
+ return cvt
231
+ end
232
+ end
233
+