ramaze 0.1.2 → 0.1.3
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/Rakefile +1 -1
- data/doc/AUTHORS +2 -0
- data/doc/CHANGELOG +173 -0
- data/doc/changes.txt +4184 -0
- data/doc/changes.xml +4186 -0
- data/doc/meta/announcement.txt +22 -25
- data/doc/meta/internals.txt +146 -9
- data/examples/blog/template/index.xhtml +5 -2
- data/examples/fcgi.rb +13 -0
- data/examples/wiktacular/main.rb +8 -0
- data/examples/wiktacular/mkd/link/2007-07-20_19-45-51.mkd +1 -0
- data/examples/wiktacular/mkd/link/current.mkd +1 -0
- data/examples/wiktacular/mkd/main/2007-07-20_16-31-33.mkd +1 -0
- data/examples/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -0
- data/examples/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +2 -0
- data/examples/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +2 -0
- data/examples/wiktacular/mkd/main/current.mkd +2 -0
- data/examples/wiktacular/mkd/markdown/current.mkd +3 -0
- data/examples/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +2 -0
- data/examples/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +3 -0
- data/examples/wiktacular/mkd/testing/2007-07-21_18-46-01.mkd +11 -0
- data/examples/wiktacular/mkd/testing/2007-07-21_18-46-32.mkd +13 -0
- data/examples/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +17 -0
- data/examples/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +17 -0
- data/examples/wiktacular/mkd/testing/current.mkd +17 -0
- data/examples/wiktacular/public/favicon.ico +0 -0
- data/examples/wiktacular/public/screen.css +72 -0
- data/examples/wiktacular/src/controller.rb +44 -0
- data/examples/wiktacular/src/model.rb +92 -0
- data/examples/wiktacular/src/page.rb +66 -0
- data/examples/wiktacular/template/edit.xhtml +7 -0
- data/examples/wiktacular/template/index.xhtml +11 -0
- data/examples/wiktacular/template/new.xhtml +7 -0
- data/lib/proto/main.rb +2 -0
- data/lib/proto/public/error.zmr +3 -0
- data/lib/proto/public/js/jquery.js +1755 -1334
- data/lib/proto/template/index.xhtml +2 -2
- data/lib/ramaze.rb +8 -3
- data/lib/ramaze/action/render.rb +11 -0
- data/lib/ramaze/adapter/base.rb +11 -7
- data/lib/ramaze/cache.rb +25 -10
- data/lib/ramaze/cache/memcached.rb +16 -1
- data/lib/ramaze/cache/yaml_store.rb +10 -0
- data/lib/ramaze/controller.rb +12 -2
- data/lib/ramaze/controller/error.rb +9 -3
- data/lib/ramaze/controller/resolve.rb +20 -18
- data/lib/ramaze/dispatcher.rb +13 -4
- data/lib/ramaze/dispatcher/action.rb +7 -3
- data/lib/ramaze/dispatcher/error.rb +24 -2
- data/lib/ramaze/dispatcher/file.rb +12 -6
- data/lib/ramaze/global.rb +0 -3
- data/lib/ramaze/global/dsl.rb +9 -0
- data/lib/ramaze/global/globalstruct.rb +7 -1
- data/lib/ramaze/helper/aspect.rb +4 -2
- data/lib/ramaze/helper/cgi.rb +2 -2
- data/lib/ramaze/helper/file.rb +3 -0
- data/lib/ramaze/helper/link.rb +20 -0
- data/lib/ramaze/helper/markaby.rb +3 -0
- data/lib/ramaze/helper/pager.rb +10 -17
- data/lib/ramaze/helper/partial.rb +9 -3
- data/lib/ramaze/inform/analogger.rb +14 -0
- data/lib/ramaze/inform/growl.rb +7 -0
- data/lib/ramaze/inform/hub.rb +9 -0
- data/lib/ramaze/inform/informer.rb +9 -3
- data/lib/ramaze/inform/informing.rb +9 -3
- data/lib/ramaze/inform/knotify.rb +5 -1
- data/lib/ramaze/inform/syslog.rb +3 -0
- data/lib/ramaze/inform/xosd.rb +12 -0
- data/lib/ramaze/template.rb +3 -0
- data/lib/ramaze/template/amrita2.rb +2 -0
- data/lib/ramaze/template/erubis.rb +1 -0
- data/lib/ramaze/template/ezamar.rb +1 -0
- data/lib/ramaze/template/ezamar/element.rb +17 -11
- data/lib/ramaze/template/ezamar/engine.rb +5 -0
- data/lib/ramaze/template/ezamar/render_partial.rb +4 -2
- data/lib/ramaze/template/haml.rb +4 -0
- data/lib/ramaze/template/liquid.rb +4 -0
- data/lib/ramaze/template/markaby.rb +4 -0
- data/lib/ramaze/template/remarkably.rb +4 -0
- data/lib/ramaze/tool.rb +10 -0
- data/lib/ramaze/tool/localize.rb +1 -1
- data/lib/ramaze/trinity/session.rb +8 -1
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/maintaince.rake +2 -2
- data/spec/ramaze/action/basics.rb +1 -1
- data/spec/ramaze/cache.rb +11 -0
- data/spec/ramaze/controller.rb +0 -14
- data/spec/ramaze/dispatcher/file.rb +5 -5
- data/spec/ramaze/dispatcher/public/favicon.ico +0 -0
- data/spec/ramaze/dispatcher/public/test_download.css +141 -0
- data/spec/ramaze/error.rb +21 -7
- data/spec/ramaze/helper/link.rb +15 -0
- data/spec/ramaze/helper/pager.rb +26 -3
- data/spec/ramaze/helper/partial.rb +2 -2
- metadata +43 -4
- data/doc/COPYING.ja +0 -51
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
|
-
# require 'ramaze/tool/tidy'
|
|
5
|
-
# require 'ramaze/tool/localize'
|
|
6
|
-
|
|
7
4
|
module Ramaze
|
|
8
5
|
module Dispatcher
|
|
9
6
|
class Action
|
|
@@ -16,10 +13,17 @@ module Ramaze
|
|
|
16
13
|
]
|
|
17
14
|
|
|
18
15
|
class << self
|
|
16
|
+
|
|
17
|
+
# Takes path, asks Controller to handle it and builds a response on
|
|
18
|
+
# success. The response is then passed to each member of FILTER for
|
|
19
|
+
# post-processing.
|
|
20
|
+
|
|
19
21
|
def process(path)
|
|
20
22
|
body = Controller.handle(path)
|
|
21
23
|
response = Dispatcher.build_response(body)
|
|
22
24
|
FILTER.inject(response){|r,f| f.call(r) }
|
|
25
|
+
rescue Ramaze::Error => ex
|
|
26
|
+
ex
|
|
23
27
|
end
|
|
24
28
|
end
|
|
25
29
|
end
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
5
|
module Dispatcher
|
|
6
|
+
|
|
7
|
+
# Last resort dispatcher, tries to recover as much information as possible
|
|
8
|
+
# from the past request and takes the appropiate actions.
|
|
9
|
+
#
|
|
10
|
+
# You can configure it over the HANDLE_ERROR constant or by defining error
|
|
11
|
+
# actions in your controllers.
|
|
12
|
+
|
|
6
13
|
class Error
|
|
7
14
|
HANDLE_ERROR = {
|
|
8
15
|
Exception => [ 500, '/error' ],
|
|
@@ -13,13 +20,23 @@ module Ramaze
|
|
|
13
20
|
class << self
|
|
14
21
|
trait :last_error => nil
|
|
15
22
|
|
|
16
|
-
def process
|
|
23
|
+
def process(error, metainfo = {})
|
|
17
24
|
log_error(error)
|
|
18
25
|
|
|
19
26
|
Thread.current[:exception] = error
|
|
20
27
|
|
|
21
28
|
key = error.class.ancestors.find{|a| HANDLE_ERROR[a]}
|
|
22
29
|
status, path = *HANDLE_ERROR[key || Exception]
|
|
30
|
+
status ||= 500
|
|
31
|
+
|
|
32
|
+
if controller = metainfo[:controller]
|
|
33
|
+
begin
|
|
34
|
+
action = Controller.resolve(controller.mapping + path)
|
|
35
|
+
return Dispatcher.build_response(action.render, status)
|
|
36
|
+
rescue Ramaze::Error
|
|
37
|
+
Inform.debug("No custom error page found on #{controller}, going to #{path}")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
23
40
|
|
|
24
41
|
unless error.message =~ %r(`#{path.split('/').last}')
|
|
25
42
|
Response.current.status = status
|
|
@@ -29,7 +46,7 @@ module Ramaze
|
|
|
29
46
|
Dispatcher.build_response(error.message, status)
|
|
30
47
|
rescue Object => ex
|
|
31
48
|
Inform.error(ex)
|
|
32
|
-
Dispatcher.build_response(ex.message, status
|
|
49
|
+
Dispatcher.build_response(ex.message, status)
|
|
33
50
|
end
|
|
34
51
|
|
|
35
52
|
def log_error error
|
|
@@ -42,6 +59,11 @@ module Ramaze
|
|
|
42
59
|
Inform.error(error)
|
|
43
60
|
end
|
|
44
61
|
end
|
|
62
|
+
|
|
63
|
+
def current
|
|
64
|
+
Thread.current[:exception]
|
|
65
|
+
end
|
|
66
|
+
|
|
45
67
|
end
|
|
46
68
|
end
|
|
47
69
|
end
|
|
@@ -3,22 +3,28 @@
|
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
5
|
module Dispatcher
|
|
6
|
+
|
|
7
|
+
# First of the dispatchers, looks up the public path and serves the
|
|
8
|
+
# file if found.
|
|
9
|
+
|
|
6
10
|
class File
|
|
7
11
|
class << self
|
|
12
|
+
|
|
13
|
+
# Entry point from Dispatcher::filter.
|
|
14
|
+
# searches for the file and builds a response with status 200 if found.
|
|
15
|
+
|
|
8
16
|
def process(path)
|
|
9
17
|
return unless file = open_file(path)
|
|
10
18
|
Dispatcher.build_response(file, Ramaze::STATUS_CODE['OK'])
|
|
11
19
|
end
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end
|
|
21
|
+
# returns file-handle with the open file on success, setting the
|
|
22
|
+
# Content-Type as found in Tool::MIME
|
|
16
23
|
|
|
17
24
|
def open_file(path)
|
|
18
|
-
|
|
19
|
-
file = paths.find{|way| ::File.file?(way)}
|
|
25
|
+
file = Global.public_root/path
|
|
20
26
|
|
|
21
|
-
if file
|
|
27
|
+
if ::File.file?(file)
|
|
22
28
|
response = Response.current
|
|
23
29
|
response['Content-Type'] = Tool::MIME.type_for(file)
|
|
24
30
|
Inform.debug("Serving static: #{file}")
|
data/lib/ramaze/global.rb
CHANGED
|
@@ -53,9 +53,6 @@ module Ramaze
|
|
|
53
53
|
o "Specify port",
|
|
54
54
|
:port => 7000, :cli => 7000
|
|
55
55
|
|
|
56
|
-
o "Specify the shadowing public directory (default in proto)",
|
|
57
|
-
:public_proto => ( BASEDIR / 'proto' / 'public' )
|
|
58
|
-
|
|
59
56
|
o "Specify the public directory of your application serving static files",
|
|
60
57
|
:public_root => File.expand_path('./public')
|
|
61
58
|
|
data/lib/ramaze/global/dsl.rb
CHANGED
|
@@ -6,12 +6,21 @@ module Ramaze
|
|
|
6
6
|
OPTIONS = {}
|
|
7
7
|
CLI_OPTIONS = []
|
|
8
8
|
|
|
9
|
+
# DSL for specifying Globap options before initializing Global
|
|
10
|
+
|
|
9
11
|
module GlobalDSL
|
|
10
12
|
class << self
|
|
13
|
+
|
|
14
|
+
# The method that takes the block containing the DSL, used like in
|
|
15
|
+
# lib/ramaze/global.rb
|
|
16
|
+
|
|
11
17
|
def option_dsl(&block)
|
|
12
18
|
instance_eval(&block)
|
|
13
19
|
end
|
|
14
20
|
|
|
21
|
+
# Takes a doc-string and then the option as hash, another :cli key can
|
|
22
|
+
# be given that will expose this option via the bin/ramaze.
|
|
23
|
+
|
|
15
24
|
def o(doc, options = {})
|
|
16
25
|
cli_given = options.has_key?(:cli)
|
|
17
26
|
cli = options.delete(:cli)
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
-
|
|
5
|
+
unless defined?(GlobalStruct) # prevent problems for SourceReload
|
|
6
|
+
class GlobalStruct < Struct.new('Global', *OPTIONS.keys)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class GlobalStruct
|
|
11
|
+
|
|
6
12
|
ADAPTER_ALIAS = {
|
|
7
13
|
:webrick => :WEBrick,
|
|
8
14
|
:mongrel => :Mongrel,
|
data/lib/ramaze/helper/aspect.rb
CHANGED
|
@@ -60,12 +60,14 @@ module Ramaze
|
|
|
60
60
|
|
|
61
61
|
class Action
|
|
62
62
|
def before_process
|
|
63
|
-
|
|
63
|
+
return unless aspects = controller.ancestral_trait[:aspects]
|
|
64
|
+
block = aspects[:before][method]
|
|
64
65
|
instance.instance_eval(&block) if block
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
def after_process
|
|
68
|
-
|
|
69
|
+
return unless aspects = controller.ancestral_trait[:aspects]
|
|
70
|
+
block = aspects[:after][method]
|
|
69
71
|
instance.instance_eval(&block) if block
|
|
70
72
|
end
|
|
71
73
|
end
|
data/lib/ramaze/helper/cgi.rb
CHANGED
|
@@ -27,13 +27,13 @@ module Ramaze
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# shortcut for GCI.unescapeHTML
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def html_unescape(string)
|
|
32
32
|
CGI.unescapeHTML(string)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# one-letter versions help in case like #{h foo.inspect}
|
|
36
|
-
# ERb/ERuby/Rails compatible
|
|
36
|
+
# ERb/ERuby/Rails compatible
|
|
37
37
|
alias h html_escape
|
|
38
38
|
alias u url_encode
|
|
39
39
|
|
data/lib/ramaze/helper/file.rb
CHANGED
data/lib/ramaze/helper/link.rb
CHANGED
|
@@ -79,5 +79,25 @@ module Ramaze
|
|
|
79
79
|
def Rs(*atoms)
|
|
80
80
|
R(Controller.current, *atoms)
|
|
81
81
|
end
|
|
82
|
+
|
|
83
|
+
# Give it a path with character to split at and one to join the crumbs with.
|
|
84
|
+
# It will generate a list of links that act as pointers to previous pages on
|
|
85
|
+
# this path.
|
|
86
|
+
#
|
|
87
|
+
# Example:
|
|
88
|
+
# breadcrumbs('/path/to/somewhere')
|
|
89
|
+
#
|
|
90
|
+
# # results in this, newlines added for readability:
|
|
91
|
+
#
|
|
92
|
+
# <a href="/path">path</a>/
|
|
93
|
+
# <a href="/path/to">to</a>/
|
|
94
|
+
# <a href="/path/to/somewhere">somewhere</a>
|
|
95
|
+
|
|
96
|
+
def breadcrumbs(path, split = '/', join = '/')
|
|
97
|
+
atoms = path.split(split).reject{|a| a.empty?}
|
|
98
|
+
crumbs = atoms.inject([]){|s,v| s << [s.last,v]}
|
|
99
|
+
bread = crumbs.map{|a| A(a[-1], :href=>(a*'/'))}
|
|
100
|
+
bread.join(join)
|
|
101
|
+
end
|
|
82
102
|
end
|
|
83
103
|
end
|
data/lib/ramaze/helper/pager.rb
CHANGED
|
@@ -111,7 +111,7 @@ class Pager
|
|
|
111
111
|
|
|
112
112
|
# Return the index of the previous page.
|
|
113
113
|
|
|
114
|
-
def
|
|
114
|
+
def prev_page
|
|
115
115
|
[@page - 1, 1].max
|
|
116
116
|
end
|
|
117
117
|
|
|
@@ -121,17 +121,10 @@ class Pager
|
|
|
121
121
|
[@page + 1, @page_count].min
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def link_#{target}_page
|
|
129
|
-
target_uri(#{target}_page)
|
|
130
|
-
end
|
|
131
|
-
alias_method :#{target}_page_uri, :link_#{target}_page
|
|
132
|
-
alias_method :#{target}_page_href, :link_#{target}_page
|
|
133
|
-
}
|
|
134
|
-
end
|
|
124
|
+
def link_first_page; target_uri(first_page); end
|
|
125
|
+
def link_last_page; target_uri(last_page); end
|
|
126
|
+
def link_prev_page; target_uri(prev_page); end
|
|
127
|
+
def link_next_page; target_uri(next_page); end
|
|
135
128
|
|
|
136
129
|
# Iterator
|
|
137
130
|
|
|
@@ -208,15 +201,15 @@ class Pager
|
|
|
208
201
|
|
|
209
202
|
unless first_page?
|
|
210
203
|
nav << %{
|
|
211
|
-
<div class="first"><a href="#{
|
|
212
|
-
<div class="previous"><a href="#{
|
|
204
|
+
<div class="first"><a href="#{link_first_page}">First</a></div>
|
|
205
|
+
<div class="previous"><a href="#{link_prev_page}">Previous</a></div>
|
|
213
206
|
}
|
|
214
207
|
end
|
|
215
208
|
|
|
216
209
|
unless last_page?
|
|
217
210
|
nav << %{
|
|
218
|
-
<div class="last"><a href="#{
|
|
219
|
-
<div class="next"><a href="#{
|
|
211
|
+
<div class="last"><a href="#{link_last_page}">Last</a></div>
|
|
212
|
+
<div class="next"><a href="#{link_next_page}">Next</a></div>
|
|
220
213
|
}
|
|
221
214
|
end
|
|
222
215
|
|
|
@@ -249,7 +242,7 @@ private
|
|
|
249
242
|
|
|
250
243
|
def target_uri(page)
|
|
251
244
|
params = Request.current.params.dup.update(@key => page)
|
|
252
|
-
Rs(
|
|
245
|
+
Rs(Action.current.method, params)
|
|
253
246
|
end
|
|
254
247
|
|
|
255
248
|
end
|
|
@@ -14,15 +14,21 @@ module Ramaze
|
|
|
14
14
|
|
|
15
15
|
def render_partial(url, options = {})
|
|
16
16
|
saved = {}
|
|
17
|
-
options.keys.each {|x| saved[x] =
|
|
17
|
+
options.keys.each {|x| saved[x] = Request.current.params[x] }
|
|
18
|
+
saved_action = Thread.current[:action]
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Request.current.params.update(options)
|
|
20
21
|
|
|
21
22
|
Controller.handle(url)
|
|
22
23
|
ensure
|
|
23
|
-
|
|
24
|
+
Thread.current[:action] = saved_action
|
|
25
|
+
options.keys.each {|x| Request.current.params[x] = saved[x] }
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
# Generate from a filename in template_root of the given (or current)
|
|
29
|
+
# controller a new action.
|
|
30
|
+
# Any option you don't pass is instead taken from Action.current
|
|
31
|
+
|
|
26
32
|
def render_template(file, options = {})
|
|
27
33
|
current = Action.current
|
|
28
34
|
options[:binding] ||= current.binding
|
|
@@ -5,17 +5,31 @@ require 'swiftcore/Analogger/Client'
|
|
|
5
5
|
|
|
6
6
|
module Ramaze
|
|
7
7
|
|
|
8
|
+
# Informer for the Swiftcore Analogger logging system.
|
|
9
|
+
#
|
|
10
|
+
# You can find it at http://analogger.swiftcore.org and install with
|
|
11
|
+
# gem install analogger
|
|
12
|
+
|
|
8
13
|
class Analogger < ::Swiftcore::Analogger::Client
|
|
9
14
|
include Informing
|
|
10
15
|
|
|
16
|
+
# identifier for your application
|
|
11
17
|
trait :name => 'walrus'
|
|
18
|
+
|
|
19
|
+
# Host analogger runs on
|
|
12
20
|
trait :host => '127.0.0.1'
|
|
21
|
+
|
|
22
|
+
# Port analogger runs on
|
|
13
23
|
trait :port => 6766
|
|
14
24
|
|
|
25
|
+
# Create a new instance, parameters default to the traits.
|
|
26
|
+
|
|
15
27
|
def initialize(name = class_trait[:name], host = class_trait[:host], port = class_trait[:port])
|
|
16
28
|
super
|
|
17
29
|
end
|
|
18
30
|
|
|
31
|
+
# integration to Informing
|
|
32
|
+
|
|
19
33
|
def inform(tag, *args)
|
|
20
34
|
log(tag, args.join("\n"))
|
|
21
35
|
end
|
data/lib/ramaze/inform/growl.rb
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
require 'ruby-growl'
|
|
5
5
|
|
|
6
6
|
module Ramaze
|
|
7
|
+
|
|
8
|
+
# Informer for the growl notification system on OSX.
|
|
9
|
+
|
|
7
10
|
class Growl < ::Growl
|
|
8
11
|
|
|
9
12
|
trait :defaults => {
|
|
@@ -14,11 +17,15 @@ module Ramaze
|
|
|
14
17
|
:default_notifies => %w[error warn info]
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
# Takes the options from the default trait for merging.
|
|
21
|
+
|
|
17
22
|
def initialize(options = {})
|
|
18
23
|
options = class_trait[:defaults].merge(options).values_at(:host, :name, :all_notifies, :default_notifies, :password)
|
|
19
24
|
super(*options)
|
|
20
25
|
end
|
|
21
26
|
|
|
27
|
+
# integration to Informing
|
|
28
|
+
|
|
22
29
|
def inform(tag, *args)
|
|
23
30
|
notify(tag.to_s, Time.now.strftime("%X"), args.join("\n")[0..100])
|
|
24
31
|
rescue Errno::EMSGSIZE
|
data/lib/ramaze/inform/hub.rb
CHANGED
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
require 'set'
|
|
5
5
|
|
|
6
6
|
module Ramaze
|
|
7
|
+
|
|
8
|
+
# Bundles different informer instances and sends incoming messages to each.
|
|
9
|
+
# This is the default with Informer as only member.
|
|
10
|
+
|
|
7
11
|
class LogHub
|
|
8
12
|
include Informing
|
|
9
13
|
|
|
10
14
|
attr_accessor :loggers
|
|
11
15
|
attr_accessor :ignored_tags
|
|
12
16
|
|
|
17
|
+
# Takes a list of instances or classes (which will be initialized) and that
|
|
18
|
+
# are added to @loggers. All messages are then sent to each member.
|
|
19
|
+
|
|
13
20
|
def initialize(*loggers)
|
|
14
21
|
@loggers = loggers
|
|
15
22
|
@ignored_tags = Set.new
|
|
@@ -21,6 +28,8 @@ module Ramaze
|
|
|
21
28
|
@loggers.compact!
|
|
22
29
|
end
|
|
23
30
|
|
|
31
|
+
# integration to Informing
|
|
32
|
+
|
|
24
33
|
def inform(tag, *args)
|
|
25
34
|
return if @ignored_tags.include?(tag)
|
|
26
35
|
@loggers.each do |logger|
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
+
|
|
6
|
+
# A minimal logger for Ramaze, supports files, CLI, colors and some
|
|
7
|
+
# customization.
|
|
8
|
+
|
|
5
9
|
class Informer
|
|
6
10
|
include Informing
|
|
7
11
|
|
|
8
|
-
attr_accessor :out, :colorize
|
|
12
|
+
attr_accessor :out, :colorize, :log_levels
|
|
9
13
|
|
|
10
14
|
# Should Ramaze try to use colors?
|
|
11
15
|
trait :colorize => true
|
|
@@ -24,7 +28,7 @@ module Ramaze
|
|
|
24
28
|
:error => :red,
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
def initialize(out = $stdout)
|
|
31
|
+
def initialize(out = $stdout, log_levels = [:debug, :error, :info, :warn])
|
|
28
32
|
@colorize = false
|
|
29
33
|
|
|
30
34
|
@out =
|
|
@@ -46,6 +50,8 @@ module Ramaze
|
|
|
46
50
|
if @out.respond_to?(:tty?) and class_trait[:colorize]
|
|
47
51
|
@colorize = @out.tty?
|
|
48
52
|
end
|
|
53
|
+
|
|
54
|
+
@log_levels = log_levels
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
def shutdown
|
|
@@ -56,7 +62,7 @@ module Ramaze
|
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
def inform tag, *messages
|
|
59
|
-
return if closed?
|
|
65
|
+
return if closed? || !@log_levels.include?(tag)
|
|
60
66
|
messages.flatten!
|
|
61
67
|
|
|
62
68
|
prefix = tag.to_s.upcase.ljust(5)
|