ramaze 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/Rakefile +26 -6
  2. data/bin/ramaze +8 -1
  3. data/doc/AUTHORS +13 -11
  4. data/doc/CHANGELOG +472 -13
  5. data/doc/LEGAL +22 -0
  6. data/doc/README +1 -4
  7. data/doc/TODO +7 -2
  8. data/doc/changes.txt +472 -13
  9. data/doc/changes.xml +472 -13
  10. data/doc/meta/announcement.txt +21 -23
  11. data/doc/readme_chunks/appendix.txt +0 -3
  12. data/doc/readme_chunks/features.txt +1 -1
  13. data/examples/auth/auth.rb +49 -0
  14. data/examples/auth/template/layout.haml +20 -0
  15. data/examples/auth/template/login.haml +16 -0
  16. data/examples/blog/spec/blog.rb +1 -0
  17. data/examples/caching.rb +5 -6
  18. data/examples/css.rb +37 -0
  19. data/examples/layout.rb +3 -17
  20. data/examples/simple_auth.rb +23 -0
  21. data/examples/sourceview/public/images/file.gif +0 -0
  22. data/examples/sourceview/public/images/folder.gif +0 -0
  23. data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
  24. data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
  25. data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
  26. data/examples/sourceview/public/images/tv-expandable.gif +0 -0
  27. data/examples/sourceview/public/images/tv-item-last.gif +0 -0
  28. data/examples/sourceview/public/images/tv-item.gif +0 -0
  29. data/examples/sourceview/public/jquery.js +11 -0
  30. data/examples/sourceview/public/jquery.treeview.css +47 -0
  31. data/examples/sourceview/public/jquery.treeview.js +223 -0
  32. data/examples/sourceview/public/sourceview.js +16 -0
  33. data/examples/sourceview/sourceview.rb +74 -0
  34. data/examples/sourceview/template/index.haml +43 -0
  35. data/examples/templates/template/external.nag +28 -0
  36. data/examples/templates/template/external.xsl +57 -0
  37. data/examples/templates/template_amrita2.rb +2 -4
  38. data/examples/templates/template_erubis.rb +1 -1
  39. data/examples/templates/template_haml.rb +1 -1
  40. data/examples/templates/template_liquid.rb +2 -4
  41. data/examples/templates/template_markaby.rb +2 -4
  42. data/examples/templates/template_nagoro.rb +53 -0
  43. data/examples/templates/template_remarkably.rb +2 -4
  44. data/examples/templates/template_xslt.rb +52 -0
  45. data/examples/whywiki/spec/whywiki.rb +63 -0
  46. data/examples/whywiki/start.rb +11 -13
  47. data/examples/whywiki/template/edit.xhtml +3 -3
  48. data/examples/whywiki/template/show.xhtml +5 -8
  49. data/examples/wikore/spec/wikore.rb +115 -0
  50. data/examples/wikore/src/controller.rb +81 -0
  51. data/examples/wikore/src/model.rb +51 -0
  52. data/examples/wikore/start.rb +6 -0
  53. data/examples/wikore/template/index.xhtml +8 -0
  54. data/examples/wiktacular/spec/wiktacular.rb +1 -0
  55. data/examples/wiktacular/src/controller.rb +1 -1
  56. data/lib/ramaze.rb +6 -3
  57. data/lib/ramaze/action.rb +2 -13
  58. data/lib/ramaze/action/render.rb +36 -18
  59. data/lib/ramaze/adapter.rb +1 -1
  60. data/lib/ramaze/adapter/cgi.rb +0 -3
  61. data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
  62. data/lib/ramaze/adapter/mongrel.rb +4 -13
  63. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
  64. data/lib/ramaze/cache.rb +12 -7
  65. data/lib/ramaze/contrib.rb +22 -0
  66. data/lib/ramaze/contrib/auto_params.rb +128 -0
  67. data/lib/ramaze/contrib/auto_params/get_args.rb +56 -0
  68. data/lib/ramaze/contrib/gzip_filter.rb +57 -0
  69. data/lib/ramaze/contrib/route.rb +40 -0
  70. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  71. data/lib/ramaze/controller.rb +17 -6
  72. data/lib/ramaze/controller/resolve.rb +51 -14
  73. data/lib/ramaze/dispatcher.rb +15 -13
  74. data/lib/ramaze/dispatcher/action.rb +4 -3
  75. data/lib/ramaze/dispatcher/directory.rb +3 -3
  76. data/lib/ramaze/dispatcher/error.rb +1 -1
  77. data/lib/ramaze/dispatcher/file.rb +17 -6
  78. data/lib/ramaze/error.rb +3 -0
  79. data/lib/ramaze/gestalt.rb +28 -8
  80. data/lib/ramaze/global.rb +26 -6
  81. data/lib/ramaze/global/globalstruct.rb +31 -6
  82. data/lib/ramaze/helper.rb +2 -1
  83. data/lib/ramaze/helper/aspect.rb +2 -2
  84. data/lib/ramaze/helper/auth.rb +6 -9
  85. data/lib/ramaze/helper/cache.rb +89 -9
  86. data/lib/ramaze/helper/cgi.rb +2 -2
  87. data/lib/ramaze/helper/formatting.rb +44 -0
  88. data/lib/ramaze/helper/link.rb +7 -5
  89. data/lib/ramaze/helper/partial.rb +6 -4
  90. data/lib/ramaze/helper/redirect.rb +24 -9
  91. data/lib/ramaze/helper/stack.rb +6 -1
  92. data/lib/ramaze/inform/growl.rb +1 -1
  93. data/lib/ramaze/inform/informer.rb +2 -1
  94. data/lib/ramaze/inform/informing.rb +6 -0
  95. data/lib/ramaze/inform/syslog.rb +1 -0
  96. data/lib/ramaze/snippets/array/put_within.rb +24 -0
  97. data/lib/ramaze/snippets/dictionary.rb +499 -0
  98. data/lib/ramaze/snippets/numeric/filesize_format.rb +19 -0
  99. data/lib/ramaze/snippets/ordered_set.rb +31 -0
  100. data/lib/ramaze/snippets/string/DIVIDE.rb +1 -1
  101. data/lib/ramaze/snippets/string/snake_case.rb +1 -1
  102. data/lib/ramaze/snippets/struct/values_at.rb +5 -1
  103. data/lib/ramaze/snippets/thread/into.rb +25 -0
  104. data/lib/ramaze/sourcereload.rb +39 -19
  105. data/lib/ramaze/spec/helper.rb +4 -1
  106. data/lib/ramaze/spec/helper/{context.rb → browser.rb} +3 -0
  107. data/lib/ramaze/spec/helper/layout.rb +3 -0
  108. data/lib/ramaze/spec/helper/minimal.rb +3 -0
  109. data/lib/ramaze/spec/helper/mock_http.rb +8 -5
  110. data/lib/ramaze/spec/helper/requester.rb +4 -1
  111. data/lib/ramaze/spec/helper/wrap.rb +15 -7
  112. data/lib/ramaze/template.rb +5 -1
  113. data/lib/ramaze/template/ezamar/engine.rb +2 -3
  114. data/lib/ramaze/template/ezamar/morpher.rb +26 -45
  115. data/lib/ramaze/template/nagoro.rb +53 -0
  116. data/lib/ramaze/template/none.rb +14 -0
  117. data/lib/ramaze/template/xslt.rb +96 -0
  118. data/lib/ramaze/tool.rb +0 -1
  119. data/lib/ramaze/tool/localize.rb +7 -2
  120. data/lib/ramaze/trinity/request.rb +1 -0
  121. data/lib/ramaze/trinity/session.rb +3 -3
  122. data/lib/ramaze/version.rb +2 -2
  123. data/rake_tasks/conf.rake +1 -2
  124. data/rake_tasks/{maintaince.rake → maintenance.rake} +25 -17
  125. data/spec/contrib/auto_params.rb +97 -0
  126. data/spec/contrib/route.rb +60 -0
  127. data/spec/contrib/sequel/fill.rb +46 -0
  128. data/spec/examples/caching.rb +1 -2
  129. data/spec/examples/css.rb +12 -0
  130. data/spec/examples/element.rb +0 -1
  131. data/spec/examples/hello.rb +0 -1
  132. data/spec/examples/simple.rb +0 -1
  133. data/spec/helper.rb +3 -2
  134. data/spec/ramaze/action/cache.rb +24 -7
  135. data/spec/ramaze/action/layout.rb +19 -11
  136. data/spec/ramaze/action/template/sub/sub_wrapper.xhtml +1 -0
  137. data/spec/ramaze/controller.rb +11 -0
  138. data/spec/ramaze/controller/template_resolving.rb +28 -27
  139. data/spec/ramaze/dispatcher.rb +32 -0
  140. data/spec/ramaze/dispatcher/directory.rb +2 -1
  141. data/spec/ramaze/element.rb +1 -1
  142. data/spec/ramaze/gestalt.rb +28 -0
  143. data/spec/ramaze/helper/aspect.rb +14 -3
  144. data/spec/ramaze/helper/cache.rb +78 -13
  145. data/spec/ramaze/helper/formatting.rb +20 -0
  146. data/spec/ramaze/helper/link.rb +2 -0
  147. data/spec/ramaze/helper/partial.rb +12 -1
  148. data/spec/ramaze/helper/redirect.rb +44 -8
  149. data/spec/ramaze/helper/stack.rb +3 -3
  150. data/spec/ramaze/helper/template/loop.xhtml +3 -0
  151. data/spec/ramaze/helper/template/num.xhtml +1 -0
  152. data/spec/ramaze/helper/template/recursive.xhtml +8 -0
  153. data/spec/ramaze/morpher.rb +25 -6
  154. data/spec/ramaze/params.rb +6 -2
  155. data/spec/ramaze/request.rb +5 -2
  156. data/spec/ramaze/session.rb +19 -0
  157. data/spec/ramaze/template.rb +2 -2
  158. data/spec/ramaze/template/amrita2.rb +2 -2
  159. data/spec/ramaze/template/erubis.rb +2 -2
  160. data/spec/ramaze/template/ezamar.rb +6 -3
  161. data/spec/ramaze/template/haml.rb +3 -3
  162. data/spec/ramaze/template/liquid.rb +1 -1
  163. data/spec/ramaze/template/markaby.rb +1 -1
  164. data/spec/ramaze/template/nagoro.rb +65 -0
  165. data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
  166. data/spec/ramaze/template/nagoro/combined.nag +1 -0
  167. data/spec/ramaze/template/nagoro/file_only.nag +1 -0
  168. data/spec/ramaze/template/nagoro/index.nag +1 -0
  169. data/spec/ramaze/template/nagoro/nested.nag +1 -0
  170. data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
  171. data/spec/ramaze/template/nagoro/sum.nag +1 -0
  172. data/spec/ramaze/template/remarkably.rb +1 -1
  173. data/spec/ramaze/template/sass.rb +1 -1
  174. data/spec/ramaze/template/xslt.rb +93 -0
  175. data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
  176. data/spec/ramaze/template/xslt/index.xsl +14 -0
  177. data/spec/ramaze/template/xslt/products.xsl +32 -0
  178. data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
  179. data/spec/snippets/array/put_within.rb +32 -0
  180. data/spec/snippets/numeric/filesize_format.rb +12 -0
  181. data/spec/snippets/ordered_set.rb +56 -0
  182. data/spec/snippets/ramaze/caller_lines.rb +6 -3
  183. data/spec/snippets/string/snake_case.rb +3 -0
  184. metadata +118 -22
  185. data/doc/README.html +0 -737
  186. data/examples/fcgi.rb +0 -13
  187. data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +0 -33
  188. data/lib/ramaze/tool/tidy.rb +0 -104
  189. data/spec/ramaze/controller/template/edit.xhtml +0 -1
  190. data/spec/ramaze/controller/template/edit/content.xhtml +0 -1
  191. data/spec/ramaze/tidy.rb +0 -12
  192. data/spec/snippets/numeric/human_readable_filesize_format.rb +0 -11
