ramaze 0.1.4 → 0.2.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 +26 -6
- data/bin/ramaze +8 -1
- data/doc/AUTHORS +13 -11
- data/doc/CHANGELOG +472 -13
- data/doc/LEGAL +22 -0
- data/doc/README +1 -4
- data/doc/TODO +7 -2
- data/doc/changes.txt +472 -13
- data/doc/changes.xml +472 -13
- data/doc/meta/announcement.txt +21 -23
- data/doc/readme_chunks/appendix.txt +0 -3
- data/doc/readme_chunks/features.txt +1 -1
- data/examples/auth/auth.rb +49 -0
- data/examples/auth/template/layout.haml +20 -0
- data/examples/auth/template/login.haml +16 -0
- data/examples/blog/spec/blog.rb +1 -0
- data/examples/caching.rb +5 -6
- data/examples/css.rb +37 -0
- data/examples/layout.rb +3 -17
- data/examples/simple_auth.rb +23 -0
- data/examples/sourceview/public/images/file.gif +0 -0
- data/examples/sourceview/public/images/folder.gif +0 -0
- data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/sourceview/public/images/tv-item.gif +0 -0
- data/examples/sourceview/public/jquery.js +11 -0
- data/examples/sourceview/public/jquery.treeview.css +47 -0
- data/examples/sourceview/public/jquery.treeview.js +223 -0
- data/examples/sourceview/public/sourceview.js +16 -0
- data/examples/sourceview/sourceview.rb +74 -0
- data/examples/sourceview/template/index.haml +43 -0
- data/examples/templates/template/external.nag +28 -0
- data/examples/templates/template/external.xsl +57 -0
- data/examples/templates/template_amrita2.rb +2 -4
- data/examples/templates/template_erubis.rb +1 -1
- data/examples/templates/template_haml.rb +1 -1
- data/examples/templates/template_liquid.rb +2 -4
- data/examples/templates/template_markaby.rb +2 -4
- data/examples/templates/template_nagoro.rb +53 -0
- data/examples/templates/template_remarkably.rb +2 -4
- data/examples/templates/template_xslt.rb +52 -0
- data/examples/whywiki/spec/whywiki.rb +63 -0
- data/examples/whywiki/start.rb +11 -13
- data/examples/whywiki/template/edit.xhtml +3 -3
- data/examples/whywiki/template/show.xhtml +5 -8
- data/examples/wikore/spec/wikore.rb +115 -0
- data/examples/wikore/src/controller.rb +81 -0
- data/examples/wikore/src/model.rb +51 -0
- data/examples/wikore/start.rb +6 -0
- data/examples/wikore/template/index.xhtml +8 -0
- data/examples/wiktacular/spec/wiktacular.rb +1 -0
- data/examples/wiktacular/src/controller.rb +1 -1
- data/lib/ramaze.rb +6 -3
- data/lib/ramaze/action.rb +2 -13
- data/lib/ramaze/action/render.rb +36 -18
- data/lib/ramaze/adapter.rb +1 -1
- data/lib/ramaze/adapter/cgi.rb +0 -3
- data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
- data/lib/ramaze/adapter/mongrel.rb +4 -13
- data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
- data/lib/ramaze/cache.rb +12 -7
- data/lib/ramaze/contrib.rb +22 -0
- data/lib/ramaze/contrib/auto_params.rb +128 -0
- data/lib/ramaze/contrib/auto_params/get_args.rb +56 -0
- data/lib/ramaze/contrib/gzip_filter.rb +57 -0
- data/lib/ramaze/contrib/route.rb +40 -0
- data/lib/ramaze/contrib/sequel/fill.rb +12 -0
- data/lib/ramaze/controller.rb +17 -6
- data/lib/ramaze/controller/resolve.rb +51 -14
- data/lib/ramaze/dispatcher.rb +15 -13
- data/lib/ramaze/dispatcher/action.rb +4 -3
- data/lib/ramaze/dispatcher/directory.rb +3 -3
- data/lib/ramaze/dispatcher/error.rb +1 -1
- data/lib/ramaze/dispatcher/file.rb +17 -6
- data/lib/ramaze/error.rb +3 -0
- data/lib/ramaze/gestalt.rb +28 -8
- data/lib/ramaze/global.rb +26 -6
- data/lib/ramaze/global/globalstruct.rb +31 -6
- data/lib/ramaze/helper.rb +2 -1
- data/lib/ramaze/helper/aspect.rb +2 -2
- data/lib/ramaze/helper/auth.rb +6 -9
- data/lib/ramaze/helper/cache.rb +89 -9
- data/lib/ramaze/helper/cgi.rb +2 -2
- data/lib/ramaze/helper/formatting.rb +44 -0
- data/lib/ramaze/helper/link.rb +7 -5
- data/lib/ramaze/helper/partial.rb +6 -4
- data/lib/ramaze/helper/redirect.rb +24 -9
- data/lib/ramaze/helper/stack.rb +6 -1
- data/lib/ramaze/inform/growl.rb +1 -1
- data/lib/ramaze/inform/informer.rb +2 -1
- data/lib/ramaze/inform/informing.rb +6 -0
- data/lib/ramaze/inform/syslog.rb +1 -0
- data/lib/ramaze/snippets/array/put_within.rb +24 -0
- data/lib/ramaze/snippets/dictionary.rb +499 -0
- data/lib/ramaze/snippets/numeric/filesize_format.rb +19 -0
- data/lib/ramaze/snippets/ordered_set.rb +31 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +1 -1
- data/lib/ramaze/snippets/string/snake_case.rb +1 -1
- data/lib/ramaze/snippets/struct/values_at.rb +5 -1
- data/lib/ramaze/snippets/thread/into.rb +25 -0
- data/lib/ramaze/sourcereload.rb +39 -19
- data/lib/ramaze/spec/helper.rb +4 -1
- data/lib/ramaze/spec/helper/{context.rb → browser.rb} +3 -0
- data/lib/ramaze/spec/helper/layout.rb +3 -0
- data/lib/ramaze/spec/helper/minimal.rb +3 -0
- data/lib/ramaze/spec/helper/mock_http.rb +8 -5
- data/lib/ramaze/spec/helper/requester.rb +4 -1
- data/lib/ramaze/spec/helper/wrap.rb +15 -7
- data/lib/ramaze/template.rb +5 -1
- data/lib/ramaze/template/ezamar/engine.rb +2 -3
- data/lib/ramaze/template/ezamar/morpher.rb +26 -45
- data/lib/ramaze/template/nagoro.rb +53 -0
- data/lib/ramaze/template/none.rb +14 -0
- data/lib/ramaze/template/xslt.rb +96 -0
- data/lib/ramaze/tool.rb +0 -1
- data/lib/ramaze/tool/localize.rb +7 -2
- data/lib/ramaze/trinity/request.rb +1 -0
- data/lib/ramaze/trinity/session.rb +3 -3
- data/lib/ramaze/version.rb +2 -2
- data/rake_tasks/conf.rake +1 -2
- data/rake_tasks/{maintaince.rake → maintenance.rake} +25 -17
- data/spec/contrib/auto_params.rb +97 -0
- data/spec/contrib/route.rb +60 -0
- data/spec/contrib/sequel/fill.rb +46 -0
- data/spec/examples/caching.rb +1 -2
- data/spec/examples/css.rb +12 -0
- data/spec/examples/element.rb +0 -1
- data/spec/examples/hello.rb +0 -1
- data/spec/examples/simple.rb +0 -1
- data/spec/helper.rb +3 -2
- data/spec/ramaze/action/cache.rb +24 -7
- data/spec/ramaze/action/layout.rb +19 -11
- data/spec/ramaze/action/template/sub/sub_wrapper.xhtml +1 -0
- data/spec/ramaze/controller.rb +11 -0
- data/spec/ramaze/controller/template_resolving.rb +28 -27
- data/spec/ramaze/dispatcher.rb +32 -0
- data/spec/ramaze/dispatcher/directory.rb +2 -1
- data/spec/ramaze/element.rb +1 -1
- data/spec/ramaze/gestalt.rb +28 -0
- data/spec/ramaze/helper/aspect.rb +14 -3
- data/spec/ramaze/helper/cache.rb +78 -13
- data/spec/ramaze/helper/formatting.rb +20 -0
- data/spec/ramaze/helper/link.rb +2 -0
- data/spec/ramaze/helper/partial.rb +12 -1
- data/spec/ramaze/helper/redirect.rb +44 -8
- data/spec/ramaze/helper/stack.rb +3 -3
- data/spec/ramaze/helper/template/loop.xhtml +3 -0
- data/spec/ramaze/helper/template/num.xhtml +1 -0
- data/spec/ramaze/helper/template/recursive.xhtml +8 -0
- data/spec/ramaze/morpher.rb +25 -6
- data/spec/ramaze/params.rb +6 -2
- data/spec/ramaze/request.rb +5 -2
- data/spec/ramaze/session.rb +19 -0
- data/spec/ramaze/template.rb +2 -2
- data/spec/ramaze/template/amrita2.rb +2 -2
- data/spec/ramaze/template/erubis.rb +2 -2
- data/spec/ramaze/template/ezamar.rb +6 -3
- data/spec/ramaze/template/haml.rb +3 -3
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/nagoro.rb +65 -0
- data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
- data/spec/ramaze/template/nagoro/combined.nag +1 -0
- data/spec/ramaze/template/nagoro/file_only.nag +1 -0
- data/spec/ramaze/template/nagoro/index.nag +1 -0
- data/spec/ramaze/template/nagoro/nested.nag +1 -0
- data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
- data/spec/ramaze/template/nagoro/sum.nag +1 -0
- data/spec/ramaze/template/remarkably.rb +1 -1
- data/spec/ramaze/template/sass.rb +1 -1
- data/spec/ramaze/template/xslt.rb +93 -0
- data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
- data/spec/ramaze/template/xslt/index.xsl +14 -0
- data/spec/ramaze/template/xslt/products.xsl +32 -0
- data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
- data/spec/snippets/array/put_within.rb +32 -0
- data/spec/snippets/numeric/filesize_format.rb +12 -0
- data/spec/snippets/ordered_set.rb +56 -0
- data/spec/snippets/ramaze/caller_lines.rb +6 -3
- data/spec/snippets/string/snake_case.rb +3 -0
- metadata +118 -22
- data/doc/README.html +0 -737
- data/examples/fcgi.rb +0 -13
- data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +0 -33
- data/lib/ramaze/tool/tidy.rb +0 -104
- data/spec/ramaze/controller/template/edit.xhtml +0 -1
- data/spec/ramaze/controller/template/edit/content.xhtml +0 -1
- data/spec/ramaze/tidy.rb +0 -12
- data/spec/snippets/numeric/human_readable_filesize_format.rb +0 -11
data/lib/ramaze/helper.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/ramaze/helper/aspect.rb
CHANGED
|
@@ -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
|
data/lib/ramaze/helper/auth.rb
CHANGED
|
@@ -5,12 +5,8 @@ require 'digest/sha1'
|
|
|
5
5
|
|
|
6
6
|
module Ramaze
|
|
7
7
|
|
|
8
|
-
# A
|
|
9
|
-
#
|
|
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="#{
|
|
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
|
|
data/lib/ramaze/helper/cache.rb
CHANGED
|
@@ -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
|
|
26
|
-
# To uncache, simply delete.
|
|
61
|
+
# action_cache holds rendered output of actions for which caching is enabled.
|
|
27
62
|
#
|
|
28
|
-
#
|
|
29
|
-
# [action, parameter].inspect - so it is a bit awkward to use.
|
|
63
|
+
# For simple cases:
|
|
30
64
|
#
|
|
31
|
-
#
|
|
65
|
+
# class Controller < Ramaze::Controller
|
|
66
|
+
# map '/path/to'
|
|
67
|
+
# helper :cache
|
|
68
|
+
# cache :action
|
|
32
69
|
#
|
|
33
|
-
#
|
|
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
|
-
#
|
|
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
|
|
115
|
+
# or by deleting values from action_cache directly
|
|
38
116
|
#
|
|
39
|
-
# action_cache.
|
|
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
|
data/lib/ramaze/helper/cgi.rb
CHANGED
|
@@ -20,13 +20,13 @@ module Ramaze
|
|
|
20
20
|
CGI.unescape(*args)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
# shortcut for
|
|
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
|
|
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
|
data/lib/ramaze/helper/link.rb
CHANGED
|
@@ -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')
|
|
24
|
-
# A('foo/bar')
|
|
25
|
-
# 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.
|
|
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 =
|
|
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[:
|
|
57
|
-
options[:
|
|
58
|
-
options[:
|
|
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
|
-
#
|
|
13
|
-
# redirect
|
|
14
|
-
# redirect MainController
|
|
12
|
+
# Usage:
|
|
13
|
+
# redirect Rs()
|
|
14
|
+
# redirect R(MainController)
|
|
15
|
+
# redirect R(MainController, :foo)
|
|
15
16
|
# redirect 'foo/bar'
|
|
16
|
-
# redirect
|
|
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
|
-
|
|
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
|
-
|
|
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
|
data/lib/ramaze/helper/stack.rb
CHANGED
|
@@ -53,7 +53,12 @@ module Ramaze
|
|
|
53
53
|
# return to the last location on session[:STACK]
|
|
54
54
|
|
|
55
55
|
def answer
|
|
56
|
-
|
|
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.
|
data/lib/ramaze/inform/growl.rb
CHANGED
|
@@ -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
|
data/lib/ramaze/inform/syslog.rb
CHANGED
|
@@ -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
|