ramaze 0.0.9 → 0.1.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.
- data/Rakefile +14 -259
- data/bin/ramaze +52 -25
- data/doc/AUTHORS +6 -0
- data/doc/CHANGELOG +1363 -42
- data/doc/INSTALL +1 -1
- data/doc/README +48 -35
- data/doc/README.html +637 -0
- data/doc/TODO +7 -16
- data/doc/allison/allison.css +6 -7
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/cache/STYLE +1 -2
- data/doc/changes.txt +3375 -0
- data/doc/changes.xml +3378 -0
- data/doc/meta/announcement.txt +47 -0
- data/doc/meta/configuration.txt +179 -0
- data/doc/meta/internals.txt +111 -0
- data/doc/readme_chunks/features.txt +8 -16
- data/doc/readme_chunks/installing.txt +7 -1
- data/doc/tutorial/todolist.txt +2 -3
- data/examples/blog/main.rb +9 -8
- data/examples/blog/public/styles/blog.css +132 -0
- data/examples/blog/src/controller.rb +14 -41
- data/examples/blog/src/model.rb +12 -13
- data/examples/blog/src/view.rb +16 -0
- data/examples/blog/template/edit.xhtml +19 -8
- data/examples/blog/template/index.xhtml +14 -22
- data/examples/blog/template/new.xhtml +18 -5
- data/examples/caching.rb +5 -8
- data/examples/element.rb +3 -3
- data/examples/hello.rb +3 -5
- data/examples/simple.rb +4 -7
- data/examples/templates/template/external.haml +8 -7
- data/examples/templates/template/external.mab +11 -8
- data/examples/templates/template_amrita2.rb +4 -4
- data/examples/templates/template_erubis.rb +3 -3
- data/examples/templates/template_ezamar.rb +1 -2
- data/examples/templates/template_haml.rb +24 -23
- data/examples/templates/template_liquid.rb +3 -1
- data/examples/templates/template_markaby.rb +15 -9
- data/examples/todolist/src/element/page.rb +1 -1
- data/lib/proto/conf/benchmark.yaml +6 -20
- data/lib/proto/conf/debug.yaml +6 -19
- data/lib/proto/conf/live.yaml +7 -19
- data/lib/proto/conf/silent.yaml +6 -16
- data/lib/proto/conf/stage.yaml +6 -18
- data/lib/proto/public/error.zmr +2 -2
- data/lib/ramaze.rb +34 -72
- data/lib/ramaze/adapter.rb +21 -18
- data/lib/ramaze/adapter/mongrel.rb +0 -3
- data/lib/ramaze/adapter/webrick.rb +6 -6
- data/lib/ramaze/cache/memcached.rb +3 -0
- data/lib/ramaze/controller.rb +227 -183
- data/lib/ramaze/dispatcher.rb +34 -129
- data/lib/ramaze/dispatcher/action.rb +28 -0
- data/lib/ramaze/dispatcher/error.rb +43 -0
- data/lib/ramaze/dispatcher/file.rb +34 -0
- data/lib/ramaze/global.rb +89 -48
- data/lib/ramaze/helper/aspect.rb +8 -6
- data/lib/ramaze/helper/auth.rb +3 -3
- data/lib/ramaze/helper/cache.rb +2 -2
- data/lib/ramaze/helper/file.rb +14 -0
- data/lib/ramaze/helper/inform.rb +36 -0
- data/lib/ramaze/helper/link.rb +7 -3
- data/lib/ramaze/helper/markaby.rb +30 -0
- data/lib/ramaze/helper/redirect.rb +2 -0
- data/lib/ramaze/inform.rb +8 -182
- data/lib/ramaze/inform/analogger.rb +19 -0
- data/lib/ramaze/inform/growl.rb +28 -0
- data/lib/ramaze/inform/hub.rb +26 -0
- data/lib/ramaze/inform/informer.rb +92 -0
- data/lib/ramaze/inform/informing.rb +44 -0
- data/lib/ramaze/inform/syslog.rb +27 -0
- data/lib/ramaze/inform/xosd.rb +42 -0
- data/lib/ramaze/snippets.rb +6 -2
- data/lib/ramaze/snippets/object/traits.rb +13 -1
- data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
- data/lib/ramaze/snippets/string/color.rb +27 -0
- data/lib/ramaze/snippets/string/each.rb +6 -0
- data/lib/ramaze/snippets/struct/fill.rb +15 -0
- data/lib/ramaze/template/ezamar.rb +13 -22
- data/lib/ramaze/template/ezamar/element.rb +12 -12
- data/lib/ramaze/template/liquid.rb +19 -18
- data/lib/ramaze/template/markaby.rb +37 -58
- data/lib/ramaze/tool/localize.rb +128 -0
- data/lib/ramaze/tool/tidy.rb +51 -21
- data/lib/ramaze/trinity.rb +3 -3
- data/lib/ramaze/trinity/request.rb +41 -23
- data/lib/ramaze/trinity/response.rb +10 -5
- data/lib/ramaze/trinity/session.rb +17 -3
- data/lib/ramaze/version.rb +2 -2
- data/rake_tasks/conf.rake +56 -0
- data/rake_tasks/gem.rake +44 -0
- data/rake_tasks/maintaince.rake +187 -0
- data/spec/all.rb +32 -0
- data/spec/examples/caching.rb +19 -0
- data/spec/examples/element.rb +15 -0
- data/spec/examples/hello.rb +11 -0
- data/spec/examples/simple.rb +51 -0
- data/spec/examples/templates/template_amrita2.rb +14 -0
- data/spec/examples/templates/template_erubis.rb +21 -0
- data/spec/examples/templates/template_ezamar.rb +22 -0
- data/spec/examples/templates/template_haml.rb +23 -0
- data/spec/examples/templates/template_liquid.rb +24 -0
- data/spec/examples/templates/template_markaby.rb +21 -0
- data/spec/helper.rb +81 -0
- data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
- data/spec/helper/layout.rb +55 -0
- data/spec/helper/mock_http.rb +66 -0
- data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
- data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
- data/spec/helper/wrap.rb +193 -0
- data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
- data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
- data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
- data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
- data/spec/ramaze/conf/locale_de.yaml +6 -0
- data/spec/ramaze/conf/locale_en.yaml +6 -0
- data/spec/ramaze/controller.rb +184 -0
- data/spec/ramaze/controller/template/greet.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +54 -0
- data/spec/ramaze/dependencies.rb +16 -0
- data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
- data/spec/ramaze/error.rb +64 -0
- data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
- data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
- data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
- data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
- data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
- data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
- data/spec/ramaze/helper/file.rb +17 -0
- data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
- data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
- data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
- data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
- data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
- data/spec/ramaze/inform/informer.rb +40 -0
- data/spec/ramaze/inform/syslog.rb +10 -0
- data/spec/ramaze/localize.rb +40 -0
- data/spec/ramaze/morpher.rb +82 -0
- data/spec/ramaze/params.rb +124 -0
- data/spec/{public → ramaze/public}/error404.xhtml +0 -0
- data/spec/{public → ramaze/public}/favicon.ico +0 -0
- data/spec/{public → ramaze/public}/ramaze.png +0 -0
- data/spec/{public → ramaze/public}/test_download.css +0 -0
- data/spec/ramaze/request.rb +129 -0
- data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
- data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
- data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
- data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
- data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
- data/spec/ramaze/template.rb +86 -0
- data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
- data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
- data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
- data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
- data/spec/ramaze/template/ezamar.rb +62 -0
- data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
- data/spec/ramaze/template/ezamar/nested.zmr +1 -0
- data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
- data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
- data/spec/{template → ramaze/template}/haml/index.haml +0 -0
- data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
- data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
- data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
- data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
- data/spec/ramaze/template/markaby.rb +59 -0
- data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
- data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
- data/spec/ramaze/template/ramaze/external.test +1 -0
- data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
- metadata +145 -81
- data/examples/blog/public/screen.css +0 -106
- data/examples/blog/src/element.rb +0 -58
- data/examples/blog/template/view.xhtml +0 -15
- data/examples/blog/test/tc_entry.rb +0 -18
- data/lib/proto/public/404.jpg +0 -0
- data/spec/request_tc_helper.rb +0 -135
- data/spec/spec_all.rb +0 -118
- data/spec/spec_helper.rb +0 -66
- data/spec/tc_controller.rb +0 -49
- data/spec/tc_dependencies.rb +0 -13
- data/spec/tc_error.rb +0 -43
- data/spec/tc_morpher.rb +0 -88
- data/spec/tc_params.rb +0 -125
- data/spec/tc_template_ezamar.rb +0 -64
- data/spec/tc_template_markaby.rb +0 -72
- data/spec/template/ezamar/nested.zmr +0 -1
data/lib/ramaze/helper/aspect.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Ramaze
|
|
|
20
20
|
def self.included(klass)
|
|
21
21
|
# if we haven't been included yet...
|
|
22
22
|
unless defined?(Traits[klass][:aspects]) and Traits[klass][:aspects]
|
|
23
|
-
|
|
23
|
+
klass.trait :aspects => {:pre => {}, :post => {}, :wrap => {}}
|
|
24
24
|
unless defined?(klass.old_render)
|
|
25
25
|
klass.class_eval do
|
|
26
26
|
class << self
|
|
@@ -188,21 +188,23 @@ module Ramaze
|
|
|
188
188
|
# it just searches for post and pre wrappers, calls them
|
|
189
189
|
# before/after your action and joins the results
|
|
190
190
|
|
|
191
|
-
def new_render(action
|
|
191
|
+
def new_render(action)
|
|
192
192
|
arity_for = lambda{|meth| method(meth).arity rescue -1 }
|
|
193
|
-
post, pre = resolve_aspect(action).values_at(:post, :pre)
|
|
193
|
+
post, pre = resolve_aspect(action.method).values_at(:post, :pre)
|
|
194
194
|
|
|
195
195
|
if pre
|
|
196
196
|
arity = arity_for[pre].abs
|
|
197
|
-
|
|
197
|
+
pre_action = resolve_action(pre, *action.params[0,arity])
|
|
198
|
+
pre_content = old_render(pre_action)
|
|
198
199
|
end
|
|
199
200
|
|
|
200
201
|
unless (pre_content.delete(:skip_next_aspects) rescue false)
|
|
201
|
-
content = old_render(action
|
|
202
|
+
content = old_render(action)
|
|
202
203
|
|
|
203
204
|
if post
|
|
204
205
|
arity = arity_for[post].abs
|
|
205
|
-
|
|
206
|
+
post_action = resolve_action(post, *action.params[0,arity])
|
|
207
|
+
post_content = old_render(post_action)
|
|
206
208
|
end
|
|
207
209
|
end
|
|
208
210
|
|
data/lib/ramaze/helper/auth.rb
CHANGED
|
@@ -60,14 +60,14 @@ module Ramaze
|
|
|
60
60
|
redirect_referer
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
private
|
|
64
|
-
|
|
65
63
|
# call( R(self, :login) ) if not logged in
|
|
66
64
|
|
|
67
65
|
def login_required
|
|
68
|
-
call(
|
|
66
|
+
call(Rs(:login)) unless logged_in?
|
|
69
67
|
end
|
|
70
68
|
|
|
69
|
+
private
|
|
70
|
+
|
|
71
71
|
# checks if the user is already logged in.
|
|
72
72
|
# session[:logged_in] is not nil/false
|
|
73
73
|
|
data/lib/ramaze/helper/cache.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Ramaze
|
|
|
10
10
|
|
|
11
11
|
# Cache for values returned from actions
|
|
12
12
|
|
|
13
|
-
trait :action_cache =>
|
|
13
|
+
trait :action_cache => Controller.trait[:action_cache]
|
|
14
14
|
|
|
15
15
|
private
|
|
16
16
|
|
|
@@ -38,7 +38,7 @@ module Ramaze
|
|
|
38
38
|
# action_cache.delete_if{|key, value| key =~ /"index",/}
|
|
39
39
|
|
|
40
40
|
def action_cache
|
|
41
|
-
|
|
41
|
+
Controller.trait[:action_cache]
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# This refers to the class-trait of cached actions, you can
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
module FileHelper
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def send_file(file, mime_type = Tool::MIME.type_for(file))
|
|
9
|
+
response.header["Content-Type"] = mime_type
|
|
10
|
+
response.body = File.open(file)
|
|
11
|
+
throw(:respond)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
module InformHelper
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
# The various (default) tags you can use are:
|
|
10
|
+
#
|
|
11
|
+
# :info - just outputs whatever you give to it without modification.
|
|
12
|
+
# :debug - applies #inspect to everything you pass
|
|
13
|
+
# :error - can take normal strings or exception-objects
|
|
14
|
+
#
|
|
15
|
+
#
|
|
16
|
+
# Usage:
|
|
17
|
+
#
|
|
18
|
+
# inform :info, 'proceeding as planned'
|
|
19
|
+
# # [2007-04-04 23:38:39] INFO proceeding as planned
|
|
20
|
+
#
|
|
21
|
+
# inform :debug, [1,2,3]
|
|
22
|
+
# # [2007-04-04 23:38:39] DEBUG [1, 2, 3]
|
|
23
|
+
#
|
|
24
|
+
# inform :error, 'something bad happened'
|
|
25
|
+
# # [2007-04-04 23:38:39] ERROR something bad happened
|
|
26
|
+
#
|
|
27
|
+
# inform :error, exception
|
|
28
|
+
# # [2007-04-04 23:40:59] ERROR #<RuntimeError: Some exception>
|
|
29
|
+
# # [2007-04-04 23:40:59] ERROR hello.rb:23:in `index'
|
|
30
|
+
# # ... rest of backtrace ...
|
|
31
|
+
|
|
32
|
+
def inform tag, *args
|
|
33
|
+
Inform.send(tag, *args)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/ramaze/helper/link.rb
CHANGED
|
@@ -32,6 +32,8 @@ module Ramaze
|
|
|
32
32
|
|
|
33
33
|
module LinkHelper
|
|
34
34
|
|
|
35
|
+
private
|
|
36
|
+
|
|
35
37
|
# Usage:
|
|
36
38
|
# link MainController, :foo #=> '<a href="/foo">foo</a>'
|
|
37
39
|
# link MinorController, :foo #=> '<a href="/minor/foo">foo</a>'
|
|
@@ -40,7 +42,7 @@ module Ramaze
|
|
|
40
42
|
# link MainController, :foo, :title => 'a' #=> '<a href="/minor/foo/bar">a</a>'
|
|
41
43
|
# link MainController, :foo => :bar #=> '/?foo=bar'
|
|
42
44
|
|
|
43
|
-
def
|
|
45
|
+
def Rlink *to
|
|
44
46
|
hash = to.last.is_a?(Hash) ? to.pop : {}
|
|
45
47
|
|
|
46
48
|
to = to.flatten
|
|
@@ -64,6 +66,8 @@ module Ramaze
|
|
|
64
66
|
end
|
|
65
67
|
end
|
|
66
68
|
|
|
69
|
+
alias link Rlink
|
|
70
|
+
|
|
67
71
|
# Usage:
|
|
68
72
|
# R MainController, :foo #=> '/foo'
|
|
69
73
|
# R MinorController, :foo #=> '/minor/foo'
|
|
@@ -76,11 +80,11 @@ module Ramaze
|
|
|
76
80
|
to << {:raw => true}
|
|
77
81
|
end
|
|
78
82
|
|
|
79
|
-
|
|
83
|
+
Rlink(*to)
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
def Rs(*to)
|
|
83
|
-
R(
|
|
87
|
+
R(Controller.current, *to)
|
|
84
88
|
end
|
|
85
89
|
end
|
|
86
90
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
module MarkabyHelper
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
# use this inside your controller to directly build Markaby
|
|
9
|
+
# Refer to the Markaby-documentation and testsuite for more examples.
|
|
10
|
+
# Usage:
|
|
11
|
+
# mab { h1 "Apples & Oranges"} #=> "<h1>Apples & Oranges</h1>"
|
|
12
|
+
# mab { h1 'Apples', :class => 'fruits&floots' } #=> "<h1 class=\"fruits&floots\">Apples</h1>"
|
|
13
|
+
|
|
14
|
+
def markaby(ivs = {}, helpers = nil, &block)
|
|
15
|
+
builder = ::Markaby::Builder
|
|
16
|
+
builder.extend(Ramaze::Helper)
|
|
17
|
+
builder.send(:helper, :link)
|
|
18
|
+
|
|
19
|
+
iv_hash = {}
|
|
20
|
+
instance_variables.each do |iv|
|
|
21
|
+
key, value = iv.gsub('@', '').to_sym, instance_variable_get(iv)
|
|
22
|
+
iv_hash[key] = value
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
builder.new(iv_hash.merge(ivs), helpers, &block).to_s
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
alias mab markaby
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/ramaze/inform.rb
CHANGED
|
@@ -1,187 +1,13 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
# The module Inform is mainly used for Debugging and Logging.
|
|
7
|
-
#
|
|
8
|
-
# You can include/extend your objects with it and access its methods.
|
|
9
|
-
# Please note that all methods are private, so you should use them only
|
|
10
|
-
# within your object. The reasoning for making them private is simply
|
|
11
|
-
# to avoid interference inside the controller.
|
|
12
|
-
#
|
|
13
|
-
# In case you want to use it from the outside you can work over the
|
|
14
|
-
# Informer object. This is used for example as the Logger for WEBrick.
|
|
15
|
-
#
|
|
16
|
-
# Inform is a tag-based system, Global.inform_tags holds the tags
|
|
17
|
-
# that are used to filter the messages passed to Inform. The default
|
|
18
|
-
# is to use all tags :debug, :info and :error.
|
|
19
|
-
#
|
|
20
|
-
# You can control what gets logged over this Set.
|
|
21
|
-
|
|
22
|
-
module Inform
|
|
23
|
-
# the possible tags
|
|
24
|
-
trait :tags => [:debug, :info, :error]
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
# general debugging information, this yields quite verbose information
|
|
29
|
-
# about how requests make their way through Ramaze.
|
|
30
|
-
#
|
|
31
|
-
# Use it for your own debugging purposes.
|
|
32
|
-
# All messages you pass to it are going to be inspected.
|
|
33
|
-
# it is aliased to #D for convenience.
|
|
34
|
-
|
|
35
|
-
def debug *messages
|
|
36
|
-
return unless inform_tag?(:debug)
|
|
37
|
-
log(Global.inform_prefix_debug, *messages.map{|m| m.inspect})
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
alias D debug
|
|
41
|
-
|
|
42
|
-
def debug?() inform_tag?(:debug) end
|
|
43
|
-
|
|
44
|
-
# A little but powerful method to debug calls to methods.
|
|
45
|
-
#
|
|
46
|
-
# def foo(*args)
|
|
47
|
-
# meth_debug(:foo, args)
|
|
48
|
-
# end
|
|
49
|
-
#
|
|
50
|
-
# foo :bar
|
|
51
|
-
#
|
|
52
|
-
# Will give you
|
|
53
|
-
#
|
|
54
|
-
# [2007-01-26 22:17:24] DEBUG foo([:bar])
|
|
55
|
-
#
|
|
56
|
-
# It will also run inspect on all parameters you pass to it (only the
|
|
57
|
-
# method-name is processed with to_s)
|
|
58
|
-
#
|
|
59
|
-
# It is aliased to #mD
|
|
60
|
-
|
|
61
|
-
def meth_debug meth, *params
|
|
62
|
-
return unless inform_tag?(:debug)
|
|
63
|
-
log(Global.inform_prefix_debug, "#{meth}(#{params.map{|pa| pa.inspect}.join(', ')})")
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
alias mD meth_debug
|
|
67
|
-
|
|
68
|
-
# General information about startup, requests and other things.
|
|
69
|
-
#
|
|
70
|
-
# Use of this method is mainly for things that are not overly verbose
|
|
71
|
-
# but give you a general overview about what's happening.
|
|
72
|
-
|
|
73
|
-
def info message
|
|
74
|
-
return unless inform_tag?(:info)
|
|
75
|
-
log(Global.inform_prefix_info, message)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def info?() inform_tag?(:info) end
|
|
79
|
-
|
|
80
|
-
# Informing yourself about errors, you can pass it instances of Error
|
|
81
|
-
# but also simple Strings.
|
|
82
|
-
# (all that responds to :message/:backtrace or to_s)
|
|
83
|
-
#
|
|
84
|
-
# It will nicely truncate the backtrace to:
|
|
85
|
-
# Global.inform_backtrace_size
|
|
86
|
-
# It will not differentiate its behaviour based on other tags, as
|
|
87
|
-
# having a full backtrace is the most valuable thing to fixing the issue.
|
|
88
|
-
#
|
|
89
|
-
# However, you can set a different behaviour by adding/removing tags from:
|
|
90
|
-
# Global.inform_backtrace_for
|
|
91
|
-
# By default it just points to Global.inform_tags
|
|
92
|
-
|
|
93
|
-
def error *messages
|
|
94
|
-
return unless inform_tag?(:error)
|
|
95
|
-
prefix = Global.inform_prefix_error
|
|
96
|
-
messages.each do |e|
|
|
97
|
-
if e.respond_to?(:message) and e.respond_to?(:backtrace)
|
|
98
|
-
log prefix, e.message
|
|
99
|
-
if (Global.inform_backtrace_for || Global.inform_tags).any?{|t| inform_tag?(t)}
|
|
100
|
-
e.backtrace[0..10].each do |bt|
|
|
101
|
-
log prefix, bt
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
else
|
|
105
|
-
log prefix, e
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def error?() inform_tag?(:error) end
|
|
111
|
-
|
|
112
|
-
# This uses Global.inform_timestamp or a date in the format of
|
|
113
|
-
# %Y-%m-%d %H:%M:%S
|
|
114
|
-
# # => "2007-01-19 21:09:32"
|
|
4
|
+
require 'ramaze/inform/informing'
|
|
115
5
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def inform_tag?(inform_tag)
|
|
124
|
-
Global.inform_tags.include?(inform_tag)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# the common logging-method, you shouldn't have to call this yourself
|
|
128
|
-
# it takes the prefix and any number of messages.
|
|
129
|
-
#
|
|
130
|
-
# The produced inform-message consists of
|
|
131
|
-
# [timestamp] prefix message
|
|
132
|
-
# For the output is anything used that responds to :puts, the default
|
|
133
|
-
# is $stdout in:
|
|
134
|
-
# Global.inform_to
|
|
135
|
-
# where you can configure it.
|
|
136
|
-
#
|
|
137
|
-
# To log to a file just do
|
|
138
|
-
# Global.inform_to = File.open('log.txt', 'a+')
|
|
139
|
-
|
|
140
|
-
def log prefix, *messages
|
|
141
|
-
[messages].flatten.each do |message|
|
|
142
|
-
compiled = %{[#{timestamp}] #{prefix} #{message}}
|
|
143
|
-
|
|
144
|
-
pipes = Global.inform_pipes = pipify(Global.inform_to)
|
|
145
|
-
|
|
146
|
-
pipes.each do |pipe|
|
|
147
|
-
pipe.puts(*compiled) unless (pipe.respond_to?(:closed?) and pipe.closed?)
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def pipify *ios
|
|
153
|
-
ios.flatten.map do |io|
|
|
154
|
-
case io
|
|
155
|
-
when :stdout, 'stdout' : $stdout
|
|
156
|
-
when :stderr, 'stderr' : $stderr
|
|
157
|
-
when IO : io
|
|
158
|
-
else
|
|
159
|
-
File.open(io.to_s, 'ab+')
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
extend self
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
# This class acts as a object you can pass to any other logger, it's basically
|
|
168
|
-
# just including Inform and making its methods public
|
|
169
|
-
|
|
170
|
-
class GlobalInformer
|
|
171
|
-
include Inform
|
|
172
|
-
|
|
173
|
-
public :error, :error?, :info, :info?, :meth_debug, :debug, :debug?
|
|
174
|
-
|
|
175
|
-
# this simply sends the parameters to #debug
|
|
176
|
-
|
|
177
|
-
def <<(*str)
|
|
178
|
-
debug(*str)
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# The usual instance of GlobalInformer, for example used for WEBrick
|
|
183
|
-
|
|
184
|
-
Informer = GlobalInformer.new
|
|
185
|
-
|
|
186
|
-
include Inform
|
|
6
|
+
module Ramaze
|
|
7
|
+
autoload :Analogger, "ramaze/inform/analogger.rb"
|
|
8
|
+
autoload :Informer, "ramaze/inform/informer.rb"
|
|
9
|
+
autoload :Syslog, "ramaze/inform/syslog.rb"
|
|
10
|
+
autoload :Growl, "ramaze/inform/growl.rb"
|
|
11
|
+
autoload :Xosd, "ramaze/inform/xosd.rb"
|
|
12
|
+
autoload :LogHub, "ramaze/inform/hub.rb"
|
|
187
13
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'swiftcore/Analogger/Client'
|
|
5
|
+
|
|
6
|
+
module Ramaze
|
|
7
|
+
|
|
8
|
+
class Analogger < ::Swiftcore::Analogger::Client
|
|
9
|
+
include Informing
|
|
10
|
+
|
|
11
|
+
def initialize(name = 'walrus', host = '127.0.0.1', port = 6766)
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def inform(tag, *args)
|
|
16
|
+
log(tag, args.join("\n"))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'ruby-growl'
|
|
5
|
+
|
|
6
|
+
module Ramaze
|
|
7
|
+
class Growl < ::Growl
|
|
8
|
+
|
|
9
|
+
trait :defaults => {
|
|
10
|
+
:name => 'walrus',
|
|
11
|
+
:host => 'localhost',
|
|
12
|
+
:password => 'walrus',
|
|
13
|
+
:all_notifies => %w[error warn debug info],
|
|
14
|
+
:default_notifies => %w[error warn info]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def initialize(options = {})
|
|
18
|
+
options = class_trait[:defaults].merge(options).values_at(:host, :name, :all_notifies, :default_notifies, :password)
|
|
19
|
+
super(*options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def inform(tag, *args)
|
|
23
|
+
notify(tag.to_s, Time.now.strftime("%X"), args.join("\n")[0..100])
|
|
24
|
+
rescue Errno::EMSGSIZE
|
|
25
|
+
# Send size was to big (not really), ignore
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|