quality_extensions 1.1.6 → 1.3.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.
Files changed (133) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/License +403 -0
  4. data/Rakefile +2 -0
  5. data/Readme.rdoc +2 -3
  6. data/VERSION +1 -0
  7. data/doc_include/ReleaseNotes-0.0.10 +1 -0
  8. data/doc_include/ReleaseNotes-0.0.12 +1 -0
  9. data/doc_include/ReleaseNotes-0.0.13 +2 -0
  10. data/doc_include/ReleaseNotes-0.0.14 +1 -0
  11. data/doc_include/ReleaseNotes-0.0.15 +2 -0
  12. data/doc_include/ReleaseNotes-0.0.16 +1 -0
  13. data/doc_include/ReleaseNotes-0.0.17 +1 -0
  14. data/doc_include/ReleaseNotes-0.0.18 +1 -0
  15. data/doc_include/ReleaseNotes-0.0.19 +1 -0
  16. data/doc_include/ReleaseNotes-0.0.20 +1 -0
  17. data/doc_include/ReleaseNotes-0.0.21 +7 -0
  18. data/doc_include/ReleaseNotes-0.0.22 +2 -0
  19. data/doc_include/ReleaseNotes-0.0.23 +1 -0
  20. data/doc_include/ReleaseNotes-0.0.24 +3 -0
  21. data/doc_include/ReleaseNotes-0.0.25 +3 -0
  22. data/doc_include/ReleaseNotes-0.0.26 +2 -0
  23. data/doc_include/ReleaseNotes-0.0.27 +1 -0
  24. data/doc_include/ReleaseNotes-0.0.28 +1 -0
  25. data/doc_include/ReleaseNotes-0.0.29 +3 -0
  26. data/doc_include/ReleaseNotes-0.0.3 +1 -0
  27. data/doc_include/ReleaseNotes-0.0.30 +4 -0
  28. data/doc_include/ReleaseNotes-0.0.31 +1 -0
  29. data/doc_include/ReleaseNotes-0.0.32 +1 -0
  30. data/doc_include/ReleaseNotes-0.0.33 +1 -0
  31. data/doc_include/ReleaseNotes-0.0.34 +2 -0
  32. data/doc_include/ReleaseNotes-0.0.35 +1 -0
  33. data/doc_include/ReleaseNotes-0.0.36 +1 -0
  34. data/doc_include/ReleaseNotes-0.0.37 +1 -0
  35. data/doc_include/ReleaseNotes-0.0.38 +1 -0
  36. data/doc_include/ReleaseNotes-0.0.39 +1 -0
  37. data/doc_include/ReleaseNotes-0.0.4 +2 -0
  38. data/doc_include/ReleaseNotes-0.0.40 +1 -0
  39. data/doc_include/ReleaseNotes-0.0.41 +1 -0
  40. data/doc_include/ReleaseNotes-0.0.42 +2 -0
  41. data/doc_include/ReleaseNotes-0.0.43 +2 -0
  42. data/doc_include/ReleaseNotes-0.0.44 +3 -0
  43. data/doc_include/ReleaseNotes-0.0.45 +1 -0
  44. data/doc_include/ReleaseNotes-0.0.46 +1 -0
  45. data/doc_include/ReleaseNotes-0.0.47 +1 -0
  46. data/doc_include/ReleaseNotes-0.0.48 +2 -0
  47. data/doc_include/ReleaseNotes-0.0.49 +2 -0
  48. data/doc_include/ReleaseNotes-0.0.5 +1 -0
  49. data/doc_include/ReleaseNotes-0.0.50 +1 -0
  50. data/doc_include/ReleaseNotes-0.0.51 +1 -0
  51. data/doc_include/ReleaseNotes-0.0.52 +1 -0
  52. data/doc_include/ReleaseNotes-0.0.53 +3 -0
  53. data/doc_include/ReleaseNotes-0.0.54 +1 -0
  54. data/doc_include/ReleaseNotes-0.0.55 +2 -0
  55. data/doc_include/ReleaseNotes-0.0.56 +1 -0
  56. data/doc_include/ReleaseNotes-0.0.57 +3 -0
  57. data/doc_include/ReleaseNotes-0.0.58 +1 -0
  58. data/doc_include/ReleaseNotes-0.0.59 +1 -0
  59. data/doc_include/ReleaseNotes-0.0.6 +3 -0
  60. data/doc_include/ReleaseNotes-0.0.60 +3 -0
  61. data/doc_include/ReleaseNotes-0.0.61 +1 -0
  62. data/doc_include/ReleaseNotes-0.0.62 +1 -0
  63. data/doc_include/ReleaseNotes-0.0.63 +1 -0
  64. data/doc_include/ReleaseNotes-0.0.64 +1 -0
  65. data/doc_include/ReleaseNotes-0.0.7 +1 -0
  66. data/doc_include/ReleaseNotes-0.0.8 +2 -0
  67. data/doc_include/ReleaseNotes-0.0.9 +1 -0
  68. data/doc_include/ReleaseNotes-0.1.1 +1 -0
  69. data/doc_include/ReleaseNotes-0.1.2 +1 -0
  70. data/doc_include/ReleaseNotes-0.1.3 +1 -0
  71. data/doc_include/ReleaseNotes-0.1.4 +1 -0
  72. data/doc_include/ReleaseNotes-0.1.5 +0 -0
  73. data/doc_include/ReleaseNotes-1.0.0 +1 -0
  74. data/doc_include/ReleaseNotes-1.0.1 +1 -0
  75. data/doc_include/ReleaseNotes-1.0.2 +1 -0
  76. data/doc_include/ReleaseNotes-1.0.3 +1 -0
  77. data/doc_include/ReleaseNotes-1.1.0 +1 -0
  78. data/doc_include/ReleaseNotes-1.1.1 +1 -0
  79. data/doc_include/ReleaseNotes-1.1.6 +1 -0
  80. data/doc_include/assert_equal_with_difference_highlighting-there_he_is.png +0 -0
  81. data/doc_include/assert_equal_with_difference_highlighting-wheres_waldo.png +0 -0
  82. data/escape/Rakefile +62 -0
  83. data/escape/Readme +16 -0
  84. data/escape/doc_include/ReleaseNotes-0.0.1 +1 -0
  85. data/escape/doc_include/ReleaseNotes-0.0.3 +1 -0
  86. data/escape/doc_include/ReleaseNotes-0.0.4 +1 -0
  87. data/escape/doc_include/ReleaseNotes-0.0.5 +1 -0
  88. data/escape/doc_include/template/qualitysmith.rb +631 -0
  89. data/escape/lib/escape.rb +302 -0
  90. data/escape/pkg/escape-0.0.5.tgz +0 -0
  91. data/escape/pkg/escape-0.0.5.zip +0 -0
  92. data/escape/pkg/escape-0.0.5/Readme +16 -0
  93. data/escape/pkg/escape-0.0.5/doc_include/template/qualitysmith.rb +631 -0
  94. data/escape/pkg/escape-0.0.5/lib/escape.rb +302 -0
  95. data/lib/quality_extensions.rb +3 -1
  96. data/lib/quality_extensions/array/average.rb +45 -0
  97. data/lib/quality_extensions/array/expand_ranges.rb +2 -2
  98. data/lib/quality_extensions/array/shell_escape.rb +2 -2
  99. data/lib/quality_extensions/color/gradiate.rb +5 -5
  100. data/lib/quality_extensions/enumerable/every.rb +2 -2
  101. data/lib/quality_extensions/enumerable/grep_with_index.rb +51 -0
  102. data/lib/quality_extensions/enumerable/grepv.rb +1 -0
  103. data/lib/quality_extensions/enumerable/map_with_index.rb +2 -0
  104. data/lib/quality_extensions/enumerable/max_by_value.rb +72 -0
  105. data/lib/quality_extensions/enumerable/select_while.rb +7 -2
  106. data/lib/quality_extensions/enumerable/select_with_index.rb +2 -2
  107. data/lib/quality_extensions/float/truncate.rb +2 -1
  108. data/lib/quality_extensions/hash/except.rb +2 -2
  109. data/lib/quality_extensions/hash/to_query_string.rb +6 -6
  110. data/lib/quality_extensions/helpers/numbers.rb +259 -0
  111. data/lib/quality_extensions/kernel/die.rb +2 -2
  112. data/lib/quality_extensions/kernel/filter_output.rb +1 -0
  113. data/lib/quality_extensions/kernel/require_all.rb +7 -7
  114. data/lib/quality_extensions/module/guard_method.rb +3 -3
  115. data/lib/quality_extensions/object/non.rb +10 -4
  116. data/lib/quality_extensions/pathname.rb +51 -3
  117. data/lib/quality_extensions/regexp/named_captures.rb +7 -6
  118. data/lib/quality_extensions/regexp/to_plain_s.rb +116 -0
  119. data/lib/quality_extensions/safe_method.rb +100 -0
  120. data/lib/quality_extensions/safe_nil.rb +87 -11
  121. data/lib/quality_extensions/string/chomped_lines.rb +0 -0
  122. data/lib/quality_extensions/string/integer_eh.rb +2 -2
  123. data/lib/quality_extensions/string/prefix.rb +120 -0
  124. data/lib/quality_extensions/string/prefix_lines.rb +4 -69
  125. data/lib/quality_extensions/string/safe_numeric_conversion.rb +5 -5
  126. data/lib/quality_extensions/string/shell_escape.rb +3 -3
  127. data/lib/quality_extensions/string/to_proc.rb +119 -0
  128. data/lib/quality_extensions/template.rb +2 -2
  129. data/lib/quality_extensions/test/difference_highlighting.rb +2 -2
  130. data/lib/quality_extensions/version.rb +3 -0
  131. data/quality_extensions.gemspec +21 -0
  132. metadata +249 -145
  133. data/lib/Xfind_bug_test.rb +0 -28
