ramaze 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. data/Rakefile +360 -0
  2. data/bin/ramaze +152 -0
  3. data/doc/CHANGELOG +2021 -0
  4. data/doc/COPYING +56 -0
  5. data/doc/COPYING.ja +51 -0
  6. data/doc/README +275 -0
  7. data/doc/TODO +33 -0
  8. data/doc/allison/LICENSE +184 -0
  9. data/doc/allison/README +37 -0
  10. data/doc/allison/allison.css +300 -0
  11. data/doc/allison/allison.gif +0 -0
  12. data/doc/allison/allison.js +307 -0
  13. data/doc/allison/allison.rb +287 -0
  14. data/doc/allison/cache/BODY +588 -0
  15. data/doc/allison/cache/CLASS_INDEX +4 -0
  16. data/doc/allison/cache/CLASS_PAGE +1 -0
  17. data/doc/allison/cache/FILE_INDEX +4 -0
  18. data/doc/allison/cache/FILE_PAGE +1 -0
  19. data/doc/allison/cache/FONTS +1 -0
  20. data/doc/allison/cache/FR_INDEX_BODY +1 -0
  21. data/doc/allison/cache/IMGPATH +1 -0
  22. data/doc/allison/cache/INDEX +1 -0
  23. data/doc/allison/cache/JAVASCRIPT +307 -0
  24. data/doc/allison/cache/METHOD_INDEX +4 -0
  25. data/doc/allison/cache/METHOD_LIST +1 -0
  26. data/doc/allison/cache/SRC_PAGE +1 -0
  27. data/doc/allison/cache/STYLE +322 -0
  28. data/doc/allison/cache/URL +1 -0
  29. data/examples/blog/main.rb +16 -0
  30. data/examples/blog/public/screen.css +106 -0
  31. data/examples/blog/src/controller.rb +50 -0
  32. data/examples/blog/src/element.rb +53 -0
  33. data/examples/blog/src/model.rb +29 -0
  34. data/examples/blog/template/edit.xhtml +6 -0
  35. data/examples/blog/template/index.xhtml +24 -0
  36. data/examples/blog/template/new.xhtml +5 -0
  37. data/examples/blog/template/view.xhtml +15 -0
  38. data/examples/blog/test/tc_entry.rb +18 -0
  39. data/examples/caching.rb +23 -0
  40. data/examples/element.rb +40 -0
  41. data/examples/hello.rb +23 -0
  42. data/examples/simple.rb +60 -0
  43. data/examples/templates/template/external.haml +21 -0
  44. data/examples/templates/template/external.liquid +28 -0
  45. data/examples/templates/template/external.mab +27 -0
  46. data/examples/templates/template/external.rhtml +29 -0
  47. data/examples/templates/template/external.rmze +24 -0
  48. data/examples/templates/template_erubis.rb +50 -0
  49. data/examples/templates/template_haml.rb +48 -0
  50. data/examples/templates/template_liquid.rb +64 -0
  51. data/examples/templates/template_markaby.rb +52 -0
  52. data/examples/templates/template_ramaze.rb +49 -0
  53. data/examples/whywiki/main.rb +56 -0
  54. data/examples/whywiki/template/edit.xhtml +14 -0
  55. data/examples/whywiki/template/show.xhtml +17 -0
  56. data/lib/proto/conf/benchmark.yaml +35 -0
  57. data/lib/proto/conf/debug.yaml +34 -0
  58. data/lib/proto/conf/live.yaml +33 -0
  59. data/lib/proto/conf/silent.yaml +31 -0
  60. data/lib/proto/conf/stage.yaml +33 -0
  61. data/lib/proto/main.rb +18 -0
  62. data/lib/proto/public/404.jpg +0 -0
  63. data/lib/proto/public/css/coderay.css +105 -0
  64. data/lib/proto/public/css/ramaze_error.css +42 -0
  65. data/lib/proto/public/error.xhtml +74 -0
  66. data/lib/proto/public/favicon.ico +0 -0
  67. data/lib/proto/public/js/jquery.js +1923 -0
  68. data/lib/proto/public/ramaze.png +0 -0
  69. data/lib/proto/src/controller/main.rb +7 -0
  70. data/lib/proto/src/element/page.rb +16 -0
  71. data/lib/proto/src/model.rb +5 -0
  72. data/lib/proto/template/index.xhtml +6 -0
  73. data/lib/ramaze.rb +317 -0
  74. data/lib/ramaze/adapter/mongrel.rb +111 -0
  75. data/lib/ramaze/adapter/webrick.rb +161 -0
  76. data/lib/ramaze/cache.rb +11 -0
  77. data/lib/ramaze/cache/memcached.rb +52 -0
  78. data/lib/ramaze/cache/memory.rb +6 -0
  79. data/lib/ramaze/cache/yaml_store.rb +37 -0
  80. data/lib/ramaze/controller.rb +10 -0
  81. data/lib/ramaze/dispatcher.rb +315 -0
  82. data/lib/ramaze/error.rb +11 -0
  83. data/lib/ramaze/gestalt.rb +108 -0
  84. data/lib/ramaze/global.rb +120 -0
  85. data/lib/ramaze/helper.rb +32 -0
  86. data/lib/ramaze/helper/aspect.rb +189 -0
  87. data/lib/ramaze/helper/auth.rb +120 -0
  88. data/lib/ramaze/helper/cache.rb +52 -0
  89. data/lib/ramaze/helper/feed.rb +135 -0
  90. data/lib/ramaze/helper/form.rb +204 -0
  91. data/lib/ramaze/helper/link.rb +80 -0
  92. data/lib/ramaze/helper/redirect.rb +48 -0
  93. data/lib/ramaze/helper/stack.rb +67 -0
  94. data/lib/ramaze/http_status.rb +66 -0
  95. data/lib/ramaze/inform.rb +166 -0
  96. data/lib/ramaze/snippets.rb +5 -0
  97. data/lib/ramaze/snippets/hash/keys_to_sym.rb +19 -0
  98. data/lib/ramaze/snippets/kernel/aquire.rb +22 -0
  99. data/lib/ramaze/snippets/kernel/autoreload.rb +79 -0
  100. data/lib/ramaze/snippets/kernel/caller_lines.rb +58 -0
  101. data/lib/ramaze/snippets/kernel/constant.rb +24 -0
  102. data/lib/ramaze/snippets/kernel/rescue_require.rb +12 -0
  103. data/lib/ramaze/snippets/kernel/self_method.rb +41 -0
  104. data/lib/ramaze/snippets/kernel/silently.rb +13 -0
  105. data/lib/ramaze/snippets/object/traits.rb +60 -0
  106. data/lib/ramaze/snippets/openstruct/temp.rb +10 -0
  107. data/lib/ramaze/snippets/string/DIVIDE.rb +16 -0
  108. data/lib/ramaze/snippets/string/camel_case.rb +14 -0
  109. data/lib/ramaze/snippets/string/snake_case.rb +12 -0
  110. data/lib/ramaze/snippets/symbol/to_proc.rb +14 -0
  111. data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +11 -0
  112. data/lib/ramaze/store/default.rb +48 -0
  113. data/lib/ramaze/template.rb +102 -0
  114. data/lib/ramaze/template/amrita2.rb +40 -0
  115. data/lib/ramaze/template/erubis.rb +58 -0
  116. data/lib/ramaze/template/haml.rb +65 -0
  117. data/lib/ramaze/template/haml/actionview_stub.rb +20 -0
  118. data/lib/ramaze/template/liquid.rb +74 -0
  119. data/lib/ramaze/template/markaby.rb +68 -0
  120. data/lib/ramaze/template/ramaze.rb +177 -0
  121. data/lib/ramaze/template/ramaze/element.rb +166 -0
  122. data/lib/ramaze/template/ramaze/morpher.rb +156 -0
  123. data/lib/ramaze/tool/create.rb +70 -0
  124. data/lib/ramaze/tool/tidy.rb +71 -0
  125. data/lib/ramaze/trinity.rb +38 -0
  126. data/lib/ramaze/trinity/request.rb +244 -0
  127. data/lib/ramaze/trinity/response.rb +41 -0
  128. data/lib/ramaze/trinity/session.rb +129 -0
  129. data/lib/ramaze/version.rb +14 -0
  130. data/spec/spec_all.rb +73 -0
  131. data/spec/spec_helper.rb +215 -0
  132. data/spec/tc_adapter_mongrel.rb +24 -0
  133. data/spec/tc_adapter_webrick.rb +22 -0
  134. data/spec/tc_cache.rb +79 -0
  135. data/spec/tc_controller.rb +39 -0
  136. data/spec/tc_element.rb +100 -0
  137. data/spec/tc_error.rb +23 -0
  138. data/spec/tc_gestalt.rb +90 -0
  139. data/spec/tc_global.rb +46 -0
  140. data/spec/tc_helper_aspect.rb +65 -0
  141. data/spec/tc_helper_auth.rb +61 -0
  142. data/spec/tc_helper_cache.rb +81 -0
  143. data/spec/tc_helper_feed.rb +129 -0
  144. data/spec/tc_helper_form.rb +146 -0
  145. data/spec/tc_helper_link.rb +58 -0
  146. data/spec/tc_helper_redirect.rb +51 -0
  147. data/spec/tc_helper_stack.rb +55 -0
  148. data/spec/tc_morpher.rb +90 -0
  149. data/spec/tc_params.rb +84 -0
  150. data/spec/tc_request.rb +111 -0
  151. data/spec/tc_session.rb +56 -0
  152. data/spec/tc_store.rb +25 -0
  153. data/spec/tc_template_amrita2.rb +34 -0
  154. data/spec/tc_template_erubis.rb +41 -0
  155. data/spec/tc_template_haml.rb +44 -0
  156. data/spec/tc_template_liquid.rb +98 -0
  157. data/spec/tc_template_markaby.rb +74 -0
  158. data/spec/tc_template_ramaze.rb +54 -0
  159. data/spec/tc_tidy.rb +14 -0
  160. data/spec/template/amrita2/data.html +6 -0
  161. data/spec/template/amrita2/index.html +1 -0
  162. data/spec/template/amrita2/sum.html +1 -0
  163. data/spec/template/erubis/sum.rhtml +1 -0
  164. data/spec/template/haml/index.haml +5 -0
  165. data/spec/template/haml/with_vars.haml +4 -0
  166. data/spec/template/liquid/index.liquid +1 -0
  167. data/spec/template/liquid/products.liquid +45 -0
  168. data/spec/template/markaby/external.mab +8 -0
  169. data/spec/template/markaby/sum.mab +1 -0
  170. data/spec/template/ramaze/file_only.rmze +1 -0
  171. data/spec/template/ramaze/index.rmze +1 -0
  172. data/spec/template/ramaze/nested.rmze +1 -0
  173. data/spec/template/ramaze/sum.rmze +1 -0
  174. metadata +317 -0
