spicycode-rcov 0.8.1.5.7 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rcov/binding_of_caller.rb +83 -0
- data/lib/rcov/report.rb +24 -19
- data/lib/rcov/rexml_extensions.rb +44 -0
- data/lib/rcov/version.rb +2 -2
- data/lib/rcov/xx.rb +299 -104
- metadata +3 -1
@@ -0,0 +1,83 @@
|
|
1
|
+
unless(defined?(Continuation) and Continuation.respond_to?('create'))
|
2
|
+
# to satisfy rdoc
|
3
|
+
class Continuation #:nodoc:
|
4
|
+
end
|
5
|
+
def Continuation.create(*args, &block) # :nodoc:
|
6
|
+
cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
|
7
|
+
result ||= args
|
8
|
+
return *[cc, *result]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Binding; end # for RDoc
|
13
|
+
# This method returns the binding of the method that called your
|
14
|
+
# method. It will raise an Exception when you're not inside a method.
|
15
|
+
#
|
16
|
+
# It's used like this:
|
17
|
+
# def inc_counter(amount = 1)
|
18
|
+
# Binding.of_caller do |binding|
|
19
|
+
# # Create a lambda that will increase the variable 'counter'
|
20
|
+
# # in the caller of this method when called.
|
21
|
+
# inc = eval("lambda { |arg| counter += arg }", binding)
|
22
|
+
# # We can refer to amount from inside this block safely.
|
23
|
+
# inc.call(amount)
|
24
|
+
# end
|
25
|
+
# # No other statements can go here. Put them inside the block.
|
26
|
+
# end
|
27
|
+
# counter = 0
|
28
|
+
# 2.times { inc_counter }
|
29
|
+
# counter # => 2
|
30
|
+
#
|
31
|
+
# Binding.of_caller must be the last statement in the method.
|
32
|
+
# This means that you will have to put everything you want to
|
33
|
+
# do after the call to Binding.of_caller into the block of it.
|
34
|
+
# This should be no problem however, because Ruby has closures.
|
35
|
+
# If you don't do this an Exception will be raised. Because of
|
36
|
+
# the way that Binding.of_caller is implemented it has to be
|
37
|
+
# done this way.
|
38
|
+
def Binding.of_caller(&block)
|
39
|
+
old_critical = Thread.critical
|
40
|
+
Thread.critical = true
|
41
|
+
count = 0
|
42
|
+
cc, result, error, extra_data = Continuation.create(nil, nil)
|
43
|
+
error.call if error
|
44
|
+
|
45
|
+
tracer = lambda do |*args|
|
46
|
+
type, context, extra_data = args[0], args[4], args
|
47
|
+
if type == "return"
|
48
|
+
count += 1
|
49
|
+
# First this method and then calling one will return --
|
50
|
+
# the trace event of the second event gets the context
|
51
|
+
# of the method which called the method that called this
|
52
|
+
# method.
|
53
|
+
if count == 2
|
54
|
+
# It would be nice if we could restore the trace_func
|
55
|
+
# that was set before we swapped in our own one, but
|
56
|
+
# this is impossible without overloading set_trace_func
|
57
|
+
# in current Ruby.
|
58
|
+
set_trace_func(nil)
|
59
|
+
cc.call(eval("binding", context), nil, extra_data)
|
60
|
+
end
|
61
|
+
elsif type == "line" then
|
62
|
+
nil
|
63
|
+
elsif type == "c-return" and extra_data[3] == :set_trace_func then
|
64
|
+
nil
|
65
|
+
else
|
66
|
+
set_trace_func(nil)
|
67
|
+
error_msg = "Binding.of_caller used in non-method context or " +
|
68
|
+
"trailing statements of method using it aren't in the block."
|
69
|
+
cc.call(nil, lambda { raise(ArgumentError, error_msg) }, nil)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
unless result
|
74
|
+
set_trace_func(tracer)
|
75
|
+
return nil
|
76
|
+
else
|
77
|
+
Thread.critical = old_critical
|
78
|
+
case block.arity
|
79
|
+
when 1 then yield(result)
|
80
|
+
else yield(result, extra_data)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/rcov/report.rb
CHANGED
@@ -25,8 +25,6 @@ begin
|
|
25
25
|
rescue LoadError
|
26
26
|
end
|
27
27
|
|
28
|
-
require 'rcov/rexml_extensions' # TODO it would be nice to move the below hacks into this rexml_extensions module
|
29
|
-
|
30
28
|
if (RUBY_VERSION == "1.8.6" || RUBY_VERSION == "1.8.7") && defined? REXML::Formatters::Transitive
|
31
29
|
class REXML::Document
|
32
30
|
remove_method :write rescue nil
|
@@ -76,7 +74,6 @@ if (RUBY_VERSION == "1.8.6" || RUBY_VERSION == "1.8.7") && defined? REXML::Forma
|
|
76
74
|
output << ' '*@level
|
77
75
|
end
|
78
76
|
end
|
79
|
-
|
80
77
|
end
|
81
78
|
|
82
79
|
class Formatter # :nodoc:
|
@@ -88,11 +85,11 @@ class Formatter # :nodoc:
|
|
88
85
|
/\btest\//,
|
89
86
|
/\bvendor\//,
|
90
87
|
/\A#{Regexp.escape(__FILE__)}\z/]
|
91
|
-
|
88
|
+
|
92
89
|
DEFAULT_OPTS = {:ignore => ignore_files, :sort => :name, :sort_reverse => false,
|
93
90
|
:output_threshold => 101, :dont_ignore => [],
|
94
91
|
:callsite_analyzer => nil, :comments_run_by_default => false}
|
95
|
-
|
92
|
+
|
96
93
|
def initialize(opts = {})
|
97
94
|
options = DEFAULT_OPTS.clone.update(opts)
|
98
95
|
@files = {}
|
@@ -538,7 +535,7 @@ class HTMLCoverage < Formatter # :nodoc:
|
|
538
535
|
require 'fileutils'
|
539
536
|
JAVASCRIPT_PROLOG = <<-EOS
|
540
537
|
|
541
|
-
//
|
538
|
+
// \<![CDATA[
|
542
539
|
function toggleCode( id ) {
|
543
540
|
if ( document.getElementById )
|
544
541
|
elem = document.getElementById( id );
|
@@ -559,7 +556,7 @@ class HTMLCoverage < Formatter # :nodoc:
|
|
559
556
|
}
|
560
557
|
|
561
558
|
// Make cross-references hidden by default
|
562
|
-
document.writeln( "
|
559
|
+
document.writeln( "\<style type=\\"text/css\\">span.cross-ref { display: none }</style>" )
|
563
560
|
// ]]>
|
564
561
|
EOS
|
565
562
|
|
@@ -721,7 +718,7 @@ EOS
|
|
721
718
|
return if @files.empty?
|
722
719
|
FileUtils.mkdir_p @dest
|
723
720
|
create_index(File.join(@dest, "index.html"))
|
724
|
-
|
721
|
+
|
725
722
|
each_file_pair_sorted do |filename, fileinfo|
|
726
723
|
create_file(File.join(@dest, mangle_filename(filename)), fileinfo)
|
727
724
|
end
|
@@ -816,29 +813,29 @@ EOS
|
|
816
813
|
end
|
817
814
|
|
818
815
|
class SummaryFileInfo # :nodoc:
|
819
|
-
|
816
|
+
|
820
817
|
def initialize(obj)
|
821
|
-
@o = obj
|
818
|
+
@o = obj
|
822
819
|
end
|
823
|
-
|
820
|
+
|
824
821
|
def num_lines
|
825
822
|
@o.num_lines
|
826
823
|
end
|
827
|
-
|
824
|
+
|
828
825
|
def num_code_lines
|
829
826
|
@o.num_code_lines
|
830
827
|
end
|
831
|
-
|
828
|
+
|
832
829
|
def code_coverage
|
833
830
|
@o.code_coverage
|
834
831
|
end
|
835
|
-
|
832
|
+
|
836
833
|
def total_coverage
|
837
834
|
@o.total_coverage
|
838
835
|
end
|
839
|
-
|
836
|
+
|
840
837
|
def name
|
841
|
-
"TOTAL"
|
838
|
+
"TOTAL"
|
842
839
|
end
|
843
840
|
|
844
841
|
end
|
@@ -886,7 +883,11 @@ EOS
|
|
886
883
|
end
|
887
884
|
}
|
888
885
|
} }
|
889
|
-
|
886
|
+
if String.new.respond_to?(:lines) then
|
887
|
+
lines = output.pretty.lines.to_a
|
888
|
+
else
|
889
|
+
lines = output.pretty.to_a
|
890
|
+
end
|
890
891
|
lines.unshift lines.pop if /DOCTYPE/ =~ lines[-1]
|
891
892
|
File.open(destname, "w") do |f|
|
892
893
|
f.puts lines
|
@@ -1038,7 +1039,11 @@ EOS
|
|
1038
1039
|
}
|
1039
1040
|
} }
|
1040
1041
|
# .pretty needed to make sure DOCTYPE is in a separate line
|
1041
|
-
|
1042
|
+
if String.new.respond_to?(:lines)
|
1043
|
+
lines = output.pretty.lines.to_a
|
1044
|
+
else
|
1045
|
+
lines = output.pretty.to_a
|
1046
|
+
end
|
1042
1047
|
lines.unshift lines.pop if /DOCTYPE/ =~ lines[-1]
|
1043
1048
|
File.open(destfile, "w") do |f|
|
1044
1049
|
f.puts lines
|
@@ -1153,7 +1158,7 @@ class HTMLProfiling < HTMLCoverage # :nodoc:
|
|
1153
1158
|
nil
|
1154
1159
|
end
|
1155
1160
|
end
|
1156
|
-
|
1161
|
+
|
1157
1162
|
end
|
1158
1163
|
|
1159
1164
|
class RubyAnnotation < Formatter # :nodoc:
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'rexml/formatters/pretty'
|
3
|
+
|
4
|
+
module Rcov
|
5
|
+
module REXMLExtensions
|
6
|
+
|
7
|
+
def self.fix_pretty_formatter_wrap
|
8
|
+
REXML::Formatters::Pretty.class_eval do
|
9
|
+
include PrettyFormatterWrapFix
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Fix for this bug: http://clint-hill.com/2008/10/02/a-bug-in-ruby-did-i-just-find-that/
|
14
|
+
# Also known from this fun exception:
|
15
|
+
#
|
16
|
+
# /usr/local/ruby/lib/ruby/1.8/rexml/formatters/pretty.rb:131:in
|
17
|
+
# `[]': no implicit conversion from nil to integer (TypeError)
|
18
|
+
#
|
19
|
+
# This bug was fixed in Ruby with this changeset http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19487
|
20
|
+
# ...which should mean that this bug only affects Ruby 1.8.6. The latest stable version of 1.8.7 (and up) should be fine.
|
21
|
+
module PrettyFormatterWrapFix
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
base.class_eval do
|
25
|
+
def wrap(string, width)
|
26
|
+
# Recursively wrap string at width.
|
27
|
+
return string if string.length <= width
|
28
|
+
place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
|
29
|
+
return string if place.nil?
|
30
|
+
return string[0,place] + "\n" + wrap(string[place+1..-1], width)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.init!
|
38
|
+
if RUBY_VERSION == "1.8.6"
|
39
|
+
fix_pretty_formatter_wrap
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/rcov/version.rb
CHANGED
data/lib/rcov/xx.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# xx can be redistributed and used under the following conditions
|
2
2
|
# (just keep the following copyright notice, list of conditions and disclaimer
|
3
3
|
# in order to satisfy rcov's "Ruby license" and xx's license simultaneously).
|
4
|
-
#
|
4
|
+
#
|
5
5
|
#ePark Labs Public License version 1
|
6
6
|
#Copyright (c) 2005, ePark Labs, Inc. and contributors
|
7
7
|
#All rights reserved.
|
@@ -29,14 +29,19 @@
|
|
29
29
|
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
30
30
|
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
31
|
|
32
|
-
unless
|
32
|
+
unless(defined?($__xx_rb__) or defined?(XX))
|
33
33
|
|
34
34
|
require "rexml/document"
|
35
35
|
|
36
|
-
|
37
36
|
module XX
|
38
37
|
#--{{{
|
39
|
-
VERSION = "
|
38
|
+
VERSION = "2.1.0"
|
39
|
+
def self.version() VERSION end
|
40
|
+
|
41
|
+
LIBDIR = File.dirname(File.expand_path(__FILE__)) << File::SEPARATOR
|
42
|
+
def self.libdir() LIBDIR end
|
43
|
+
|
44
|
+
require libdir + "binding_of_caller"
|
40
45
|
|
41
46
|
%w(
|
42
47
|
CRAZY_LIKE_A_HELL
|
@@ -50,11 +55,13 @@ module XX
|
|
50
55
|
attr "doc"
|
51
56
|
attr "stack"
|
52
57
|
attr "size"
|
58
|
+
attr_accessor "xmldecl"
|
53
59
|
|
54
60
|
def initialize *a, &b
|
55
61
|
#--{{{
|
56
|
-
@doc = ::REXML::Document::new
|
62
|
+
@doc = ::REXML::Document::new *a, &b
|
57
63
|
@stack = [@doc]
|
64
|
+
@xmldecl = nil
|
58
65
|
@size = 0
|
59
66
|
#--}}}
|
60
67
|
end
|
@@ -82,17 +89,23 @@ module XX
|
|
82
89
|
end
|
83
90
|
def to_str port = ""
|
84
91
|
#--{{{
|
85
|
-
|
86
|
-
port
|
92
|
+
xmldecl ? ugly(port) : pretty(port)
|
87
93
|
#--}}}
|
88
94
|
end
|
89
95
|
alias_method "to_s", "to_str"
|
90
|
-
def pretty port =
|
96
|
+
def pretty port = ""
|
91
97
|
#--{{{
|
92
|
-
@doc.write port, indent=
|
98
|
+
@doc.write port, indent=0, transitive=false, ie_hack=true
|
93
99
|
port
|
94
100
|
#--}}}
|
95
101
|
end
|
102
|
+
def ugly port = ''
|
103
|
+
#--{{{
|
104
|
+
@doc.write port, indent=-1, transitive=false, ie_hack=true
|
105
|
+
port
|
106
|
+
#--}}}
|
107
|
+
end
|
108
|
+
alias_method "compact", "ugly"
|
96
109
|
def create element
|
97
110
|
#--{{{
|
98
111
|
push element
|
@@ -174,7 +187,7 @@ module XX
|
|
174
187
|
x.to_s
|
175
188
|
end
|
176
189
|
|
177
|
-
else # other - try anyhow
|
190
|
+
else # other - try anyhow
|
178
191
|
t <<
|
179
192
|
case x
|
180
193
|
when ::REXML::Document
|
@@ -204,67 +217,34 @@ module XX
|
|
204
217
|
|
205
218
|
module InstanceMethods
|
206
219
|
#--{{{
|
207
|
-
def
|
220
|
+
def _ tag_name, *a, &b
|
208
221
|
#--{{{
|
209
|
-
|
222
|
+
hashes, nothashes = a.partition{|x| Hash === x}
|
210
223
|
|
211
|
-
|
212
|
-
|
213
|
-
c_method_missing = xx_class::xx_config_for "method_missing", xx_which
|
214
|
-
c_tags = xx_class::xx_config_for "tags", xx_which
|
215
|
-
|
216
|
-
pat =
|
217
|
-
case c_method_missing
|
218
|
-
when ::XX::CRAZY_LIKE_A_HELL
|
219
|
-
%r/.*/
|
220
|
-
when ::XX::PERMISSIVE
|
221
|
-
%r/_$/o
|
222
|
-
when ::XX::STRICT
|
223
|
-
%r/_$/o
|
224
|
-
else
|
225
|
-
super(m.to_sym, *a, &b)
|
226
|
-
end
|
227
|
-
|
228
|
-
super(m.to_sym, *a, &b) unless m =~ pat
|
229
|
-
|
230
|
-
if c_method_missing == ::XX::STRICT
|
231
|
-
super(m.to_sym, *a, &b) unless c_tags.include? tag_name
|
232
|
-
end
|
233
|
-
|
234
|
-
ret, defined = nil
|
224
|
+
doc = xx_doc
|
225
|
+
element = ::REXML::Element::new "#{ tag_name }"
|
235
226
|
|
236
|
-
|
237
|
-
|
238
|
-
xx_class::xx_define_tag_method tag_method, tag_name
|
239
|
-
ret = send tag_method, *a, &b
|
240
|
-
defined = true
|
241
|
-
ensure
|
242
|
-
xx_class::xx_remove_tag_method tag_method unless defined
|
243
|
-
end
|
227
|
+
hashes.each{|h| h.each{|k,v| element.add_attribute k.to_s, v}}
|
228
|
+
nothashes.each{|nh| element << ::REXML::Text::new(nh.to_s)}
|
244
229
|
|
245
|
-
|
230
|
+
doc.create element, &b
|
246
231
|
#--}}}
|
247
232
|
end
|
248
|
-
|
233
|
+
alias_method "xx_tag" , "_"
|
234
|
+
alias_method "__" , "_"
|
235
|
+
alias_method "g__" , "_"
|
236
|
+
def method_missing m, *a, &b
|
249
237
|
#--{{{
|
250
|
-
|
238
|
+
m = m.to_s
|
251
239
|
|
252
|
-
|
240
|
+
tag_name = m.sub! %r/_+$/, ''
|
253
241
|
|
254
|
-
|
255
|
-
xx_class::xx_define_tmp_method tag_method
|
256
|
-
xx_class::xx_define_tag_method tag_method, tag_name
|
257
|
-
ret = send tag_method, *a, &b
|
258
|
-
defined = true
|
259
|
-
ensure
|
260
|
-
xx_class::xx_remove_tag_method tag_method unless defined
|
261
|
-
end
|
242
|
+
super unless tag_name
|
262
243
|
|
263
|
-
|
244
|
+
__ tag_name, *a, &b
|
264
245
|
#--}}}
|
265
246
|
end
|
266
|
-
|
267
|
-
def xx_which *argv
|
247
|
+
def xx_which *argv
|
268
248
|
#--{{{
|
269
249
|
@xx_which = nil unless defined? @xx_which
|
270
250
|
if argv.empty?
|
@@ -272,7 +252,7 @@ module XX
|
|
272
252
|
else
|
273
253
|
xx_which = @xx_which
|
274
254
|
begin
|
275
|
-
@xx_which = argv.shift
|
255
|
+
@xx_which = argv.shift
|
276
256
|
return yield
|
277
257
|
ensure
|
278
258
|
@xx_which = xx_which
|
@@ -283,16 +263,15 @@ module XX
|
|
283
263
|
def xx_with_doc_in_effect *a, &b
|
284
264
|
#--{{{
|
285
265
|
@xx_docs ||= []
|
286
|
-
doc = ::XX::Document::new
|
266
|
+
doc = ::XX::Document::new *a
|
287
267
|
ddoc = doc.doc
|
288
268
|
begin
|
289
269
|
@xx_docs.push doc
|
290
|
-
b.call doc if b
|
291
270
|
|
292
271
|
doctype = xx_config_for "doctype", xx_which
|
293
272
|
if doctype
|
294
273
|
unless ddoc.doctype
|
295
|
-
doctype = ::REXML::DocType::new doctype unless
|
274
|
+
doctype = ::REXML::DocType::new doctype unless
|
296
275
|
::REXML::DocType === doctype
|
297
276
|
ddoc << doctype
|
298
277
|
end
|
@@ -304,9 +283,12 @@ module XX
|
|
304
283
|
xmldecl = ::REXML::XMLDecl::new xmldecl unless
|
305
284
|
::REXML::XMLDecl === xmldecl
|
306
285
|
ddoc << xmldecl
|
286
|
+
doc.xmldecl = ::REXML::XMLDecl
|
307
287
|
end
|
308
288
|
end
|
309
289
|
|
290
|
+
b.call doc if b
|
291
|
+
|
310
292
|
return doc
|
311
293
|
ensure
|
312
294
|
@xx_docs.pop
|
@@ -323,26 +305,26 @@ module XX
|
|
323
305
|
doc = xx_doc
|
324
306
|
|
325
307
|
text =
|
326
|
-
::REXML::Text::new("",
|
308
|
+
::REXML::Text::new("",
|
327
309
|
respect_whitespace=true, parent=nil
|
328
310
|
)
|
329
311
|
|
330
|
-
objects.each do |object|
|
312
|
+
objects.each do |object|
|
331
313
|
text << object.to_s if object
|
332
314
|
end
|
333
315
|
|
334
316
|
doc.create text, &b
|
335
317
|
#--}}}
|
336
318
|
end
|
337
|
-
alias_method "
|
338
|
-
alias_method "
|
319
|
+
alias_method "t__", "xx_text_"
|
320
|
+
alias_method "text__", "xx_text_"
|
339
321
|
def xx_markup_ *objects, &b
|
340
322
|
#--{{{
|
341
323
|
doc = xx_doc
|
342
324
|
|
343
325
|
doc2 = ::REXML::Document::new ""
|
344
326
|
|
345
|
-
objects.each do |object|
|
327
|
+
objects.each do |object|
|
346
328
|
(doc2.root ? doc2.root : doc2) << ::REXML::Document::new(object.to_s)
|
347
329
|
end
|
348
330
|
|
@@ -353,41 +335,43 @@ module XX
|
|
353
335
|
ret
|
354
336
|
#--}}}
|
355
337
|
end
|
356
|
-
alias_method "
|
338
|
+
alias_method "x__", "xx_markup_"
|
339
|
+
alias_method "markup__", "xx_markup_"
|
357
340
|
def xx_any_ *objects, &b
|
358
341
|
#--{{{
|
359
342
|
doc = xx_doc
|
360
343
|
nothing = %r/.^/m
|
361
344
|
|
362
345
|
text =
|
363
|
-
::REXML::Text::new("",
|
346
|
+
::REXML::Text::new("",
|
364
347
|
respect_whitespace=true, parent=nil, raw=true, entity_filter=nil, illegal=nothing
|
365
348
|
)
|
366
349
|
|
367
|
-
objects.each do |object|
|
350
|
+
objects.each do |object|
|
368
351
|
text << object.to_s if object
|
369
352
|
end
|
370
353
|
|
371
354
|
doc.create text, &b
|
372
355
|
#--}}}
|
373
356
|
end
|
374
|
-
alias_method "
|
375
|
-
|
376
|
-
alias_method "
|
357
|
+
alias_method "any__", "xx_any_"
|
358
|
+
alias_method "h__", "xx_any_"
|
359
|
+
alias_method "x__", "xx_any_" # supplant for now
|
377
360
|
def xx_cdata_ *objects, &b
|
378
361
|
#--{{{
|
379
362
|
doc = xx_doc
|
380
363
|
|
381
364
|
cdata = ::REXML::CData::new ""
|
382
365
|
|
383
|
-
objects.each do |object|
|
366
|
+
objects.each do |object|
|
384
367
|
cdata << object.to_s if object
|
385
368
|
end
|
386
369
|
|
387
370
|
doc.create cdata, &b
|
388
371
|
#--}}}
|
389
372
|
end
|
390
|
-
alias_method "
|
373
|
+
alias_method "cdata__", "xx_cdata_"
|
374
|
+
alias_method "c__", "xx_cdata_"
|
391
375
|
def xx_parse_attributes string
|
392
376
|
#--{{{
|
393
377
|
string = string.to_s
|
@@ -396,7 +380,7 @@ module XX
|
|
396
380
|
xx_parse_yaml_attributes(tokens.join(','))
|
397
381
|
#--}}}
|
398
382
|
end
|
399
|
-
alias_method "
|
383
|
+
alias_method "a__", "xx_parse_attributes"
|
400
384
|
def xx_parse_yaml_attributes string
|
401
385
|
#--{{{
|
402
386
|
require "yaml"
|
@@ -408,31 +392,30 @@ module XX
|
|
408
392
|
obj
|
409
393
|
#--}}}
|
410
394
|
end
|
411
|
-
alias_method "
|
412
|
-
alias_method "yat_", "xx_parse_yaml_attributes"
|
395
|
+
alias_method "y__", "xx_parse_yaml_attributes"
|
413
396
|
def xx_class
|
414
397
|
#--{{{
|
415
398
|
@xx_class ||= self.class
|
416
399
|
#--}}}
|
417
400
|
end
|
418
|
-
def xx_tag_method_name *a, &b
|
401
|
+
def xx_tag_method_name *a, &b
|
419
402
|
#--{{{
|
420
|
-
xx_class.xx_tag_method_name
|
403
|
+
xx_class.xx_tag_method_name *a, &b
|
421
404
|
#--}}}
|
422
405
|
end
|
423
|
-
def xx_define_tmp_method *a, &b
|
406
|
+
def xx_define_tmp_method *a, &b
|
424
407
|
#--{{{
|
425
|
-
xx_class.
|
408
|
+
xx_class.xx_define_tmp_method *a, &b
|
426
409
|
#--}}}
|
427
410
|
end
|
428
|
-
def xx_define_tag_method *a, &b
|
411
|
+
def xx_define_tag_method *a, &b
|
429
412
|
#--{{{
|
430
|
-
xx_class.xx_define_tag_method
|
413
|
+
xx_class.xx_define_tag_method *a, &b
|
431
414
|
#--}}}
|
432
415
|
end
|
433
|
-
def xx_remove_tag_method *a, &b
|
416
|
+
def xx_remove_tag_method *a, &b
|
434
417
|
#--{{{
|
435
|
-
xx_class.xx_tag_remove_method
|
418
|
+
xx_class.xx_tag_remove_method *a, &b
|
436
419
|
#--}}}
|
437
420
|
end
|
438
421
|
def xx_ancestors
|
@@ -448,12 +431,12 @@ module XX
|
|
448
431
|
end
|
449
432
|
def xx_config_for *a, &b
|
450
433
|
#--{{{
|
451
|
-
xx_class.xx_config_for
|
434
|
+
xx_class.xx_config_for *a, &b
|
452
435
|
#--}}}
|
453
436
|
end
|
454
437
|
def xx_configure *a, &b
|
455
438
|
#--{{{
|
456
|
-
xx_class.xx_configure
|
439
|
+
xx_class.xx_configure *a, &b
|
457
440
|
#--}}}
|
458
441
|
end
|
459
442
|
#--}}}
|
@@ -468,7 +451,7 @@ module XX
|
|
468
451
|
[ tag_method, tag_name ]
|
469
452
|
#--}}}
|
470
453
|
end
|
471
|
-
def xx_define_tmp_method m
|
454
|
+
def xx_define_tmp_method m
|
472
455
|
#--{{{
|
473
456
|
define_method(m){ raise NotImplementedError, m.to_s }
|
474
457
|
#--}}}
|
@@ -476,10 +459,9 @@ module XX
|
|
476
459
|
def xx_define_tag_method tag_method, tag_name = nil
|
477
460
|
#--{{{
|
478
461
|
tag_method = tag_method.to_s
|
479
|
-
tag_name ||= tag_method.
|
462
|
+
tag_name ||= tag_method.sub(%r/_$/, '')
|
480
463
|
|
481
|
-
|
482
|
-
module_eval <<-code, __FILE__, __LINE__+1
|
464
|
+
module_eval <<-code
|
483
465
|
def #{ tag_method } *a, &b
|
484
466
|
hashes, nothashes = a.partition{|x| Hash === x}
|
485
467
|
|
@@ -517,9 +499,9 @@ module XX
|
|
517
499
|
@@xx_config ||= Hash::new{|h,k| h[k] = {}}
|
518
500
|
#--}}}
|
519
501
|
end
|
520
|
-
def xx_config_for key, xx_which = nil
|
502
|
+
def xx_config_for key, xx_which = nil
|
521
503
|
#--{{{
|
522
|
-
key = key.to_s
|
504
|
+
key = key.to_s
|
523
505
|
xx_which ||= self
|
524
506
|
xx_ancestors(xx_which).each do |a|
|
525
507
|
if xx_config[a].has_key? key
|
@@ -529,7 +511,7 @@ module XX
|
|
529
511
|
nil
|
530
512
|
#--}}}
|
531
513
|
end
|
532
|
-
def xx_configure key, value, xx_which = nil
|
514
|
+
def xx_configure key, value, xx_which = nil
|
533
515
|
#--{{{
|
534
516
|
key = key.to_s
|
535
517
|
xx_which ||= self
|
@@ -572,10 +554,10 @@ module XX
|
|
572
554
|
def xhtml_ which = XHTML, *a, &b
|
573
555
|
#--{{{
|
574
556
|
xx_which(which) do
|
575
|
-
doc = xx_with_doc_in_effect
|
557
|
+
doc = xx_with_doc_in_effect *a, &b
|
576
558
|
ddoc = doc.doc
|
577
559
|
root = ddoc.root
|
578
|
-
if root and root.name and root.name =~ %r/^html$/i
|
560
|
+
if root and root.name and root.name =~ %r/^html$/i
|
579
561
|
if root.attribute("lang",nil).nil? or root.attribute("lang",nil).to_s.empty?
|
580
562
|
root.add_attribute "lang", "en"
|
581
563
|
end
|
@@ -590,6 +572,7 @@ module XX
|
|
590
572
|
end
|
591
573
|
#--}}}
|
592
574
|
end
|
575
|
+
alias_method "xhtml__", "xhtml_"
|
593
576
|
|
594
577
|
module Strict
|
595
578
|
#--{{{
|
@@ -611,6 +594,7 @@ module XX
|
|
611
594
|
super(which, *a, &b)
|
612
595
|
#--}}}
|
613
596
|
end
|
597
|
+
alias_method "xhtml__", "xhtml_"
|
614
598
|
#--}}}
|
615
599
|
end
|
616
600
|
|
@@ -623,6 +607,7 @@ module XX
|
|
623
607
|
super(which, *a, &b)
|
624
608
|
#--}}}
|
625
609
|
end
|
610
|
+
alias_method "xhtml__", "xhtml_"
|
626
611
|
#--}}}
|
627
612
|
end
|
628
613
|
#--}}}
|
@@ -632,12 +617,13 @@ module XX
|
|
632
617
|
#--{{{
|
633
618
|
include Markup
|
634
619
|
xx_configure "doctype", %(html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN")
|
635
|
-
|
620
|
+
|
636
621
|
def html4_ which = HTML4, *a, &b
|
637
622
|
#--{{{
|
638
|
-
xx_which(which){ xx_with_doc_in_effect
|
623
|
+
xx_which(which){ xx_with_doc_in_effect *a, &b }
|
639
624
|
#--}}}
|
640
625
|
end
|
626
|
+
alias_method "html4__", "html4_"
|
641
627
|
|
642
628
|
module Strict
|
643
629
|
#--{{{
|
@@ -658,6 +644,7 @@ module XX
|
|
658
644
|
super(which, *a, &b)
|
659
645
|
#--}}}
|
660
646
|
end
|
647
|
+
alias_method "html4__", "html4_"
|
661
648
|
#--}}}
|
662
649
|
end
|
663
650
|
|
@@ -670,6 +657,7 @@ module XX
|
|
670
657
|
super(which, *a, &b)
|
671
658
|
#--}}}
|
672
659
|
end
|
660
|
+
alias_method "html4__", "html4_"
|
673
661
|
#--}}}
|
674
662
|
end
|
675
663
|
#--}}}
|
@@ -683,11 +671,218 @@ module XX
|
|
683
671
|
|
684
672
|
def xml_ *a, &b
|
685
673
|
#--{{{
|
686
|
-
xx_which(XML){ xx_with_doc_in_effect
|
674
|
+
xx_which(XML){ xx_with_doc_in_effect *a, &b }
|
687
675
|
#--}}}
|
688
676
|
end
|
677
|
+
alias_method "xml__", "xml_"
|
689
678
|
#--}}}
|
690
679
|
end
|
680
|
+
|
681
|
+
module Template
|
682
|
+
#--{{{
|
683
|
+
class Basic
|
684
|
+
#--{{{
|
685
|
+
%w( path inline type object template port pretty ).each{|a| attr_accessor a}
|
686
|
+
def initialize opts = {}, &b
|
687
|
+
#--{{{
|
688
|
+
@path = opts['path'] || opts[:path]
|
689
|
+
@inline = opts['inline'] || opts[:inline]
|
690
|
+
@type = opts['type'] || opts[:type]
|
691
|
+
@object = opts['object'] || opts[:object]
|
692
|
+
@pretty = opts['pretty'] || opts[:pretty]
|
693
|
+
@port = opts['port'] || opts[:port] || STDOUT
|
694
|
+
|
695
|
+
bool = lambda{|value| value ? true : false}
|
696
|
+
raise ArgumentError unless(bool[@path] ^ bool[@inline])
|
697
|
+
|
698
|
+
path_init(&b) if @path
|
699
|
+
inline_init(&b) if @inline
|
700
|
+
|
701
|
+
@type =
|
702
|
+
case @type.to_s.downcase.strip
|
703
|
+
when /^xhtml$/
|
704
|
+
XHTML
|
705
|
+
when /^xml$/
|
706
|
+
XML
|
707
|
+
when /^html4$/
|
708
|
+
HTML4
|
709
|
+
else
|
710
|
+
XHTML
|
711
|
+
end
|
712
|
+
#--}}}
|
713
|
+
end
|
714
|
+
def path_init &b
|
715
|
+
#--{{{
|
716
|
+
@template = IO.read @path
|
717
|
+
@type = @path[%r/\.[^\.]+$/o] || XHTML unless @type
|
718
|
+
#--}}}
|
719
|
+
end
|
720
|
+
def inline_init &b
|
721
|
+
#--{{{
|
722
|
+
@template = (@inline || b.call).to_s
|
723
|
+
@type ||= XHTML
|
724
|
+
#--}}}
|
725
|
+
end
|
726
|
+
def expand binding, opts = {}
|
727
|
+
#--{{{
|
728
|
+
port = opts['port'] || opts[:port] || STDOUT
|
729
|
+
pretty = opts['pretty'] || opts[:pretty]
|
730
|
+
|
731
|
+
object = eval 'self', binding
|
732
|
+
|
733
|
+
unless type === object
|
734
|
+
__m = type
|
735
|
+
klass = object.class
|
736
|
+
klass.module_eval{ include __m }
|
737
|
+
end
|
738
|
+
|
739
|
+
doc = eval @template, binding
|
740
|
+
|
741
|
+
display = pretty ? 'pretty' : 'to_str'
|
742
|
+
|
743
|
+
doc.send display, port
|
744
|
+
#--}}}
|
745
|
+
end
|
746
|
+
alias_method "result", "expand"
|
747
|
+
#--}}}
|
748
|
+
end
|
749
|
+
|
750
|
+
class File < Basic
|
751
|
+
#--{{{
|
752
|
+
def initialize *argv, &b
|
753
|
+
#--{{{
|
754
|
+
opts, argv = argv.partition{|arg| Hash === arg}
|
755
|
+
opts = opts.inject{|a,b| a.update b}
|
756
|
+
path = argv.shift
|
757
|
+
raise ArgumentError, "no path" unless path
|
758
|
+
raise ArgumentError, "bad opts" unless Hash === opts or opts.nil?
|
759
|
+
opts ||= {}
|
760
|
+
opts['path'] = opts[:path] = path.to_s
|
761
|
+
super opts, &b
|
762
|
+
#--}}}
|
763
|
+
end
|
764
|
+
#--}}}
|
765
|
+
end
|
766
|
+
|
767
|
+
class Inline < Basic
|
768
|
+
#--{{{
|
769
|
+
def initialize *argv, &b
|
770
|
+
#--{{{
|
771
|
+
opts, argv = argv.partition{|arg| Hash === arg}
|
772
|
+
opts = opts.inject{|a,b| a.update b}
|
773
|
+
inline = argv.shift || b.call
|
774
|
+
raise ArgumentError, "no inline" unless inline
|
775
|
+
raise ArgumentError, "bad opts" unless Hash === opts or opts.nil?
|
776
|
+
opts ||= {}
|
777
|
+
opts['inline'] = opts[:inline] = inline.to_s
|
778
|
+
super opts, &b
|
779
|
+
#--}}}
|
780
|
+
end
|
781
|
+
#--}}}
|
782
|
+
end
|
783
|
+
#--}}}
|
784
|
+
end
|
785
|
+
|
786
|
+
module Expandable
|
787
|
+
#--{{{
|
788
|
+
module InstanceMethods
|
789
|
+
#--{{{
|
790
|
+
def xx_template_file *a, &b
|
791
|
+
#--{{{
|
792
|
+
template = XX::Template::File.new *a, &b
|
793
|
+
template.object ||= self
|
794
|
+
template
|
795
|
+
#--}}}
|
796
|
+
end
|
797
|
+
def xx_template_inline *a, &b
|
798
|
+
#--{{{
|
799
|
+
template = XX::Template::Inline.new *a, &b
|
800
|
+
template.object ||= self
|
801
|
+
template
|
802
|
+
#--}}}
|
803
|
+
end
|
804
|
+
def xx_expand template, opts = {}
|
805
|
+
#--{{{
|
806
|
+
port = opts['port'] || opts[:port] || STDOUT
|
807
|
+
pretty = opts['pretty'] || opts[:pretty]
|
808
|
+
binding = opts['binding'] || opts[:binding]
|
809
|
+
|
810
|
+
type = template.type
|
811
|
+
|
812
|
+
unless type === self
|
813
|
+
klass = self.class
|
814
|
+
klass.module_eval{ include type }
|
815
|
+
end
|
816
|
+
|
817
|
+
display = pretty ? 'pretty' : 'to_str'
|
818
|
+
|
819
|
+
Binding.of_caller do |scope|
|
820
|
+
binding ||= eval('binding', scope)
|
821
|
+
doc = eval template.template, binding
|
822
|
+
doc.send display, port
|
823
|
+
end
|
824
|
+
#--}}}
|
825
|
+
end
|
826
|
+
def xx_expand_file *a, &b
|
827
|
+
#--{{{
|
828
|
+
template = xx_template_file *a, &b
|
829
|
+
|
830
|
+
type = template.type
|
831
|
+
pretty = template.pretty
|
832
|
+
port = template.port
|
833
|
+
|
834
|
+
unless type === self
|
835
|
+
klass = self.class
|
836
|
+
klass.module_eval{ include type }
|
837
|
+
end
|
838
|
+
|
839
|
+
display = pretty ? 'pretty' : 'to_str'
|
840
|
+
|
841
|
+
Binding.of_caller do |scope|
|
842
|
+
binding ||= eval('binding', scope)
|
843
|
+
doc = eval template.template, binding
|
844
|
+
doc.send display, port
|
845
|
+
end
|
846
|
+
#--}}}
|
847
|
+
end
|
848
|
+
alias_method "xx_expand_path", "xx_expand_file"
|
849
|
+
alias_method "xx_expand_template", "xx_expand_file"
|
850
|
+
def xx_expand_inline *a, &b
|
851
|
+
#--{{{
|
852
|
+
template = xx_template_inline *a, &b
|
853
|
+
|
854
|
+
type = template.type
|
855
|
+
pretty = template.pretty
|
856
|
+
port = template.port
|
857
|
+
|
858
|
+
unless type === self
|
859
|
+
klass = self.class
|
860
|
+
klass.module_eval{ include type }
|
861
|
+
end
|
862
|
+
|
863
|
+
display = pretty ? 'pretty' : 'to_str'
|
864
|
+
|
865
|
+
Binding.of_caller do |scope|
|
866
|
+
binding ||= eval('binding', scope)
|
867
|
+
doc = eval template.template, binding
|
868
|
+
doc.send display, port
|
869
|
+
end
|
870
|
+
#--}}}
|
871
|
+
end
|
872
|
+
alias_method "xx_expand_string", "xx_expand_inline"
|
873
|
+
#--}}}
|
874
|
+
end
|
875
|
+
module ClassMethods
|
876
|
+
end
|
877
|
+
def self.included other
|
878
|
+
#--{{{
|
879
|
+
other.instance_eval{ include InstanceMethods }
|
880
|
+
other.extend ClassMethods
|
881
|
+
#--}}}
|
882
|
+
end
|
883
|
+
#--}}}
|
884
|
+
end
|
885
|
+
|
691
886
|
#--}}}
|
692
887
|
end
|
693
888
|
|
@@ -714,7 +909,7 @@ if __FILE__ == $0
|
|
714
909
|
include XX::HTML4::Strict
|
715
910
|
include XX::XML
|
716
911
|
|
717
|
-
def doc
|
912
|
+
def doc
|
718
913
|
html_{
|
719
914
|
head_{ title_{ "xhtml/html4/xml demo" } }
|
720
915
|
|
@@ -726,7 +921,7 @@ if __FILE__ == $0
|
|
726
921
|
|
727
922
|
x_{ "<any_valid> xml </any_valid>" }
|
728
923
|
|
729
|
-
div_(:style => :sweet){
|
924
|
+
div_(:style => :sweet){
|
730
925
|
em_ "this is a table"
|
731
926
|
|
732
927
|
table_(:width => 42, :height => 42){
|
@@ -749,7 +944,7 @@ if __FILE__ == $0
|
|
749
944
|
end
|
750
945
|
|
751
946
|
table = Table[ %w( 0 1 2 ), %w( a b c ) ]
|
752
|
-
|
947
|
+
|
753
948
|
methods = %w( to_xhtml to_html4 to_xml )
|
754
949
|
|
755
950
|
methods.each do |method|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spicycode-rcov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Fernandez
|
@@ -33,7 +33,9 @@ files:
|
|
33
33
|
- lib/rcov/version.rb
|
34
34
|
- lib/rcov/rant.rb
|
35
35
|
- lib/rcov/report.rb
|
36
|
+
- lib/rcov/binding_of_caller.rb
|
36
37
|
- lib/rcov/rcovtask.rb
|
38
|
+
- lib/rcov/rexml_extensions.rb
|
37
39
|
- ext/rcovrt/extconf.rb
|
38
40
|
- ext/rcovrt/1.8/rcovrt.c
|
39
41
|
- ext/rcovrt/1.9/rcovrt.c
|