@@ -23,7 +23,8 @@ module Ramaze
23
23
  def helper *syms
24
24
  syms.each do |sym|
25
25
  mod_name = sym.to_s.capitalize + 'Helper'
26
- require("ramaze/helper/"/sym)
26
+ glob = "{helper,#{BASEDIR/:ramaze/:helper}}/#{sym}.{rb,so}"
27
+ require Dir[glob].first
27
28
  include ::Ramaze.const_get(mod_name)
28
29
  extend ::Ramaze.const_get(mod_name)
29
30
  end
@@ -74,7 +74,7 @@ module Ramaze
74
74
  # overwrites the default Action hook and runs the neccesary blocks in its
75
75
  # scope.
76
76
  def before_process
77
- return unless aspects = controller.ancestral_trait[:aspects]
77
+ return unless path and aspects = controller.ancestral_trait[:aspects]
78
78
  [ aspects[:before][name], aspects[:before][:all] ].compact.map do |block|
79
79
  instance.instance_eval(&block) if block
80
80
  end
@@ -83,7 +83,7 @@ module Ramaze
83
83
  # overwrites the default Action hook and runs the neccesary blocks in its
84
84
  # scope.
85
85
  def after_process
86
- return unless aspects = controller.ancestral_trait[:aspects]
86
+ return unless path and aspects = controller.ancestral_trait[:aspects]
87
87
  [ aspects[:after][name], aspects[:after][:all] ].compact.map do |block|
