mongrel2 0.21.0 → 0.22.1
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.
- data.tar.gz.sig +0 -0
- data/ChangeLog +55 -1
- data/History.rdoc +12 -0
- data/Manifest.txt +0 -4
- data/Rakefile +2 -1
- data/bin/m2sh.rb +22 -9
- data/examples/helloworld-handler.rb +3 -3
- data/examples/request-dumper.rb +3 -3
- data/examples/ws-echo.rb +3 -3
- data/lib/mongrel2.rb +9 -6
- data/lib/mongrel2/config.rb +14 -10
- data/lib/mongrel2/config/dsl.rb +7 -2
- data/lib/mongrel2/config/host.rb +3 -3
- data/lib/mongrel2/config/server.rb +6 -6
- data/lib/mongrel2/connection.rb +5 -2
- data/lib/mongrel2/control.rb +6 -2
- data/lib/mongrel2/handler.rb +11 -6
- data/lib/mongrel2/httprequest.rb +8 -3
- data/lib/mongrel2/httpresponse.rb +6 -3
- data/lib/mongrel2/jsonrequest.rb +6 -2
- data/lib/mongrel2/request.rb +10 -8
- data/lib/mongrel2/response.rb +6 -3
- data/lib/mongrel2/table.rb +8 -5
- data/lib/mongrel2/testing.rb +10 -1
- data/lib/mongrel2/websocket.rb +1 -2
- data/lib/mongrel2/xmlrequest.rb +6 -2
- data/spec/lib/helpers.rb +11 -43
- data/spec/mongrel2/handler_spec.rb +0 -5
- data/spec/mongrel2_spec.rb +1 -1
- metadata +23 -11
- metadata.gz.sig +0 -0
- data/lib/mongrel2/logging.rb +0 -241
- data/lib/mongrel2/mixins.rb +0 -143
- data/spec/mongrel2/logging_spec.rb +0 -76
- data/spec/mongrel2/mixins_spec.rb +0 -62
@@ -138,7 +138,6 @@ describe Mongrel2::Handler do
|
|
138
138
|
response.status.should == 204
|
139
139
|
end
|
140
140
|
|
141
|
-
|
142
141
|
it "ignores JSON messages by default" do
|
143
142
|
req = make_json_request()
|
144
143
|
@request_sock.should_receive( :recv ).and_return( req )
|
@@ -151,7 +150,6 @@ describe Mongrel2::Handler do
|
|
151
150
|
response.should be_nil()
|
152
151
|
end
|
153
152
|
|
154
|
-
|
155
153
|
it "dispatches JSON message to the #handle_json method" do
|
156
154
|
json_handler = Class.new( OneShotHandler ) do
|
157
155
|
def handle_json( request )
|
@@ -170,7 +168,6 @@ describe Mongrel2::Handler do
|
|
170
168
|
response.should be_a( Mongrel2::Response )
|
171
169
|
end
|
172
170
|
|
173
|
-
|
174
171
|
it "ignores XML messages by default" do
|
175
172
|
req = make_xml_request()
|
176
173
|
@request_sock.should_receive( :recv ).and_return( req )
|
@@ -183,7 +180,6 @@ describe Mongrel2::Handler do
|
|
183
180
|
response.should be_nil()
|
184
181
|
end
|
185
182
|
|
186
|
-
|
187
183
|
it "dispatches XML message to the #handle_xml method" do
|
188
184
|
xml_handler = Class.new( OneShotHandler ) do
|
189
185
|
def handle_xml( request )
|
@@ -202,7 +198,6 @@ describe Mongrel2::Handler do
|
|
202
198
|
response.should be_a( Mongrel2::Response )
|
203
199
|
end
|
204
200
|
|
205
|
-
|
206
201
|
it "continues when a ZMQ::Error is received but the connection remains open" do
|
207
202
|
req = make_request()
|
208
203
|
|
data/spec/mongrel2_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongrel2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2012-
|
39
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: nokogiri
|
@@ -157,7 +157,7 @@ dependencies:
|
|
157
157
|
requirements:
|
158
158
|
- - ~>
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version: 2.1
|
160
|
+
version: '2.1'
|
161
161
|
type: :runtime
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,23 @@ dependencies:
|
|
165
165
|
requirements:
|
166
166
|
- - ~>
|
167
167
|
- !ruby/object:Gem::Version
|
168
|
-
version: 2.1
|
168
|
+
version: '2.1'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: loggability
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ~>
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0.0'
|
177
|
+
type: :runtime
|
178
|
+
prerelease: false
|
179
|
+
version_requirements: !ruby/object:Gem::Requirement
|
180
|
+
none: false
|
181
|
+
requirements:
|
182
|
+
- - ~>
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0.0'
|
169
185
|
- !ruby/object:Gem::Dependency
|
170
186
|
name: hoe-mercurial
|
171
187
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,7 +205,7 @@ dependencies:
|
|
189
205
|
requirements:
|
190
206
|
- - ~>
|
191
207
|
- !ruby/object:Gem::Version
|
192
|
-
version: 0.0
|
208
|
+
version: 0.1.0
|
193
209
|
type: :development
|
194
210
|
prerelease: false
|
195
211
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -197,7 +213,7 @@ dependencies:
|
|
197
213
|
requirements:
|
198
214
|
- - ~>
|
199
215
|
- !ruby/object:Gem::Version
|
200
|
-
version: 0.0
|
216
|
+
version: 0.1.0
|
201
217
|
- !ruby/object:Gem::Dependency
|
202
218
|
name: rdoc
|
203
219
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,8 +362,6 @@ files:
|
|
346
362
|
- lib/mongrel2/httprequest.rb
|
347
363
|
- lib/mongrel2/httpresponse.rb
|
348
364
|
- lib/mongrel2/jsonrequest.rb
|
349
|
-
- lib/mongrel2/logging.rb
|
350
|
-
- lib/mongrel2/mixins.rb
|
351
365
|
- lib/mongrel2/request.rb
|
352
366
|
- lib/mongrel2/response.rb
|
353
367
|
- lib/mongrel2/table.rb
|
@@ -375,8 +389,6 @@ files:
|
|
375
389
|
- spec/mongrel2/handler_spec.rb
|
376
390
|
- spec/mongrel2/httprequest_spec.rb
|
377
391
|
- spec/mongrel2/httpresponse_spec.rb
|
378
|
-
- spec/mongrel2/logging_spec.rb
|
379
|
-
- spec/mongrel2/mixins_spec.rb
|
380
392
|
- spec/mongrel2/request_spec.rb
|
381
393
|
- spec/mongrel2/response_spec.rb
|
382
394
|
- spec/mongrel2/table_spec.rb
|
@@ -407,7 +419,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
407
419
|
version: '0'
|
408
420
|
requirements: []
|
409
421
|
rubyforge_project: mongrel2
|
410
|
-
rubygems_version: 1.8.
|
422
|
+
rubygems_version: 1.8.24
|
411
423
|
signing_key:
|
412
424
|
specification_version: 3
|
413
425
|
summary: Ruby-Mongrel2 is a complete Ruby (1.9-only) connector for Mongrel2[http://mongrel2.org/]
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/mongrel2/logging.rb
DELETED
@@ -1,241 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
require 'mongrel2' unless defined?( Mongrel2 )
|
7
|
-
require 'mongrel2/mixins'
|
8
|
-
|
9
|
-
|
10
|
-
# A mixin that adds a logging subsystem to the extended object.
|
11
|
-
module Mongrel2::Logging
|
12
|
-
|
13
|
-
### Logging
|
14
|
-
# Log levels
|
15
|
-
LOG_LEVELS = {
|
16
|
-
'debug' => Logger::DEBUG,
|
17
|
-
'info' => Logger::INFO,
|
18
|
-
'warn' => Logger::WARN,
|
19
|
-
'error' => Logger::ERROR,
|
20
|
-
'fatal' => Logger::FATAL,
|
21
|
-
}.freeze
|
22
|
-
LOG_LEVEL_NAMES = LOG_LEVELS.invert.freeze
|
23
|
-
|
24
|
-
|
25
|
-
### Inclusion hook
|
26
|
-
def self::extended( mod )
|
27
|
-
super
|
28
|
-
|
29
|
-
class << mod
|
30
|
-
# the log formatter that will be used when the logging subsystem is reset
|
31
|
-
attr_accessor :default_log_formatter
|
32
|
-
|
33
|
-
# the logger that will be used when the logging subsystem is reset
|
34
|
-
attr_accessor :default_logger
|
35
|
-
|
36
|
-
# the logger that's currently in effect
|
37
|
-
attr_accessor :logger
|
38
|
-
alias_method :log, :logger
|
39
|
-
alias_method :log=, :logger=
|
40
|
-
end
|
41
|
-
|
42
|
-
mod.default_logger = mod.logger = Logger.new( $stderr )
|
43
|
-
mod.default_logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
44
|
-
mod.default_log_formatter = Mongrel2::Logging::Formatter.new( mod.default_logger )
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
### Reset the global logger object to the default
|
49
|
-
def reset_logger
|
50
|
-
self.logger = self.default_logger
|
51
|
-
self.logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
52
|
-
self.logger.formatter = self.default_log_formatter
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
### Returns +true+ if the global logger has not been set to something other than
|
57
|
-
### the default one.
|
58
|
-
def using_default_logger?
|
59
|
-
return self.logger == self.default_logger
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# A alternate formatter for Logger instances.
|
64
|
-
class Formatter < Logger::Formatter
|
65
|
-
|
66
|
-
# The format to output unless debugging is turned on
|
67
|
-
DEFAULT_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"
|
68
|
-
|
69
|
-
# The format to output if debugging is turned on
|
70
|
-
DEFAULT_DEBUG_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"
|
71
|
-
|
72
|
-
|
73
|
-
### Initialize the formatter with a reference to the logger so it can check for log level.
|
74
|
-
def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
|
75
|
-
@logger = logger
|
76
|
-
@format = format
|
77
|
-
@debug_format = debug
|
78
|
-
|
79
|
-
super()
|
80
|
-
end
|
81
|
-
|
82
|
-
######
|
83
|
-
public
|
84
|
-
######
|
85
|
-
|
86
|
-
# The Logger object associated with the formatter
|
87
|
-
attr_accessor :logger
|
88
|
-
|
89
|
-
# The logging format string
|
90
|
-
attr_accessor :format
|
91
|
-
|
92
|
-
# The logging format string that's used when outputting in debug mode
|
93
|
-
attr_accessor :debug_format
|
94
|
-
|
95
|
-
|
96
|
-
### Log using either the DEBUG_FORMAT if the associated logger is at ::DEBUG level or
|
97
|
-
### using FORMAT if it's anything less verbose.
|
98
|
-
def call( severity, time, progname, msg )
|
99
|
-
args = [
|
100
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
101
|
-
time.usec, # %2$d
|
102
|
-
Process.pid, # %3$d
|
103
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
104
|
-
severity, # %5$s
|
105
|
-
progname, # %6$s
|
106
|
-
msg # %7$s
|
107
|
-
]
|
108
|
-
|
109
|
-
if @logger.level == Logger::DEBUG
|
110
|
-
return self.debug_format % args
|
111
|
-
else
|
112
|
-
return self.format % args
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end # class LogFormatter
|
116
|
-
|
117
|
-
|
118
|
-
# A ANSI-colorized formatter for Logger instances.
|
119
|
-
class ColorFormatter < Logger::Formatter
|
120
|
-
extend Mongrel2::ANSIColorUtilities
|
121
|
-
|
122
|
-
# Color settings
|
123
|
-
LEVEL_FORMATS = {
|
124
|
-
:debug => colorize( :bold, :black ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"},
|
125
|
-
:info => colorize( :normal ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
126
|
-
:warn => colorize( :bold, :yellow ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
127
|
-
:error => colorize( :red ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
128
|
-
:fatal => colorize( :bold, :red ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
### Initialize the formatter with a reference to the logger so it can check for log level.
|
133
|
-
def initialize( logger, settings={} ) # :notnew:
|
134
|
-
settings = LEVEL_FORMATS.merge( settings )
|
135
|
-
|
136
|
-
@logger = logger
|
137
|
-
@settings = settings
|
138
|
-
|
139
|
-
super()
|
140
|
-
end
|
141
|
-
|
142
|
-
######
|
143
|
-
public
|
144
|
-
######
|
145
|
-
|
146
|
-
# The Logger object associated with the formatter
|
147
|
-
attr_accessor :logger
|
148
|
-
|
149
|
-
# The formats, by level
|
150
|
-
attr_accessor :settings
|
151
|
-
|
152
|
-
|
153
|
-
### Log using the format associated with the severity
|
154
|
-
def call( severity, time, progname, msg )
|
155
|
-
args = [
|
156
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
157
|
-
time.usec, # %2$d
|
158
|
-
Process.pid, # %3$d
|
159
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
160
|
-
severity, # %5$s
|
161
|
-
progname, # %6$s
|
162
|
-
msg # %7$s
|
163
|
-
]
|
164
|
-
|
165
|
-
return self.settings[ severity.downcase.to_sym ] % args
|
166
|
-
end
|
167
|
-
end # class LogFormatter
|
168
|
-
|
169
|
-
|
170
|
-
# An alternate formatter for Logger instances that outputs +div+ HTML
|
171
|
-
# fragments.
|
172
|
-
class HtmlFormatter < Logger::Formatter
|
173
|
-
|
174
|
-
# The default HTML fragment that'll be used as the template for each log message.
|
175
|
-
HTML_LOG_FORMAT = %q{
|
176
|
-
<div class="log-message %5$s">
|
177
|
-
<span class="log-time">%1$s.%2$06d</span>
|
178
|
-
[
|
179
|
-
<span class="log-pid">%3$d</span>
|
180
|
-
/
|
181
|
-
<span class="log-tid">%4$s</span>
|
182
|
-
]
|
183
|
-
<span class="log-level">%5$s</span>
|
184
|
-
:
|
185
|
-
<span class="log-name">%6$s</span>
|
186
|
-
<span class="log-message-text">%7$s</span>
|
187
|
-
</div>
|
188
|
-
}
|
189
|
-
|
190
|
-
### Override the logging formats with ones that generate HTML fragments
|
191
|
-
def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
|
192
|
-
@logger = logger
|
193
|
-
@format = format
|
194
|
-
super()
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
######
|
199
|
-
public
|
200
|
-
######
|
201
|
-
|
202
|
-
# The HTML fragment that will be used as a format() string for the log
|
203
|
-
attr_accessor :format
|
204
|
-
|
205
|
-
|
206
|
-
### Return a log message composed out of the arguments formatted using the
|
207
|
-
### formatter's format string
|
208
|
-
def call( severity, time, progname, msg )
|
209
|
-
args = [
|
210
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
211
|
-
time.usec, # %2$d
|
212
|
-
Process.pid, # %3$d
|
213
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
214
|
-
severity.downcase, # %5$s
|
215
|
-
progname, # %6$s
|
216
|
-
html_escape( msg ).gsub(/\n/, '<br />') # %7$s
|
217
|
-
]
|
218
|
-
|
219
|
-
return self.format % args
|
220
|
-
end
|
221
|
-
|
222
|
-
|
223
|
-
#######
|
224
|
-
private
|
225
|
-
#######
|
226
|
-
|
227
|
-
### Return a copy of the specified +string+ with HTML special characters escaped as
|
228
|
-
### HTML entities.
|
229
|
-
def html_escape( string )
|
230
|
-
return string.
|
231
|
-
gsub( /&/, '&' ).
|
232
|
-
gsub( /</, '<' ).
|
233
|
-
gsub( />/, '>' )
|
234
|
-
end
|
235
|
-
|
236
|
-
end # class HtmlLogFormatter
|
237
|
-
|
238
|
-
end # module Mongrel2
|
239
|
-
|
240
|
-
# vim: set nosta noet ts=4 sw=4:
|
241
|
-
|
data/lib/mongrel2/mixins.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
require 'mongrel2' unless defined?( Mongrel2 )
|
6
|
-
require 'mongrel2/constants'
|
7
|
-
|
8
|
-
|
9
|
-
module Mongrel2
|
10
|
-
|
11
|
-
# Add logging to a Mongrel2 class. Including classes get #log and #log_debug methods.
|
12
|
-
module Loggable
|
13
|
-
|
14
|
-
# A logging proxy class that wraps calls to the logger into calls that include
|
15
|
-
# the name of the calling class.
|
16
|
-
class ClassNameProxy
|
17
|
-
|
18
|
-
### Create a new proxy for the given +klass+.
|
19
|
-
def initialize( klass, force_debug=false )
|
20
|
-
@classname = klass.name
|
21
|
-
@force_debug = force_debug
|
22
|
-
end
|
23
|
-
|
24
|
-
### Delegate debug messages to the global logger with the appropriate class name.
|
25
|
-
def debug( msg=nil, &block )
|
26
|
-
Mongrel2.logger.add( Logger::DEBUG, msg, @classname, &block )
|
27
|
-
end
|
28
|
-
|
29
|
-
### Delegate info messages to the global logger with the appropriate class name.
|
30
|
-
def info( msg=nil, &block )
|
31
|
-
return self.debug( msg, &block ) if @force_debug
|
32
|
-
Mongrel2.logger.add( Logger::INFO, msg, @classname, &block )
|
33
|
-
end
|
34
|
-
|
35
|
-
### Delegate warn messages to the global logger with the appropriate class name.
|
36
|
-
def warn( msg=nil, &block )
|
37
|
-
return self.debug( msg, &block ) if @force_debug
|
38
|
-
Mongrel2.logger.add( Logger::WARN, msg, @classname, &block )
|
39
|
-
end
|
40
|
-
|
41
|
-
### Delegate error messages to the global logger with the appropriate class name.
|
42
|
-
def error( msg=nil, &block )
|
43
|
-
return self.debug( msg, &block ) if @force_debug
|
44
|
-
Mongrel2.logger.add( Logger::ERROR, msg, @classname, &block )
|
45
|
-
end
|
46
|
-
|
47
|
-
### Delegate fatal messages to the global logger with the appropriate class name.
|
48
|
-
def fatal( msg=nil, &block )
|
49
|
-
Mongrel2.logger.add( Logger::FATAL, msg, @classname, &block )
|
50
|
-
end
|
51
|
-
|
52
|
-
end # ClassNameProxy
|
53
|
-
|
54
|
-
#########
|
55
|
-
protected
|
56
|
-
#########
|
57
|
-
|
58
|
-
### Copy constructor -- clear the original's log proxy.
|
59
|
-
def initialize_copy( original )
|
60
|
-
@log_proxy = @log_debug_proxy = nil
|
61
|
-
super
|
62
|
-
end
|
63
|
-
|
64
|
-
### Return the proxied logger.
|
65
|
-
def log
|
66
|
-
@log_proxy ||= ClassNameProxy.new( self.class )
|
67
|
-
end
|
68
|
-
|
69
|
-
### Return a proxied "debug" logger that ignores other level specification.
|
70
|
-
def log_debug
|
71
|
-
@log_debug_proxy ||= ClassNameProxy.new( self.class, true )
|
72
|
-
end
|
73
|
-
|
74
|
-
end # module Loggable
|
75
|
-
|
76
|
-
# A collection of ANSI color utility functions
|
77
|
-
module ANSIColorUtilities
|
78
|
-
|
79
|
-
# Set some ANSI escape code constants (Shamelessly stolen from Perl's
|
80
|
-
# Term::ANSIColor by Russ Allbery <rra@stanford.edu> and Zenin <zenin@best.com>
|
81
|
-
ANSI_ATTRIBUTES = {
|
82
|
-
'clear' => 0,
|
83
|
-
'reset' => 0,
|
84
|
-
'bold' => 1,
|
85
|
-
'dark' => 2,
|
86
|
-
'underline' => 4,
|
87
|
-
'underscore' => 4,
|
88
|
-
'blink' => 5,
|
89
|
-
'reverse' => 7,
|
90
|
-
'concealed' => 8,
|
91
|
-
|
92
|
-
'black' => 30, 'on_black' => 40,
|
93
|
-
'red' => 31, 'on_red' => 41,
|
94
|
-
'green' => 32, 'on_green' => 42,
|
95
|
-
'yellow' => 33, 'on_yellow' => 43,
|
96
|
-
'blue' => 34, 'on_blue' => 44,
|
97
|
-
'magenta' => 35, 'on_magenta' => 45,
|
98
|
-
'cyan' => 36, 'on_cyan' => 46,
|
99
|
-
'white' => 37, 'on_white' => 47
|
100
|
-
}
|
101
|
-
|
102
|
-
###############
|
103
|
-
module_function
|
104
|
-
###############
|
105
|
-
|
106
|
-
### Create a string that contains the ANSI codes specified and return it
|
107
|
-
def ansi_code( *attributes )
|
108
|
-
attributes.flatten!
|
109
|
-
attributes.collect! {|at| at.to_s }
|
110
|
-
return '' unless /(?:vt10[03]|xterm(?:-color)?|linux|screen)/i =~ ENV['TERM']
|
111
|
-
attributes = ANSI_ATTRIBUTES.values_at( *attributes ).compact.join(';')
|
112
|
-
|
113
|
-
if attributes.empty?
|
114
|
-
return ''
|
115
|
-
else
|
116
|
-
return "\e[%sm" % attributes
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
### Colorize the given +string+ with the specified +attributes+ and return it, handling
|
122
|
-
### line-endings, color reset, etc.
|
123
|
-
def colorize( *args )
|
124
|
-
string = ''
|
125
|
-
|
126
|
-
if block_given?
|
127
|
-
string = yield
|
128
|
-
else
|
129
|
-
string = args.shift
|
130
|
-
end
|
131
|
-
|
132
|
-
ending = string[/(\s)$/] || ''
|
133
|
-
string = string.rstrip
|
134
|
-
|
135
|
-
return ansi_code( args.flatten ) + string + ansi_code( 'reset' ) + ending
|
136
|
-
end
|
137
|
-
|
138
|
-
end # module ANSIColorUtilities
|
139
|
-
|
140
|
-
end # module Mongrel2
|
141
|
-
|
142
|
-
# vim: set nosta noet ts=4 sw=4:
|
143
|
-
|