@@ -0,0 +1,80 @@
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
+ # LinkHelper is included into the Template::Ramaze by default
6
+ #
7
+ # this helper tries to get along without any major magic, the only 'magic'
8
+ # thing is that it looks up controller-paths if you pass it a controller
9
+ # the text shown is always the last segmet of the finished link from split('/')
10
+ #
11
+ # usage is pretty much shown in test/tc_helper
12
+ # however, to give you some idea of how it actually works, some examples:
13
+ #
14
+ # link MainController, :foo #=> '<a href="/foo">foo</a>'
15
+ # link MinorController, :foo #=> '<a href="/minor/foo">foo</a>'
16
+ # link MinorController, :foo, :bar #=> '<a href="/minor/foo/bar">bar</a>'
17
+ # link MainController, :foo, :raw => true #=> '/foo'
18
+ # link MainController, :foo => :bar #=> '/?foo=bar'
19
+ #
20
+ # link_raw MainController, :foo #=> '/foo'
21
+ # link_raw MinorController, :foo #=> '/minor/foo'
22
+ # link_raw MinorController, :foo, :bar #=> '/minor/foo/bar'
23
+ #
24
+ # TODO:
25
+ # - handling of no passed parameters
26
+ # - setting imagelinks
27
+ # - setting of id or class
28
+ # - taking advantae of Gestalt to build links
29
+ # - lots of other minor niceties, for the moment i'm only concerned to keep
30
+ # it as simple as possible
31
+ #
32
+
33
+ module LinkHelper
34
+
35
+ # Usage:
36
+ # link MainController, :foo #=> '<a href="/foo">foo</a>'
37
+ # link MinorController, :foo #=> '<a href="/minor/foo">foo</a>'
38
+ # link MinorController, :foo, :bar #=> '<a href="/minor/foo/bar">bar</a>'
39
+ # link MainController, :foo, :raw => true #=> '/foo'
40
+ # link MainController, :foo, :title => 'a' #=> '<a href="/minor/foo/bar">a</a>'
41
+ # link MainController, :foo => :bar #=> '/?foo=bar'
42
+
43
+ def link *to
44
+ hash = to.last.is_a?(Hash) ? to.pop : {}
45
+
46
+ to = to.flatten
47
+
48
+ to.map! do |t|
49
+ t = t.class if not t.respond_to?(:transform) and t.is_a?(Controller)
50
+ Global.mapping.invert[t] || t
51
+ end
52
+
53
+ raw, title = hash.delete(:raw), hash.delete(:title)
54
+ opts = hash.inject('?'){|s,(k,v)| s << "#{k}=#{v};"}[0..-2]
55
+ link = to.join('/').squeeze('/') << (opts.empty? ? '' : opts)
56
+
57
+ if raw
58
+ link
59
+ else
60
+ title ||= link.split('/').last.to_s.split('?').first || 'index'
61
+ %{<a href="#{link}">#{title}</a>}
62
+ end
63
+ end
64
+
65
+ # Usage:
66
+ # R MainController, :foo #=> '/foo'
67
+ # R MinorController, :foo #=> '/minor/foo'
68
+ # R MinorController, :foo, :bar #=> '/minor/foo/bar'
69
+
70
+ def R *to
71
+ if to.last.is_a?(Hash)
72
+ to.last[:raw] = true
73
+ else
74
+ to << {:raw => true}
75
+ end
76
+
77
+ link(*to)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,48 @@
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
+
6
+ # RedirectHelper actually takes advantage of LinkHelper.link_raw to build the links
7
+ # it redirects to.
8
+ # It doesn't do much else than this:
9
+ # setting a status-code of 303 and a head['Location'] = link
10
+ # returning some nice text for visitors who insist on ignoring those hints :P
11
+ #
12
+ # example of usage:
13
+ # redirect MainController
14
+ # redirect MainController, :foo
15
+ # redirect 'foo/bar'
16
+ #
17
+ # TODO:
18
+ # - setting custom status-code, it ignores any preset ones at the moment
19
+ # - maybe some more options, like a delay
20
+ #
21
+
22
+ module RedirectHelper
23
+
24
+ # Usage:
25
+ # redirect MainController
26
+ # redirect MainController, :foo
27
+ # redirect 'foo/bar'
28
+
29
+ def redirect *target
30
+ target = target.join('/')
31
+
32
+ response.head['Location'] = target
33
+
34
+ hash = target.find{|h| h.is_a?(Hash)} and status = hash.delete(:status) rescue nil
35
+
36
+ response.code = status || STATUS_CODE[:see_other]
37
+ response.out = %{Please follow <a href="#{target}">#{target}</a>!}
38
+
39
+ throw :respond
40
+ end
41
+
42
+ # redirect to the location the browser says it's coming from.
43
+
44
+ def redirect_referer
45
+ redirect request.referer
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,67 @@
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
+
6
+ # provides an call/answer mechanism, this is useful for example in a
7
+ # login-system.
8
+ #
9
+ # It is basically good to redirect temporarly somewhere else without
10
+ # forgetting where you come from and offering a nice way to get back
11
+ # to the last urls.
12
+ #
13
+ # Example:
14
+ #
15
+ # class AuthController < Template::Ramaze
16
+ # helper :stack
17
+ #
18
+ # def login pass
19
+ # if pass == 'password'
20
+ # session[:logged_in] = true
21
+ # answer if inside_stack?
22
+ # redirect '/'
23
+ # else
24
+ # "failed"
25
+ # end
26
+ # end
27
+ #
28
+ # def logged_in?
29
+ # !!session[:logged_in]
30
+ # end
31
+ # end
32
+ #
33
+ # class ImportantController < Template::Ramaze
34
+ # helper :stack
35
+ #
36
+ # def secret_information
37
+ # call :login unless logged_in?
38
+ # "Agent X is assinged to fight the RubyNinjas"
39
+ # end
40
+ # end
41
+
42
+ module StackHelper
43
+ private
44
+
45
+ # redirect to another location and pushing the current location
46
+ # on the session[:STACK]
47
+
48
+ def call this
49
+ (session[:STACK] ||= []) << request.request_uri
50
+ redirect(this)
51
+ end
52
+
53
+ # return to the last location on session[:STACK]
54
+
55
+ def answer
56
+ redirect session[:STACK].pop if inside_stack?
57
+ end
58
+
59
+ # check if the stack has something inside.
60
+
61
+ def inside_stack?
62
+ not session[:STACK].empty?
63
+ rescue
64
+ false
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,66 @@
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
+ STATUS_CODE = {
6
+ # 1xx Informational (Request received, continuing process.)
7
+
8
+ :continue => 100,
9
+ :switching_protocols => 101,
10
+
11
+ # 2xx Success (The action was successfully received, understood, and accepted.)
12
+
13
+ :ok => 200,
14
+ :created => 201,
15
+ :accepted => 202,
16
+ :non_authorative_information => 203,
17
+ :no_content => 204,
18
+ :resent_content => 205,
19
+ :partial_content => 206,
20
+ :multi_status => 207,
21
+
22
+ # 3xx Redirection (The client must take additional action to complete the request.)
23
+
24
+ :multiple_choices => 300,
25
+ :moved_permamently => 301,
26
+ :moved_temporarily => 302,
27
+ :found => 302,
28
+ :see_other => 303,
29
+ :not_modified => 304,
30
+ :use_proxy => 305,
31
+ :switch_proxy => 306,
32
+ :temporary_redirect => 307,
33
+
34
+ # 4xx Client Error (The request contains bad syntax or cannot be fulfilled.)
35
+
36
+ :bad_request => 400,
37
+ :unauthorized => 401,
38
+ :payment_required => 402,
39
+ :forbidden => 403,
40
+ :not_found => 404,
41
+ :method_not_allowed => 405,
42
+ :not_aceptable => 406,
43
+ :proxy_authentication_required => 407,
44
+ :request_timeout => 408,
45
+ :conflict => 409,
46
+ :gone => 410,
47
+ :length_required => 411,
48
+ :precondition_failed => 412,
49
+ :request_entity_too_large => 413,
50
+ :request_uri_too_long => 414,
51
+ :unsupported_media_type => 415,
52
+ :requested_range_not_satisfiable => 416,
53
+ :expectation_failed => 417,
54
+ :retry_with => 449,
55
+
56
+ # 5xx Server Error (The server failed to fulfill an apparently valid request.)
57
+
58
+ :internal_server_error => 500,
59
+ :not_implemented => 501,
60
+ :bad_gateway => 502,
61
+ :service_unavailable => 503,
62
+ :gateway_timeout => 504,
63
+ :http_version_not_supported => 505,
64
+ :bandwidth_limit_exceeded => 509, # (not official)
65
+ }
66
+ end
@@ -0,0 +1,166 @@
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
+
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
+ # A little but powerful method to debug calls to methods.
43
+ #
44
+ # def foo(*args)
45
+ # meth_debug(:foo, args)
46
+ # end
47
+ #
48
+ # foo :bar
49
+ #
50
+ # Will give you
51
+ #
52
+ # [2007-01-26 22:17:24] DEBUG foo([:bar])
53
+ #
54
+ # It will also run inspect on all parameters you pass to it (only the
55
+ # method-name is processed with to_s)
56
+ #
57
+ # It is aliased to #mD
58
+
59
+ def meth_debug meth, *params
60
+ return unless inform_tag?(:debug)
61
+ log(Global.inform_prefix_debug, "#{meth}(#{params.map{|pa| pa.inspect}.join(', ')})")
62
+ end
63
+
64
+ alias mD meth_debug
65
+
66
+ # General information about startup, requests and other things.
67
+ #
68
+ # Use of this method is mainly for things that are not overly verbose
69
+ # but give you a general overview about what's happening.
70
+
71
+ def info message
72
+ return unless inform_tag?(:info)
73
+ log(Global.inform_prefix_info, message)
74
+ end
75
+
76
+ # Informing yourself about errors, you can pass it instances of Error
77
+ # but also simple Strings.
78
+ # (all that responds to :message/:backtrace or to_s)
79
+ #
80
+ # It will nicely truncate the backtrace to:
81
+ # Global.inform_backtrace_size
82
+ # It will not differentiate its behaviour based on other tags, as
83
+ # having a full backtrace is the most valuable thing to fixing the issue.
84
+ #
85
+ # However, you can set a different behaviour by adding/removing tags from:
86
+ # Global.inform_backtrace_for
87
+ # By default it just points to Global.inform_tags
88
+
89
+ def error *messages
90
+ return unless inform_tag?(:error)
91
+ prefix = Global.inform_prefix_error
92
+ messages.each do |e|
93
+ if e.respond_to?(:message) and e.respond_to?(:backtrace)
94
+ log prefix, e.message
95
+ if (Global.inform_backtrace_for || Global.inform_tags).any?{|t| inform_tag?(t)}
96
+ e.backtrace[0..10].each do |bt|
97
+ log prefix, bt
98
+ end
99
+ end
100
+ else
101
+ log prefix, e
102
+ end
103
+ end
104
+ end
105
+
106
+ # This uses Global.inform_timestamp or a date in the format of
107
+ # %Y-%m-%d %H:%M:%S
108
+ # # => "2007-01-19 21:09:32"
109
+
110
+ def timestamp
111
+ mask = Global.inform_timestamp
112
+ Time.now.strftime(mask || "%Y-%m-%d %H:%M:%S")
113
+ end
114
+
115
+ # is the given inform_tag in Global.inform_tags ?
116
+
117
+ def inform_tag?(inform_tag)
118
+ Global.inform_tags.include?(inform_tag)
119
+ end
120
+
121
+ # the common logging-method, you shouldn't have to call this yourself
122
+ # it takes the prefix and any number of messages.
123
+ #
124
+ # The produced inform-message consists of
125
+ # [timestamp] prefix message
126
+ # For the output is anything used that responds to :puts, the default
127
+ # is $stdout in:
128
+ # Global.inform_to
129
+ # where you can configure it.
130
+ #
131
+ # To log to a file just do
132
+ # Global.inform_to = File.open('log.txt', 'a+')
133
+
134
+ def log prefix, *messages
135
+ [messages].flatten.each do |message|
136
+ compiled = %{[#{timestamp}] #{prefix} #{message}}
137
+ out =
138
+ case Global.inform_to
139
+ when $stdout, :stderr, 'stdout' : $stdout
140
+ when $stdout, :stderr, 'stderr' : $stderr
141
+ else
142
+ File.open(Global.inform_to, 'ab+')
143
+ end
144
+ out.puts(*compiled) unless (out.respond_to?(:closed?) and out.closed?)
145
+ end
146
+ end
147
+
148
+ extend self
149
+ end
150
+
151
+ class GlobalInformer
152
+ include Inform
153
+
154
+ public :error, :info, :meth_debug, :debug
155
+
156
+ # this simply sends the parameters to #debug
157
+
158
+ def <<(*str)
159
+ debug(*str)
160
+ end
161
+ end
162
+
163
+ Informer = GlobalInformer.new
164
+
165
+ include Inform
166
+ end
@@ -0,0 +1,5 @@
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 'ramaze/snippets/kernel/aquire'
5
+ aquire 'ramaze/snippets/*'
@@ -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
+ class Hash
5
+
6
+ # convert all keys in the Hash to symbols.
7
+
8
+ def keys_to_sym!
9
+ each do |key, value|
10
+ self[key.to_sym] = delete(key)
11
+ end
12
+ end
13
+
14
+ # answer with a new Hash with all keys as symbols.
15
+
16
+ def keys_to_sym
17
+ dup.keys_to_sym!
18
+ end
19
+ end