88
88
  instance.instance_eval(&block) if block
89
89
  end
@@ -5,12 +5,8 @@ require 'digest/sha1'
5
5
 
6
6
  module Ramaze
7
7
 
8
- # A really, really, totally stupid way to do authentication. It has no
9
- # roles and only a single password without usernames.
10
- #
11
- # It is intended to be a simple way to protect various portions of a page
12
- # when you start working on it. Also it is a nice way to see how you could
13
- # implement your own authentication.
8
+ # A simple way to do authentication. Please have a look at the docs for the
9
+ # check_auth method for detailed information
14
10
 
15
11
  module AuthHelper
16
12
 
@@ -32,6 +28,7 @@ module Ramaze
32
28
  username, password = request.params.values_at('username', 'password')
33
29
  if check_auth(username, password)
34
30
  session[:logged_in] = true
31
+ session[:username] = username
35
32
  inside_stack? ? answer : redirect( R(self) )
36
33
  else
37
34
  if AUTH_ELEMENT and AUTH_ELEMENT.to_s.split.any?
@@ -40,7 +37,7 @@ module Ramaze
40
37
  end
41
38
  %{
42
39
  #{open_element}
43
- <form method="POST" action="#{R(self, :login)}"
40
+ <form method="POST" action="#{Rs(:login)}"
44
41
  <ul style="list-style:none;">
45
42
  <li>Username: <input type="text" name="username" /></li>
46
43
  <li>Password: <input type="password" name="password" /></li>
@@ -60,14 +57,14 @@ module Ramaze
60
57
  redirect_referer
61
58
  end
62
59
 
60
+ private
61
+
63
62
  # call( R(self, :login) ) if not logged in
64
63
 
65
64
  def login_required
66
65
  call(Rs(:login)) unless logged_in?
67
66
  end
68
67
 
69
- private
70
-
71
68
  # checks if the user is already logged in.
72
69
  # session[:logged_in] is not nil/false
73
70
 
@@ -13,6 +13,42 @@ module Ramaze
13
13
  Cache.add(:value_cache) unless Cache::CACHES.has_key?(:value_cache)
14
14
  end
15
15
 
16
+ # Example:
17
+ #
18
+ # class FooController < Ramaze::Controller
19
+ # helper :cache
20
+ # cache :index, :map_of_the_internet
21
+ # end
22
+ #
23
+ # cache supports these options
24
+ # [+:ttl+] time-to-live in seconds
25
+ # [+:key+] proc that returns a key to store cache with
26
+ #
27
+ # Example:
28
+ #
29
+ # class CacheController < Ramaze::Controller
30
+ # helper :cache
31
+ #
32
+ # # for each distinct value of request['name']
33
+ # # cache rendered output of name action for 60 seconds
34
+ # cache :name, :key => lambda{ request['name'] }, :ttl => 60
35
+ #
36
+ # def name
37
+ # "hi #{request['name']}"
38
+ # end
39
+ # end
40
+
41
+ def cache *args
42
+ if args.last.is_a? Hash
43
+ opts = args.pop
44
+ end
45
+ opts ||= {}
46
+
47
+ args.each do |arg|
48
+ actions_cached[arg.to_sym] = opts unless arg.nil?
49
+ end
50
+ end
51
+
16
52
  private
17
53
 
18
54
  # use this to cache values in your controller and templates,
@@ -22,21 +58,65 @@ module Ramaze
22
58
  Cache.value_cache
23
59
  end
24
60
 
25
- # holds the values returned on the first call to a cached action.
26
- # To uncache, simply delete.
61
+ # action_cache holds rendered output of actions for which caching is enabled.
27
62
  #
28
- # Please note that the action is cached by a combination of
29
- # [action, parameter].inspect - so it is a bit awkward to use.
63
+ # For simple cases:
30
64
  #
31
- # Suggestions welcome.
65
+ # class Controller < Ramaze::Controller
66
+ # map '/path/to'
67
+ # helper :cache
68
+ # cache :action
32
69
  #
33
- # Example:
70
+ # def action with, params
71
+ # 'rendered output'
72
+ # end
73
+ # end
74
+ #
75
+ # { '/path/to/action/with/params' => {
76
+ # :time => Time.at(rendering),
77
+ # :type => 'content/type',
78
+ # :content => 'rendered output'
79
+ # }
80
+ # }
81
+ #
82
+ # If an additional key is provided:
83
+ #
84
+ # class Controller < Ramaze::Controller
85
+ # map '/path/to'
86
+ # helper :cache
87
+ # cache :action, :key => lambda{ 'value of key proc' }
34
88
  #
35
- # action_cache.delete '["index", []]'
89
+ # def action
90
+ # 'output'
91
+ # end
92
+ # end
93
+ #
94
+ # { '/path/to/action' => {
95
+ # 'value of key proc' => {
96
+ # :time => Time.at(rendering),
97
+ # :type => 'content/type',
98
+ # :content => 'output'
99
+ # }
100
+ # }
101
+ # }
102
+ #
103
+ # Caches can be invalidated after a certain amount of time
104
+ # by supplying a :ttl option (in seconds)
105
+ #
106
+ # class Controller < Ramaze::Controller
107
+ # helper :cache
108
+ # cache :index, :ttl => 60
109
+ #
110
+ # def index
111
+ # Time.now.to_s
112
+ # end
113
+ # end
36
114
  #
37
- # or by delete_if
115
+ # or by deleting values from action_cache directly
38
116
  #
39
- # action_cache.delete_if{|key, value| key =~ /"index",/}
117
+ # action_cache.clear
118
+ # action_cache.delete '/index'
119
+ # action_cache.delete '/path/to/action'
40
120
 
41
121
  def action_cache
42
122
  Cache.actions
@@ -20,13 +20,13 @@ module Ramaze
20
20
  CGI.unescape(*args)
21
21
  end
22
22
 
23
- # shortcut for GCI.escapeHTML
23
+ # shortcut for CGI.escapeHTML
24
24
 
25
25
  def html_escape(string)
26
26
  CGI.escapeHTML(string)
27
27
  end
28
28
 
29
- # shortcut for GCI.unescapeHTML
29
+ # shortcut for CGI.unescapeHTML
30
30
 
31
31
  def html_unescape(string)
32
32
  CGI.unescapeHTML(string)
@@ -0,0 +1,44 @@
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 FormattingHelper
6
+ private
7
+
8
+ def number_format(n, delimiter = ',')
9
+ delim_l, delim_r = delimiter == ',' ? %w[, .] : %w[. ,]
10
+ h, r = n.to_s.split('.')
11
+ [h.reverse.scan(/\d{1,3}/).join(delim_l).reverse, r].compact.join(delim_r)
12
+ end
13
+
14
+ # stolen and adapted from rails
15
+ def time_diff from_time, to_time = Time.now, include_seconds = false
16
+ distance_in_minutes = (((to_time - from_time).abs)/60).round
17
+ distance_in_seconds = ((to_time - from_time).abs).round if include_seconds
18
+
19
+ case distance_in_minutes
20
+ when 0..1
21
+ return (distance_in_minutes == 0) ? 'less than a minute' : '1 minute' unless include_seconds
22
+ case distance_in_seconds
23
+ when 0..4 then 'less than 5 seconds'
24
+ when 5..9 then 'less than 10 seconds'
25
+ when 10..19 then 'less than 20 seconds'
26
+ when 20..39 then 'half a minute'
27
+ when 40..59 then 'less than a minute'
28
+ else '1 minute'
29
+ end
30
+
31
+ when 2..44 then "#{distance_in_minutes} minutes"
32
+ when 45..89 then 'about 1 hour'
33
+ when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
34
+ when 1440..2879 then '1 day'
35
+ when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
36
+ when 43200..86399 then 'about 1 month'
37
+ when 86400..525959 then "#{(distance_in_minutes / 43200).round} months"
38
+ when 525960..1051919 then 'about 1 year'
39
+ else "over #{(distance_in_minutes / 525960).round} years"
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -20,13 +20,15 @@ module Ramaze
20
20
  # used instead. If you really want an empty href, use :href => ''
21
21
  #
22
22
  # Usage:
23
- # A('title') #=> <a href="/title">title</a>
24
- # A('foo/bar') #=> <a href="/foo/bar">foo/bar</a>
25
- # A('Home', :href => Rs(:/)) #=> <a href="/foo/bar">Home</a>
23
+ # A('title') #> <a href="/title">title</a>
24
+ # A('foo/bar') #> <a href="/foo/bar">foo/bar</a>
25
+ # A('/foo?x=y') #> <a href="/foo?x=y">/foo?x=y</a>
26
+ # A('title', :href => '/foo?x=y') #> <a href="/foo?x=y">title</a>
27
+ # A('Home', :href => Rs(:/)) #> <a href="/foo/bar">Home</a>
26
28
 
27
29
  def A(title, hash = {})
28
- hash[:href] ||= Rs(title)
29
- hash[:href].to_s.gsub!(/[^\/]+/){|m| CGI.escape(m) }
30
+ hash[:href] ||= (Rs(title) rescue title)
31
+ hash[:href].to_s.sub!(/\A[^\/?]+/){|m| CGI.escape(m) }
30
32
 
31
33
  args = ['']
32
34
  hash.each{|k,v| args << %(#{k}="#{v}") if k and v }
@@ -37,7 +37,7 @@ module Ramaze
37
37
  def render_partial(url, options = {})
38
38
  saved = {}
39
39
  options.keys.each {|x| saved[x] = Request.current.params[x] }
40
- saved_action = Thread.current[:action]
40
+ saved_action = Action.current
41
41
 
42
42
  Request.current.params.update(options)
43
43
 
@@ -53,13 +53,15 @@ module Ramaze
53
53
 
54
54
  def render_template(file, options = {})
55
55
  current = Action.current
56
- options[:binding] ||= current.binding
57
- options[:controller] ||= current.controller
58
- options[:instance] ||= current.instance
56
+ options[:controller] ||= current.controller
57
+ options[:instance] ||= current.instance.dup
58
+ options[:binding] ||= options[:instance].instance_eval{ binding }
59
59
  options[:template] = (options[:controller].template_root/file)
60
60
 
61
61
  action = Ramaze::Action(options)
62
62
  action.render
63
+ ensure
64
+ Thread.current[:action] = current
63
65
  end
64
66
  end
65
67
  end
@@ -9,11 +9,12 @@ module Ramaze
9
9
  # setting a status-code of 303 and a response['Location'] = link
10
10
  # returning some nice text for visitors who insist on ignoring those hints :P
11
11
  #
12
- # example of usage:
13
- # redirect MainController
14
- # redirect MainController, :foo
12
+ # Usage:
13
+ # redirect Rs()
14
+ # redirect R(MainController)
15
+ # redirect R(MainController, :foo)
15
16
  # redirect 'foo/bar'
16
- # redirect :index, :status => 309
17
+ # redirect 'foo/bar', :status => 301
17
18
  #
18
19
  # TODO:
19
20
  # - maybe some more options, like a delay
@@ -23,22 +24,35 @@ module Ramaze
23
24
 
24
25
  private
25
26
 
27
+ # render to the browser directly, ignoring any templates
28
+ def respond *args
29
+ response.build(*args)
30
+ throw :respond
31
+ end
32
+
26
33
  # Usage:
34
+ # redirect Rs()
27
35
  # redirect R(MainController)
28
36
  # redirect R(MainController, :foo)
29
37
  # redirect 'foo/bar'
38
+ # redirect 'foo/bar', :status => 301
30
39
 
31
40
  def redirect target, opts = {}
32
41
  target = target.to_s
33
- head = {
34
- 'Location' => target
35
- }.merge(response.header)
36
42
 
37
- status = opts[:status] || STATUS_CODE["See Other"]
43
+ unless target =~ %r!^https?://!
44
+ target[0,0] = '/' unless target =~ %r!^/!
45
+ if host = request.env['HTTP_HOST']
46
+ target[0,0] = "http://#{host}"
47
+ end
48
+ end
38
49
 
50
+ header = {'Location' => target}
51
+ status = opts[:status] || STATUS_CODE["See Other"]
39
52
  body = %{You are being redirected, please follow <a href="#{target}">this link to: #{target}</a>!}
40
53
 
41
- throw(:redirect, :body => body, :status => status, :head => head)
54
+ Inform.info("Redirect to '#{target}'")
55
+ throw(:redirect, [body, status, header])
42
56
  end
43
57
 
44
58
  # redirect to the location the browser says it's coming from.
@@ -46,5 +60,6 @@ module Ramaze
46
60
  def redirect_referer
47
61
  redirect request.referer
48
62
  end
63
+ alias redirect_referrer redirect_referer
49
64
  end
50
65
  end
@@ -53,7 +53,12 @@ module Ramaze
53
53
  # return to the last location on session[:STACK]
54
54
 
55
55
  def answer
56
- redirect R(session[:STACK].pop) if inside_stack?
56
+ if inside_stack?
57
+ stack = session[:STACK]
58
+ target = stack.pop
59
+ session.delete(:STACK) if stack.empty?
60
+ redirect target
61
+ end
57
62
  end
58
63
 
59
64
  # check if the stack has something inside.
@@ -13,7 +13,7 @@ module Ramaze
13
13
  :name => 'walrus',
14
14
  :host => 'localhost',
15
15
  :password => 'walrus',
16
- :all_notifies => %w[error warn debug info],
16
+ :all_notifies => %w[error warn debug info dev],
17
17
  :default_notifies => %w[error warn info]
18
18
  }
19
19
 
@@ -22,8 +22,9 @@ module Ramaze
22
22
 
23
23
  # Which tag should be in what color
24
24
  COLORS = {
25
- :info => :green,
25
+ :dev => :blue,
26
26
  :debug => :yellow,
27
+ :info => :green,
27
28
  :warn => :red,
28
29
  :error => :red,
29
30
  }
@@ -46,6 +46,12 @@ module Ramaze
46
46
  tag_inform(:debug, :inspect, *objects)
47
47
  end
48
48
 
49
+ # inspects objects if they are no strings. Tag is :dev
50
+
51
+ def dev(*objects)
52
+ tag_inform(:dev, :inspect, *objects)
53
+ end
54
+
49
55
  alias << debug
50
56
 
51
57
  # Takes either an Exception or just a String, formats backtraces to be a bit
@@ -19,6 +19,7 @@ module Ramaze
19
19
  # alias for default syslog methods so they match ramaze
20
20
  alias error err
21
21
  alias warn warning
22
+ alias dev debug
22
23
 
23
24
  # just sends all messages received to ::Syslog
24
25
  def inform(tag, *args)
@@ -0,0 +1,24 @@
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 Array
5
+ def put_within(object, constrain)
6
+ pre, post = constrain.values_at(:after, :before)
7
+
8
+ unless rindex(post) - index(pre) == 1
9
+ raise ArgumentError, "Too many elements within constrain"
10
+ end
11
+
12
+ put_after(pre, object)
13
+ end
14
+
15
+ def put_after(element, object)
16
+ raise ArgumentError, "The given element doesn't exist" unless include?(element)
17
+ self[index(element) + 1, 0] = object
18
+ end
19
+
20
+ def put_before(element, object)
21
+ raise ArgumentError, "The given element doesn't exist" unless include?(element)
22
+ self[rindex(element), 0] = object
23
+ end
24
+ end