@@ -0,0 +1,302 @@
1
+ # escape.rb - escape/unescape library for several formats
2
+ #
3
+ # Copyright (C) 2006,2007 Tanaka Akira <akr@fsij.org>
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ # 3. The name of the author may not be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
+ # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
+ # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25
+ # OF SUCH DAMAGE.
26
+
27
+ # Escape module provides several escape functions.
28
+ # * URI
29
+ # * HTML
30
+ # * shell command
31
+ module Escape
32
+ module_function
33
+
34
+ class StringWrapper
35
+ class << self
36
+ alias new_no_dup new
37
+ def new(str)
38
+ new_no_dup(str.dup)
39
+ end
40
+ end
41
+
42
+ def initialize(str)
43
+ @str = str
44
+ end
45
+
46
+ def to_s
47
+ @str.dup
48
+ end
49
+
50
+ def inspect
51
+ "\#<#{self.class}: #{@str}>"
52
+ end
53
+
54
+ def ==(other)
55
+ other.class == self.class && @str == other.instance_variable_get(:@str)
56
+ end
57
+ alias eql? ==
58
+
59
+ def hash
60
+ @str.hash
61
+ end
62
+ end
63
+
64
+ class ShellEscaped < StringWrapper
65
+ end
66
+
67
+ # Escape.shell_command composes
68
+ # a sequence of words to
69
+ # a single shell command line.
70
+ # All shell meta characters are quoted and
71
+ # the words are concatenated with interleaving space.
72
+ # It returns an instance of ShellEscaped.
73
+ #
74
+ # Escape.shell_command(["ls", "/"]) #=> #<Escape::ShellEscaped: ls />
75
+ # Escape.shell_command(["echo", "*"]) #=> #<Escape::ShellEscaped: echo '*'>
76
+ #
77
+ # Note that system(*command) and
78
+ # system(Escape.shell_command(command)) is roughly same.
79
+ # There are two exception as follows.
80
+ # * The first is that the later may invokes /bin/sh.
81
+ # * The second is an interpretation of an array with only one element:
82
+ # the element is parsed by the shell with the former but
83
+ # it is recognized as single word with the later.
84
+ # For example, system(*["echo foo"]) invokes echo command with an argument "foo".
85
+ # But system(Escape.shell_command(["echo foo"])) invokes "echo foo" command without arguments (and it probably fails).
86
+ def shell_command(command)
87
+ s = command.map {|word| shell_single_word(word) }.join(' ')
88
+ ShellEscaped.new_no_dup(s)
89
+ end
90
+
91
+ # Escape.shell_single_word quotes shell meta characters.
92
+ # It returns an instance of ShellEscaped.
93
+ #
94
+ # The result string is always single shell word, even if
95
+ # the argument is "".
96
+ # Escape.shell_single_word("") returns #<Escape::ShellEscaped: ''>.
97
+ #
98
+ # Escape.shell_single_word("") #=> #<Escape::ShellEscaped: ''>
99
+ # Escape.shell_single_word("foo") #=> #<Escape::ShellEscaped: foo>
100
+ # Escape.shell_single_word("*") #=> #<Escape::ShellEscaped: '*'>
101
+ def shell_single_word(str)
102
+ if str.empty?
103
+ ShellEscaped.new_no_dup("''")
104
+ elsif %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ str
105
+ ShellEscaped.new(str)
106
+ else
107
+ result = ''
108
+ str.scan(/('+)|[^']+/) {
109
+ if $1
110
+ result << %q{\'} * $1.length
111
+ else
112
+ result << "'#{$&}'"
113
+ end
114
+ }
115
+ ShellEscaped.new_no_dup(result)
116
+ end
117
+ end
118
+
119
+ class PercentEncoded < StringWrapper
120
+ end
121
+
122
+ # Escape.uri_segment escapes URI segment using percent-encoding.
123
+ # It returns an instance of PercentEncoded.
124
+ #
125
+ # Escape.uri_segment("a/b") #=> #<Escape::PercentEncoded: a%2Fb>
126
+ #
127
+ # The segment is "/"-splitted element after authority before query in URI, as follows.
128
+ #
129
+ # scheme://authority/segment1/segment2/.../segmentN?query#fragment
130
+ #
131
+ # See RFC 3986 for details of URI.
132
+ def uri_segment(str)
133
+ # pchar - pct-encoded = unreserved / sub-delims / ":" / "@"
134
+ # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
135
+ # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
136
+ s = str.gsub(%r{[^A-Za-z0-9\-._~!$&'()*+,;=:@]}n) {
137
+ '%' + $&.unpack("H2")[0].upcase
138
+ }
139
+ PercentEncoded.new_no_dup(s)
140
+ end
141
+
142
+ # Escape.uri_path escapes URI path using percent-encoding.
143
+ # The given path should be a sequence of (non-escaped) segments separated by "/".
144
+ # The segments cannot contains "/".
145
+ # It returns an instance of PercentEncoded.
146
+ #
147
+ # Escape.uri_path("a/b/c") #=> #<Escape::PercentEncoded: a/b/c>
148
+ # Escape.uri_path("a?b/c?d/e?f") #=> #<Escape::PercentEncoded: a%3Fb/c%3Fd/e%3Ff>
149
+ #
150
+ # The path is the part after authority before query in URI, as follows.
151
+ #
152
+ # scheme://authority/path#fragment
153
+ #
154
+ # See RFC 3986 for details of URI.
155
+ #
156
+ # Note that this function is not appropriate to convert OS path to URI.
157
+ def uri_path(str)
158
+ s = str.gsub(%r{[^/]+}n) { uri_segment($&) }
159
+ PercentEncoded.new_no_dup(s)
160
+ end
161
+
162
+ # :stopdoc:
163
+ def html_form_fast(pairs, sep='&')
164
+ s = pairs.map {|k, v|
165
+ # query-chars - pct-encoded - x-www-form-urlencoded-delimiters =
166
+ # unreserved / "!" / "$" / "'" / "(" / ")" / "*" / "," / ":" / "@" / "/" / "?"
167
+ # query-char - pct-encoded = unreserved / sub-delims / ":" / "@" / "/" / "?"
168
+ # query-char = pchar / "/" / "?" = unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?"
169
+ # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
170
+ # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
171
+ # x-www-form-urlencoded-delimiters = "&" / "+" / ";" / "="
172
+ k = k.gsub(%r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n) {
173
+ '%' + $&.unpack("H2")[0].upcase
174
+ }
175
+ v = v.gsub(%r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n) {
176
+ '%' + $&.unpack("H2")[0].upcase
177
+ }
178
+ "#{k}=#{v}"
179
+ }.join(sep)
180
+ PercentEncoded.new_no_dup(s)
181
+ end
182
+ # :startdoc:
183
+
184
+ # Escape.html_form composes HTML form key-value pairs as a x-www-form-urlencoded encoded string.
185
+ # It returns an instance of PercentEncoded.
186
+ #
187
+ # Escape.html_form takes an array of pair of strings or
188
+ # an hash from string to string.
189
+ #
190
+ # Escape.html_form([["a","b"], ["c","d"]]) #=> #<Escape::PercentEncoded: a=b&c=d>
191
+ # Escape.html_form({"a"=>"b", "c"=>"d"}) #=> #<Escape::PercentEncoded: a=b&c=d>
192
+ #
193
+ # In the array form, it is possible to use same key more than once.
194
+ # (It is required for a HTML form which contains
195
+ # checkboxes and select element with multiple attribute.)
196
+ #
197
+ # Escape.html_form([["k","1"], ["k","2"]]) #=> #<Escape::PercentEncoded: k=1&k=2>
198
+ #
199
+ # If the strings contains characters which must be escaped in x-www-form-urlencoded,
200
+ # they are escaped using %-encoding.
201
+ #
202
+ # Escape.html_form([["k=","&;="]]) #=> #<Escape::PercentEncoded: k%3D=%26%3B%3D>
203
+ #
204
+ # The separator can be specified by the optional second argument.
205
+ #
206
+ # Escape.html_form([["a","b"], ["c","d"]], ";") #=> #<Escape::PercentEncoded: a=b;c=d>
207
+ #
208
+ # See HTML 4.01 for details.
209
+ def html_form(pairs, sep='&')
210
+ r = ''
211
+ first = true
212
+ pairs.each {|k, v|
213
+ # query-chars - pct-encoded - x-www-form-urlencoded-delimiters =
214
+ # unreserved / "!" / "$" / "'" / "(" / ")" / "*" / "," / ":" / "@" / "/" / "?"
215
+ # query-char - pct-encoded = unreserved / sub-delims / ":" / "@" / "/" / "?"
216
+ # query-char = pchar / "/" / "?" = unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?"
217
+ # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
218
+ # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
219
+ # x-www-form-urlencoded-delimiters = "&" / "+" / ";" / "="
220
+ r << sep if !first
221
+ first = false
222
+ k.each_byte {|byte|
223
+ ch = byte.chr
224
+ if %r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n =~ ch
225
+ r << "%" << ch.unpack("H2")[0].upcase
226
+ else
227
+ r << ch
228
+ end
229
+ }
230
+ r << '='
231
+ v.each_byte {|byte|
232
+ ch = byte.chr
233
+ if %r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n =~ ch
234
+ r << "%" << ch.unpack("H2")[0].upcase
235
+ else
236
+ r << ch
237
+ end
238
+ }
239
+ }
240
+ PercentEncoded.new_no_dup(r)
241
+ end
242
+
243
+ class HTMLEscaped < StringWrapper
244
+ end
245
+
246
+ # :stopdoc:
247
+ HTML_TEXT_ESCAPE_HASH = {
248
+ '&' => '&amp;',
249
+ '<' => '&lt;',
250
+ '>' => '&gt;',
251
+ }
252
+ # :startdoc:
253
+
254
+ # Escape.html_text escapes a string appropriate for HTML text using character references.
255
+ # It returns an instance of HTMLEscaped.
256
+ #
257
+ # It escapes 3 characters:
258
+ # * '&' to '&amp;'
259
+ # * '<' to '&lt;'
260
+ # * '>' to '&gt;'
261
+ #
262
+ # Escape.html_text("abc") #=> #<Escape::HTMLEscaped: abc>
263
+ # Escape.html_text("a & b < c > d") #=> #<Escape::HTMLEscaped: a &amp; b &lt; c &gt; d>
264
+ #
265
+ # This function is not appropriate for escaping HTML element attribute
266
+ # because quotes are not escaped.
267
+ def html_text(str)
268
+ s = str.gsub(/[&<>]/) {|ch| HTML_TEXT_ESCAPE_HASH[ch] }
269
+ HTMLEscaped.new_no_dup(s)
270
+ end
271
+
272
+ # :stopdoc:
273
+ HTML_ATTR_ESCAPE_HASH = {
274
+ '&' => '&amp;',
275
+ '<' => '&lt;',
276
+ '>' => '&gt;',
277
+ '"' => '&quot;',
278
+ }
279
+ # :startdoc:
280
+
281
+ class HTMLAttrValue < StringWrapper
282
+ end
283
+
284
+ # Escape.html_attr_value encodes a string as a double-quoted HTML attribute using character references.
285
+ # It returns an instance of HTMLAttrValue.
286
+ #
287
+ # Escape.html_attr_value("abc") #=> #<Escape::HTMLAttrValue: "abc">
288
+ # Escape.html_attr_value("a&b") #=> #<Escape::HTMLAttrValue: "a&amp;b">
289
+ # Escape.html_attr_value("ab&<>\"c") #=> #<Escape::HTMLAttrValue: "ab&amp;&lt;&gt;&quot;c">
290
+ # Escape.html_attr_value("a'c") #=> #<Escape::HTMLAttrValue: "a'c">
291
+ #
292
+ # It escapes 4 characters:
293
+ # * '&' to '&amp;'
294
+ # * '<' to '&lt;'
295
+ # * '>' to '&gt;'
296
+ # * '"' to '&quot;'
297
+ #
298
+ def html_attr_value(str)
299
+ s = '"' + str.gsub(/[&<>"]/) {|ch| HTML_ATTR_ESCAPE_HASH[ch] } + '"'
300
+ HTMLAttrValue.new_no_dup(s)
301
+ end
302
+ end
@@ -0,0 +1,16 @@
1
+ = Escape
2
+
3
+ [<b>Home page</b>:] ?
4
+ [<b>Gem install</b>:] <tt>gem install escape</tt>
5
+ [<b>Author</b>:] Tanaka Akira
6
+ [<b>Copyright</b>:] Copyright (C) 2006,2007 Tanaka Akira <akr@fsij.org>
7
+ [<b>License</b>:] Looks like the BSD license
8
+
9
+ == Introduction
10
+
11
+ I only turned this into a gem to make it easier for my code to specify a dependency on it. For those of us used to the ease of use afforded by gems, it's hard to ask users to download and manually install the escape library...
12
+
13
+ However, it appears that escape.rb now ships standard with newer versions of Ruby, so this gem may not be needed at all any more (unless you have an old version).
14
+
15
+ (It is available as /usr/lib/ruby/1.8/escape.rb, at least in my version of ruby: ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux])
16
+
@@ -0,0 +1,631 @@
1
+ module RDoc
2
+ module Page
3
+
4
+ FONTS = "\"Bitstream Vera Sans\", Verdana, Arial, Helvetica, sans-serif"
5
+
6
+ STYLE = <<CSS
7
+ a {
8
+ color: #00F;
9
+ text-decoration: none;
10
+ }
11
+
12
+ a:hover {
13
+ color: #77F;
14
+ text-decoration: underline;
15
+ }
16
+
17
+ body, td, p {
18
+ font-family: %fonts%;
19
+ background: #FFF;
20
+ color: #000;
21
+ margin: 0px;
22
+ font-size: small;
23
+ }
24
+
25
+ #content {
26
+ margin: 2em;
27
+ }
28
+
29
+ #description p {
30
+ margin-bottom: 0.5em;
31
+ }
32
+
33
+ .sectiontitle {
34
+ margin-top: 1em;
35
+ margin-bottom: 1em;
36
+ padding: 0.5em;
37
+ padding-left: 2em;
38
+ background: #005;
39
+ color: #FFF;
40
+ font-weight: bold;
41
+ border: 1px dotted black;
42
+ }
43
+
44
+ .attr-rw {
45
+ padding-left: 1em;
46
+ padding-right: 1em;
47
+ text-align: center;
48
+ color: #055;
49
+ }
50
+
51
+ .attr-name {
52
+ font-weight: bold;
53
+ }
54
+
55
+ .attr-desc {
56
+ }
57
+
58
+ .attr-value {
59
+ font-family: monospace;
60
+ }
61
+
62
+ .file-title-prefix {
63
+ font-size: large;
64
+ }
65
+
66
+ .file-title {
67
+ font-size: large;
68
+ font-weight: bold;
69
+ background: #005;
70
+ color: #FFF;
71
+ }
72
+
73
+ .banner {
74
+ background: #005;
75
+ color: #FFF;
76
+ border: 1px solid black;
77
+ padding: 1em;
78
+ }
79
+
80
+ .banner td {
81
+ background: transparent;
82
+ color: #FFF;
83
+ }
84
+
85
+ h1 a, h2 a, .sectiontitle a, .banner a {
86
+ color: #FF0;
87
+ }
88
+
89
+ h1 a:hover, h2 a:hover, .sectiontitle a:hover, .banner a:hover {
90
+ color: #FF7;
91
+ }
92
+
93
+ .dyn-source {
94
+ display: none;
95
+ background: #FFE;
96
+ color: #000;
97
+ border: 1px dotted black;
98
+ margin: 0.5em 2em 0.5em 2em;
99
+ padding: 0.5em;
100
+ }
101
+
102
+ .dyn-source .cmt {
103
+ color: #00F;
104
+ font-style: italic;
105
+ }
106
+
107
+ .dyn-source .kw {
108
+ color: #070;
109
+ font-weight: bold;
110
+ }
111
+
112
+ .method {
113
+ margin-left: 1em;
114
+ margin-right: 1em;
115
+ margin-bottom: 1em;
116
+ }
117
+
118
+ .description pre {
119
+ padding: 0.5em;
120
+ border: 1px dotted black;
121
+ background: #FFE;
122
+ }
123
+
124
+ .method .title {
125
+ font-family: monospace;
126
+ font-size: large;
127
+ border-bottom: 1px dashed black;
128
+ margin-bottom: 0.3em;
129
+ padding-bottom: 0.1em;
130
+ }
131
+
132
+ .method .description, .method .sourcecode {
133
+ margin-left: 1em;
134
+ }
135
+
136
+ .description p, .sourcecode p {
137
+ margin-bottom: 0.5em;
138
+ }
139
+
140
+ .method .sourcecode p.source-link {
141
+ text-indent: 0em;
142
+ margin-top: 0.5em;
143
+ }
144
+
145
+ .method .aka {
146
+ margin-top: 0.3em;
147
+ margin-left: 1em;
148
+ font-style: italic;
149
+ text-indent: 2em;
150
+ }
151
+
152
+ h1 {
153
+ padding: 1em;
154
+ border: 1px solid black;
155
+ font-size: x-large;
156
+ font-weight: bold;
157
+ color: #FFF;
158
+ background: #007;
159
+ }
160
+
161
+ h2 {
162
+ padding: 0.5em 1em 0.5em 1em;
163
+ border: 1px solid black;
164
+ font-size: large;
165
+ font-weight: bold;
166
+ color: #FFF;
167
+ background: #009;
168
+ }
169
+
170
+ h3, h4, h5, h6 {
171
+ padding: 0.2em 1em 0.2em 1em;
172
+ border: 1px dashed black;
173
+ color: #000;
174
+ background: #AAF;
175
+ }
176
+
177
+ .sourcecode > pre {
178
+ padding: 0.5em;
179
+ border: 1px dotted black;
180
+ background: #FFE;
181
+ }
182
+
183
+ CSS
184
+
185
+ XHTML_PREAMBLE = %{<?xml version="1.0" encoding="%charset%"?>
186
+ <!DOCTYPE html
187
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
188
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
189
+ }
190
+
191
+ HEADER = XHTML_PREAMBLE + <<ENDHEADER
192
+ <html>
193
+ <head>
194
+ <title>%title%</title>
195
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
196
+ <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" />
197
+
198
+ <script language="JavaScript" type="text/javascript">
199
+ // <![CDATA[
200
+
201
+ function toggleSource( id )
202
+ {
203
+ var elem
204
+ var link
205
+
206
+ if( document.getElementById )
207
+ {
208
+ elem = document.getElementById( id )
209
+ link = document.getElementById( "l_" + id )
210
+ }
211
+ else if ( document.all )
212
+ {
213
+ elem = eval( "document.all." + id )
214
+ link = eval( "document.all.l_" + id )
215
+ }
216
+ else
217
+ return false;
218
+
219
+ if( elem.style.display == "block" )
220
+ {
221
+ elem.style.display = "none"
222
+ link.innerHTML = "show source"
223
+ }
224
+ else
225
+ {
226
+ elem.style.display = "block"
227
+ link.innerHTML = "hide source"
228
+ }
229
+ }
230
+
231
+ function openCode( url )
232
+ {
233
+ window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
234
+ }
235
+ // ]]>
236
+ </script>
237
+ </head>
238
+
239
+ <body>
240
+ ENDHEADER
241
+
242
+ FILE_PAGE = <<HTML
243
+ <table border='0' cellpadding='0' cellspacing='0' width="100%" class='banner'>
244
+ <tr><td>
245
+ <table width="100%" border='0' cellpadding='0' cellspacing='0'><tr>
246
+ <td class="file-title" colspan="2"><span class="file-title-prefix">File</span><br />%short_name%</td>
247
+ <td align="right">
248
+ <table border='0' cellspacing="0" cellpadding="2">
249
+ <tr>
250
+ <td>Path:</td>
251
+ <td>%full_path%
252
+ IF:cvsurl
253
+ &nbsp;(<a href="%cvsurl%">CVS</a>)
254
+ ENDIF:cvsurl
255
+ </td>
256
+ </tr>
257
+ <tr>
258
+ <td>Modified:</td>
259
+ <td>%dtm_modified%</td>
260
+ </tr>
261
+ </table>
262
+ </td></tr>
263
+ </table>
264
+ </td></tr>
265
+ </table><br>
266
+ HTML
267
+
268
+ ###################################################################
269
+
270
+ CLASS_PAGE = <<HTML
271
+ <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
272
+ <td class="file-title"><span class="file-title-prefix">%classmod%</span><br />%full_name%</td>
273
+ <td align="right">
274
+ <table cellspacing=0 cellpadding=2>
275
+ <tr valign="top">
276
+ <td>In:</td>
277
+ <td>
278
+ START:infiles
279
+ HREF:full_path_url:full_path:
280
+ IF:cvsurl
281
+ &nbsp;(<a href="%cvsurl%">CVS</a>)
282
+ ENDIF:cvsurl
283
+ END:infiles
284
+ </td>
285
+ </tr>
286
+ IF:parent
287
+ <tr>
288
+ <td>Parent:</td>
289
+ <td>
290
+ IF:par_url
291
+ <a href="%par_url%">
292
+ ENDIF:par_url
293
+ %parent%
294
+ IF:par_url
295
+ </a>
296
+ ENDIF:par_url
297
+ </td>
298
+ </tr>
299
+ ENDIF:parent
300
+ </table>
301
+ </td>
302
+ </tr>
303
+ </table>
304
+ HTML
305
+
306
+ ###################################################################
307
+
308
+ METHOD_LIST = <<HTML
309
+ <div id="content">
310
+ IF:diagram
311
+ <table cellpadding='0' cellspacing='0' border='0' width="100%"><tr><td align="center">
312
+ %diagram%
313
+ </td></tr></table>
314
+ ENDIF:diagram
315
+
316
+ IF:description
317
+ <div class="description">%description%</div>
318
+ ENDIF:description
319
+
320
+ IF:requires
321
+ <div class="sectiontitle">Required Files</div>
322
+ <ul>
323
+ START:requires
324
+ <li>HREF:aref:name:</li>
325
+ END:requires
326
+ </ul>
327
+ ENDIF:requires
328
+
329
+ IF:toc
330
+ <div class="sectiontitle">Contents</div>
331
+ <ul>
332
+ START:toc
333
+ <li><a href="#%href%">%secname%</a></li>
334
+ END:toc
335
+ </ul>
336
+ ENDIF:toc
337
+
338
+ IF:methods
339
+ <div class="sectiontitle">Methods</div>
340
+ <ul>
341
+ START:methods
342
+ <li>HREF:aref:name:</li>
343
+ END:methods
344
+ </ul>
345
+ ENDIF:methods
346
+
347
+ IF:includes
348
+ <div class="sectiontitle">Included Modules</div>
349
+ <ul>
350
+ START:includes
351
+ <li>HREF:aref:name:</li>
352
+ END:includes
353
+ </ul>
354
+ ENDIF:includes
355
+
356
+ START:sections
357
+ IF:sectitle
358
+ <div class="sectiontitle"><a name="%secsequence%">%sectitle%</a></div>
359
+ IF:seccomment
360
+ <div class="description">
361
+ %seccomment%
362
+ </div>
363
+ ENDIF:seccomment
364
+ ENDIF:sectitle
365
+
366
+ IF:classlist
367
+ <div class="sectiontitle">Classes and Modules</div>
368
+ %classlist%
369
+ ENDIF:classlist
370
+
371
+ IF:constants
372
+ <div class="sectiontitle">Constants</div>
373
+ <table border='0' cellpadding='5'>
374
+ START:constants
375
+ <tr valign='top'>
376
+ <td class="attr-name">%name%</td>
377
+ <td>=</td>
378
+ <td class="attr-value">%value%</td>
379
+ </tr>
380
+ IF:desc
381
+ <tr valign='top'>
382
+ <td>&nbsp;</td>
383
+ <td colspan="2" class="attr-desc">%desc%</td>
384
+ </tr>
385
+ ENDIF:desc
386
+ END:constants
387
+ </table>
388
+ ENDIF:constants
389
+
390
+ IF:attributes
391
+ <div class="sectiontitle">Attributes</div>
392
+ <table border='0' cellpadding='5'>
393
+ START:attributes
394
+ <tr valign='top'>
395
+ <td class='attr-rw'>
396
+ IF:rw
397
+ [%rw%]
398
+ ENDIF:rw
399
+ </td>
400
+ <td class='attr-name'>%name%</td>
401
+ <td class='attr-desc'>%a_desc%</td>
402
+ </tr>
403
+ END:attributes
404
+ </table>
405
+ ENDIF:attributes
406
+
407
+ IF:method_list
408
+ START:method_list
409
+ IF:methods
410
+ <div class="sectiontitle">%type% %category% methods</div>
411
+ START:methods
412
+ <div class="method">
413
+ <div class="title">
414
+ IF:callseq
415
+ <a name="%aref%"></a><b>%callseq%</b>
416
+ ENDIF:callseq
417
+ IFNOT:callseq
418
+ <a name="%aref%"></a><b>%name%</b>%params%
419
+ ENDIF:callseq
420
+ IF:codeurl
421
+ [ <a href="javascript:openCode('%codeurl%')">source</a> ]
422
+ ENDIF:codeurl
423
+ </div>
424
+ IF:m_desc
425
+ <div class="description">
426
+ %m_desc%
427
+ </div>
428
+ ENDIF:m_desc
429
+ IF:aka
430
+ <div class="aka">
431
+ This method is also aliased as
432
+ START:aka
433
+ <a href="%aref%">%name%</a>
434
+ END:aka
435
+ </div>
436
+ ENDIF:aka
437
+ IF:sourcecode
438
+ <div class="sourcecode">
439
+ <p class="source-link">[ <a href="javascript:toggleSource('%aref%_source')" id="l_%aref%_source">show source</a> ]</p>
440
+ <div id="%aref%_source" class="dyn-source">
441
+ <pre>
442
+ %sourcecode%
443
+ </pre>
444
+ </div>
445
+ </div>
446
+ ENDIF:sourcecode
447
+ </div>
448
+ END:methods
449
+ ENDIF:methods
450
+ END:method_list
451
+ ENDIF:method_list
452
+ END:sections
453
+ </div>
454
+ HTML
455
+
456
+ FOOTER = <<ENDFOOTER
457
+ </body>
458
+ </html>
459
+ ENDFOOTER
460
+
461
+ BODY = HEADER + <<ENDBODY
462
+ !INCLUDE! <!-- banner header -->
463
+
464
+ <div id="bodyContent">
465
+ #{METHOD_LIST}
466
+ </div>
467
+
468
+ #{FOOTER}
469
+ ENDBODY
470
+
471
+ ########################## Source code ##########################
472
+
473
+ SRC_PAGE = XHTML_PREAMBLE + <<HTML
474
+ <html>
475
+ <head><title>%title%</title>
476
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
477
+ <style>
478
+ .ruby-comment { color: green; font-style: italic }
479
+ .ruby-constant { color: #4433aa; font-weight: bold; }
480
+ .ruby-identifier { color: #222222; }
481
+ .ruby-ivar { color: #2233dd; }
482
+ .ruby-keyword { color: #3333FF; font-weight: bold }
483
+ .ruby-node { color: #777777; }
484
+ .ruby-operator { color: #111111; }
485
+ .ruby-regexp { color: #662222; }
486
+ .ruby-value { color: #662222; font-style: italic }
487
+ .kw { color: #3333FF; font-weight: bold }
488
+ .cmt { color: green; font-style: italic }
489
+ .str { color: #662222; font-style: italic }
490
+ .re { color: #662222; }
491
+ </style>
492
+ </head>
493
+ <body bgcolor="white">
494
+ <pre>%code%</pre>
495
+ </body>
496
+ </html>
497
+ HTML
498
+
499
+ ########################## Index ################################
500
+
501
+ FR_INDEX_BODY = <<HTML
502
+ !INCLUDE!
503
+ HTML
504
+
505
+ FILE_INDEX = XHTML_PREAMBLE + <<HTML
506
+ <html>
507
+ <head>
508
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
509
+ <style>
510
+ <!--
511
+ body {
512
+ background-color: #EEE;
513
+ font-family: #{FONTS};
514
+ color: #000;
515
+ margin: 0px;
516
+ }
517
+ .banner {
518
+ background: #005;
519
+ color: #FFF;
520
+ padding: 0.2em;
521
+ font-size: small;
522
+ font-weight: bold;
523
+ text-align: center;
524
+ }
525
+ .entries {
526
+ margin: 0.25em 1em 0 1em;
527
+ font-size: x-small;
528
+ }
529
+ a {
530
+ display: block;
531
+ color: #00F;
532
+ text-decoration: none;
533
+ white-space: nowrap;
534
+ }
535
+ a:hover {
536
+ color: #77F;
537
+ text-decoration: underline;
538
+ }
539
+ input#link_search {
540
+ color: #a00;
541
+ }
542
+ input#link_search.default {
543
+ color: #888;
544
+ }
545
+ -->
546
+ </style>
547
+ <script type="text/javascript" language="javascript">
548
+ function init_frame_select() {
549
+ var opts = document.getElementById('frame_select').options;
550
+ for (i = 0; i < opts.length; i++) {
551
+ opts[i].selected = (location.href.indexOf(opts[i].value) != -1);
552
+ }
553
+ }
554
+ function do_link_search() {
555
+ var search_box = document.getElementById('link_search');
556
+ if (search_box.value == search_box.defaultValue) return;
557
+ var links = document.getElementById('entries').getElementsByTagName('a');
558
+ search = new RegExp(search_box.value, 'i');
559
+ for (i = 0; i < links.length; i++) {
560
+ links[i].style.display = search.exec(links[i].innerHTML) ? 'block' : 'none';
561
+ }
562
+ }
563
+ function clear_link_search() {
564
+ var search_box = document.getElementById('link_search');
565
+ if (search_box.value == search_box.defaultValue) search_box.value = '';
566
+ search_box.className = '';
567
+ }
568
+ function reset_link_search() {
569
+ var search_box = document.getElementById('link_search');
570
+ if (search_box.value == '') search_box.value = search_box.defaultValue;
571
+ search_box.className = 'default';
572
+ }
573
+ </script>
574
+ <base target="docwin">
575
+ </head>
576
+ <body onload="init_frame_select(); reset_link_search();">
577
+ <select id="frame_select" onchange="location.href=this.value" style="width: 100%;">
578
+ <option value="fr_class_index.html">Classes</option>
579
+ <option value="fr_file_index.html">Files</option>
580
+ <option value="fr_method_index.html">Methods</option>
581
+ </select>
582
+ <input id="link_search" class="default" type="text" onkeyup="do_link_search()" onfocus="clear_link_search()" onblur="reset_link_search()" style="width: 100%;" value="type search here..." />
583
+ <div class="banner">%list_title%</div>
584
+ <div class="entries" id="entries">
585
+ START:entries
586
+ <a href="%href%">%name%</a>
587
+ END:entries
588
+ </div>
589
+ </body></html>
590
+ HTML
591
+
592
+ CLASS_INDEX = FILE_INDEX
593
+ METHOD_INDEX = FILE_INDEX
594
+
595
+ INDEX = XHTML_PREAMBLE + <<HTML
596
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
597
+ <head>
598
+ <title>%title%</title>
599
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
600
+ </head>
601
+
602
+ <frameset cols="200, *">
603
+ <frame src="fr_class_index.html" name="framewin" />
604
+ <frame src="%initial_page%" name="docwin" />
605
+ </frameset>
606
+
607
+ <frameset cols="200,*">
608
+ <frame src="fr_class_index.html" name="framewin" />
609
+ IF:inline_source
610
+ <frame src="%initial_page%" name="docwin">
611
+ ENDIF:inline_source
612
+ IFNOT:inline_source
613
+ <frameset rows="80%,20%">
614
+ <frame src="%initial_page%" name="docwin">
615
+ <frame src="blank.html" name="source">
616
+ </frameset>
617
+ ENDIF:inline_source
618
+ <noframes>
619
+ <body bgcolor="white">
620
+ Click <a href="html/index.html">here</a> for a non-frames
621
+ version of this page.
622
+ </body>
623
+ </noframes>
624
+ </frameset>
625
+
626
+ </html>
627
+ HTML
628
+
629
+ end
630
+ end
631
+