ramaze 2011.01.30 → 2011.07.25
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/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
|
@@ -36,15 +36,14 @@ module Ramaze
|
|
|
36
36
|
op = rand > 0.42 ? [ns[0], :+, ns[1]] : [ns[1], :-, ns[0]]
|
|
37
37
|
|
|
38
38
|
question = op.join(' ')
|
|
39
|
-
answer
|
|
39
|
+
answer = op[0].send(op[1], op[2])
|
|
40
40
|
|
|
41
41
|
[question, answer]
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
# Call the trait[:captcha] and store question/answer in session
|
|
45
45
|
def simple_captcha
|
|
46
|
-
question, answer
|
|
47
|
-
|
|
46
|
+
question, answer = ancestral_trait[:captcha].call
|
|
48
47
|
session[:CAPTCHA] = { :question => question, :answer => answer.to_s }
|
|
49
48
|
|
|
50
49
|
question
|
|
@@ -56,6 +55,6 @@ module Ramaze
|
|
|
56
55
|
|
|
57
56
|
answer.to_s.strip == captcha[:answer].to_s
|
|
58
57
|
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
58
|
+
end # SimpleCaptcha
|
|
59
|
+
end # Helper
|
|
60
|
+
end # Ramaze
|
data/lib/ramaze/helper/stack.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
5
|
module Helper
|
|
6
|
-
|
|
6
|
+
##
|
|
7
7
|
# provides an call/answer mechanism, this is useful for example in a
|
|
8
8
|
# login-system.
|
|
9
9
|
#
|
|
@@ -38,6 +38,7 @@ module Ramaze
|
|
|
38
38
|
# "Agent X is assigned to fight the RubyNinjas"
|
|
39
39
|
# end
|
|
40
40
|
# end
|
|
41
|
+
#
|
|
41
42
|
module Stack
|
|
42
43
|
# redirect to another location and pushing the current location
|
|
43
44
|
# on the session[:STACK]
|
|
@@ -50,11 +51,13 @@ module Ramaze
|
|
|
50
51
|
redirect(this)
|
|
51
52
|
end
|
|
52
53
|
|
|
54
|
+
##
|
|
53
55
|
# return to the last location on session[:STACK]
|
|
54
56
|
# The optional alternative paramter will be used to redirect in case you
|
|
55
57
|
# are not inside_stack?
|
|
56
58
|
# If the session has no stack and no alternative is given this won't do
|
|
57
59
|
# anything
|
|
60
|
+
#
|
|
58
61
|
def answer(alternative = nil)
|
|
59
62
|
if inside_stack?
|
|
60
63
|
stack = session[:STACK]
|
|
@@ -70,6 +73,6 @@ module Ramaze
|
|
|
70
73
|
def inside_stack?
|
|
71
74
|
session[:STACK] and session[:STACK].any?
|
|
72
75
|
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
+
end # Stack
|
|
77
|
+
end # Helper
|
|
78
|
+
end # Ramaze
|
data/lib/ramaze/helper/tagz.rb
CHANGED
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
require 'tagz'
|
|
5
5
|
|
|
6
6
|
module Ramaze
|
|
7
|
-
|
|
8
|
-
# Allows you to use some shortcuts for Tagz in your Controller.
|
|
9
|
-
|
|
10
|
-
# use this inside your controller to directly build Tagz
|
|
11
|
-
# Refer to the Tagz-documentation and testsuite for more examples.
|
|
12
|
-
# Usage:
|
|
13
|
-
# tagz { h1_{ "Apples & Oranges" } } #=> "<h1>Apples & Oranges</h1>"
|
|
14
|
-
# tagz { h1_(:class => 'fruits&floots'){ 'Apples' } } #=> "<h1 class=\"fruits&floots\">Apples</h1>"
|
|
15
|
-
|
|
16
7
|
module Helper
|
|
8
|
+
##
|
|
9
|
+
# Allows you to use some shortcuts for Tagz in your Controller.
|
|
10
|
+
# use this inside your controller to directly build Tagz
|
|
11
|
+
# Refer to the Tagz-documentation and testsuite for more examples.
|
|
12
|
+
# Usage:
|
|
13
|
+
# tagz { h1_{ "Apples & Oranges" } } #=> "<h1>Apples & Oranges</h1>"
|
|
14
|
+
# tagz { h1_(:class => 'fruits&floots'){ 'Apples' } }
|
|
15
|
+
#
|
|
17
16
|
Tagz = ::Tagz
|
|
18
|
-
end
|
|
19
|
-
end
|
|
17
|
+
end # Helper
|
|
18
|
+
end # Ramaze
|
data/lib/ramaze/helper/thread.rb
CHANGED
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
-
module Helper
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
module Helper
|
|
6
|
+
module Thread
|
|
7
|
+
##
|
|
8
|
+
# The thread method executes the specified block in a new thread.
|
|
9
|
+
#
|
|
10
|
+
# @param [Block] block The block that contains the code that will be
|
|
11
|
+
# executed in the new thread.
|
|
12
|
+
#
|
|
13
|
+
def thread &block
|
|
14
|
+
parent_thread = Thread.current
|
|
15
|
+
Thread.new do
|
|
16
|
+
begin
|
|
17
|
+
block.call
|
|
18
|
+
rescue Exception => e
|
|
19
|
+
parent_thread.raise(e)
|
|
20
|
+
end
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
+
end # Thread
|
|
24
|
+
end # Helper
|
|
25
|
+
end # Ramaze
|
|
@@ -11,9 +11,11 @@ module Ramaze
|
|
|
11
11
|
:headers => false, # ouput document with all headers
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
##
|
|
14
15
|
# Parse and output the file at the given path.
|
|
15
16
|
# Please head over to the Ultraviolet documentation for more information
|
|
16
17
|
# on possible options.
|
|
18
|
+
#
|
|
17
19
|
def ultraviolet(path, options = {})
|
|
18
20
|
o = ancestral_trait[:ultraviolet].merge(options)
|
|
19
21
|
output, syntax, lines, style, headers =
|
|
@@ -26,6 +28,7 @@ module Ramaze
|
|
|
26
28
|
Uv.parse(code, output, syntax, lines, style, headers)
|
|
27
29
|
end
|
|
28
30
|
|
|
31
|
+
##
|
|
29
32
|
# Return absolute path to the css of given name.
|
|
30
33
|
#
|
|
31
34
|
# Usually this will point to somewhere in the gem tree.
|
|
@@ -33,7 +36,7 @@ module Ramaze
|
|
|
33
36
|
# It seems like Uv will add support for user-defined PATH in the future,
|
|
34
37
|
# so we will, to be future-proof, traverse the Uv.path even though it
|
|
35
38
|
# currently will only have one directory.
|
|
36
|
-
|
|
39
|
+
#
|
|
37
40
|
def ultraviolet_css(theme)
|
|
38
41
|
Uv.path.each do |path|
|
|
39
42
|
Dir[path/"render/xhtml/files/css/*.css"].each do |css|
|
|
@@ -41,6 +44,6 @@ module Ramaze
|
|
|
41
44
|
end
|
|
42
45
|
end
|
|
43
46
|
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
+
end # UltraViolet
|
|
48
|
+
end # Helper
|
|
49
|
+
end # Ramaze
|
data/lib/ramaze/helper/user.rb
CHANGED
|
@@ -4,8 +4,8 @@ module Ramaze
|
|
|
4
4
|
# This helper provides a convenience wrapper for handling authentication
|
|
5
5
|
# and persistence of users.
|
|
6
6
|
#
|
|
7
|
-
# On every request, when you use the {UserHelper#user} method for the first
|
|
8
|
-
# we confirm the authentication and store the returned object in the
|
|
7
|
+
# On every request, when you use the {UserHelper#user} method for the first
|
|
8
|
+
# time, we confirm the authentication and store the returned object in the
|
|
9
9
|
# request.env, usually this will involve a request to your database.
|
|
10
10
|
#
|
|
11
11
|
# @example Basic usage with User::authenticate
|
|
@@ -77,7 +77,7 @@ module Ramaze
|
|
|
77
77
|
#
|
|
78
78
|
# @example Using a lambda instead of User::authenticate
|
|
79
79
|
#
|
|
80
|
-
# # assumes all your controllers
|
|
80
|
+
# # assumes all your controllers inherit from this one
|
|
81
81
|
#
|
|
82
82
|
# class Controller < Ramaze::Controller
|
|
83
83
|
# trait :user_callback => lambda{|creds|
|
|
@@ -87,7 +87,7 @@ module Ramaze
|
|
|
87
87
|
#
|
|
88
88
|
# @example Using a different model instead of User
|
|
89
89
|
#
|
|
90
|
-
# # assumes all your controllers
|
|
90
|
+
# # assumes all your controllers inherit from this one
|
|
91
91
|
#
|
|
92
92
|
# class Controller < Ramaze::Controller
|
|
93
93
|
# trait :user_model => Account
|
|
@@ -99,36 +99,42 @@ module Ramaze
|
|
|
99
99
|
# Using this as key in request.env
|
|
100
100
|
RAMAZE_HELPER_USER = 'ramaze.helper.user'.freeze
|
|
101
101
|
|
|
102
|
+
##
|
|
102
103
|
# Use this method in your application, but do not use it in conditionals
|
|
103
104
|
# as it will never be nil or false.
|
|
104
105
|
#
|
|
105
|
-
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
|
106
|
+
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
|
107
|
+
# model or callback
|
|
106
108
|
#
|
|
107
109
|
# @api external
|
|
108
110
|
# @author manveru
|
|
111
|
+
#
|
|
109
112
|
def user
|
|
110
113
|
env = request.env
|
|
111
114
|
found = env[RAMAZE_HELPER_USER]
|
|
112
115
|
return found if found
|
|
113
116
|
|
|
114
117
|
model, callback = ancestral_trait.values_at(:user_model, :user_callback)
|
|
115
|
-
model ||= ::User
|
|
118
|
+
model ||= ::User unless callback
|
|
116
119
|
env[RAMAZE_HELPER_USER] = Wrapper.new(model, callback)
|
|
117
120
|
end
|
|
118
121
|
|
|
122
|
+
##
|
|
119
123
|
# shortcut for user._login but default argument are request.params
|
|
120
124
|
#
|
|
121
|
-
# @param [Hash] creds the credentials that will be passed to callback or
|
|
122
|
-
#
|
|
125
|
+
# @param [Hash] creds the credentials that will be passed to callback or
|
|
126
|
+
# model
|
|
123
127
|
# @return [nil Hash] the given creds are returned on successful login
|
|
124
128
|
#
|
|
125
129
|
# @api external
|
|
126
130
|
# @see Ramaze::Helper::User::Wrapper#_login
|
|
127
131
|
# @author manveru
|
|
132
|
+
#
|
|
128
133
|
def user_login(creds = request.params)
|
|
129
134
|
user._login(creds)
|
|
130
135
|
end
|
|
131
136
|
|
|
137
|
+
##
|
|
132
138
|
# shortcut for user._logout
|
|
133
139
|
#
|
|
134
140
|
# @return [nil]
|
|
@@ -136,19 +142,23 @@ module Ramaze
|
|
|
136
142
|
# @api external
|
|
137
143
|
# @see Ramaze::Helper::User::Wrapper#_logout
|
|
138
144
|
# @author manveru
|
|
145
|
+
#
|
|
139
146
|
def user_logout
|
|
140
147
|
user._logout
|
|
141
148
|
end
|
|
142
149
|
|
|
150
|
+
##
|
|
143
151
|
# @return [true false] whether the user is logged in already.
|
|
144
152
|
#
|
|
145
153
|
# @api external
|
|
146
154
|
# @see Ramaze::Helper::User::Wrapper#_logged_in?
|
|
147
155
|
# @author manveru
|
|
156
|
+
#
|
|
148
157
|
def logged_in?
|
|
149
158
|
user._logged_in?
|
|
150
159
|
end
|
|
151
160
|
|
|
161
|
+
##
|
|
152
162
|
# Wrapper for the ever-present "user" in your application.
|
|
153
163
|
# It wraps around an arbitrary instance and worries about authentication
|
|
154
164
|
# and storing information about the user in the session.
|
|
@@ -157,6 +167,7 @@ module Ramaze
|
|
|
157
167
|
# methods with an underscore.
|
|
158
168
|
#
|
|
159
169
|
# Patches and suggestions are highly appreciated.
|
|
170
|
+
#
|
|
160
171
|
class Wrapper < BlankSlate
|
|
161
172
|
attr_accessor :_model, :_callback, :_user
|
|
162
173
|
|
|
@@ -166,15 +177,21 @@ module Ramaze
|
|
|
166
177
|
_login
|
|
167
178
|
end
|
|
168
179
|
|
|
169
|
-
|
|
180
|
+
##
|
|
181
|
+
# @param [Hash] creds this hash will be stored in the session on
|
|
182
|
+
# successful login
|
|
170
183
|
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
|
171
|
-
#
|
|
184
|
+
# model or callback
|
|
172
185
|
# @see Ramaze::Helper::User#user_login
|
|
173
186
|
# @author manveru
|
|
174
|
-
def _login(creds =
|
|
175
|
-
if
|
|
176
|
-
|
|
177
|
-
|
|
187
|
+
def _login(creds = nil)
|
|
188
|
+
if creds
|
|
189
|
+
if @_user = _would_login?(creds)
|
|
190
|
+
Current.session.resid!
|
|
191
|
+
self._persistence = {:credentials => creds}
|
|
192
|
+
end
|
|
193
|
+
elsif persistence = self._persistence
|
|
194
|
+
@_user = _would_login?(persistence[:credentials])
|
|
178
195
|
end
|
|
179
196
|
end
|
|
180
197
|
|
|
@@ -184,6 +201,8 @@ module Ramaze
|
|
|
184
201
|
# This will not actually login, just check whether the credentials
|
|
185
202
|
# would result in a user.
|
|
186
203
|
def _would_login?(creds)
|
|
204
|
+
return unless creds
|
|
205
|
+
|
|
187
206
|
if c = @_callback
|
|
188
207
|
c.call(creds)
|
|
189
208
|
elsif _model.respond_to?(:authenticate)
|
|
@@ -198,7 +217,7 @@ module Ramaze
|
|
|
198
217
|
# @see Ramaze::Helper::User#user_logout
|
|
199
218
|
# @author manveru
|
|
200
219
|
def _logout
|
|
201
|
-
_persistence.clear
|
|
220
|
+
(_persistence || {}).clear
|
|
202
221
|
Current.request.env['ramaze.helper.user'] = nil
|
|
203
222
|
end
|
|
204
223
|
|
|
@@ -210,12 +229,12 @@ module Ramaze
|
|
|
210
229
|
!!_user
|
|
211
230
|
end
|
|
212
231
|
|
|
213
|
-
def _persistence=(
|
|
214
|
-
Current.session[:USER] =
|
|
232
|
+
def _persistence=(obj)
|
|
233
|
+
Current.session[:USER] = obj
|
|
215
234
|
end
|
|
216
235
|
|
|
217
236
|
def _persistence
|
|
218
|
-
Current.session[:USER]
|
|
237
|
+
Current.session[:USER]
|
|
219
238
|
end
|
|
220
239
|
|
|
221
240
|
# Refer everything not known
|
|
@@ -225,6 +244,6 @@ module Ramaze
|
|
|
225
244
|
_user.send(meth, *args, &block)
|
|
226
245
|
end
|
|
227
246
|
end
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
end
|
|
247
|
+
end # User
|
|
248
|
+
end # Helper
|
|
249
|
+
end # Ramaze
|
data/lib/ramaze/helper/xhtml.rb
CHANGED
|
@@ -8,8 +8,8 @@ module Ramaze
|
|
|
8
8
|
#
|
|
9
9
|
# css 'reset', 'screen', :only => 'ie'
|
|
10
10
|
#
|
|
11
|
-
# This would result in a stylesheet named "reset.css" being loaded only when
|
|
12
|
-
# is using Internet Explorer.
|
|
11
|
+
# This would result in a stylesheet named "reset.css" being loaded only when
|
|
12
|
+
# the user is using Internet Explorer.
|
|
13
13
|
#
|
|
14
14
|
module XHTML
|
|
15
15
|
LINK_TAG = '<link href=%p media=%p rel="stylesheet" type="text/css" />'
|
|
@@ -17,12 +17,15 @@ module Ramaze
|
|
|
17
17
|
|
|
18
18
|
##
|
|
19
19
|
# Generate a CSS tag based on the name, media type and a hash containing
|
|
20
|
-
# additional options. For example, if we want to load the stylesheet only
|
|
21
|
-
# is using Internet Explorer we would have to add a key
|
|
20
|
+
# additional options. For example, if we want to load the stylesheet only
|
|
21
|
+
# when the user is using Internet Explorer we would have to add a key
|
|
22
|
+
# 'only' with a value of 'ie' to the hash.
|
|
22
23
|
#
|
|
23
24
|
# @param [String] name The name of the CSS file to load.
|
|
24
|
-
# @param [String] media The media type for which the stylesheet should be
|
|
25
|
-
#
|
|
25
|
+
# @param [String] media The media type for which the stylesheet should be
|
|
26
|
+
# loaded.
|
|
27
|
+
# @param [Hash] options A hash containing additional options for the
|
|
28
|
+
# stylesheet tag.
|
|
26
29
|
# @example
|
|
27
30
|
#
|
|
28
31
|
# # A very basic example.
|
|
@@ -46,14 +49,18 @@ module Ramaze
|
|
|
46
49
|
LINK_TAG % [name, media]
|
|
47
50
|
else
|
|
48
51
|
prefix = options[:prefix] || 'css'
|
|
49
|
-
LINK_TAG % [
|
|
52
|
+
LINK_TAG % [
|
|
53
|
+
"#{Ramaze.options.prefix.chomp("/")}/#{prefix}/#{name}.css",
|
|
54
|
+
media
|
|
55
|
+
]
|
|
50
56
|
end
|
|
51
57
|
end
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
##
|
|
55
|
-
# The css_for method can be used when you want to load multiple
|
|
56
|
-
# want to call the css() method over and over
|
|
61
|
+
# The css_for method can be used when you want to load multiple
|
|
62
|
+
# stylesheets and don't want to call the css() method over and over
|
|
63
|
+
# again.
|
|
57
64
|
#
|
|
58
65
|
# @example
|
|
59
66
|
#
|
|
@@ -64,8 +71,9 @@ module Ramaze
|
|
|
64
71
|
# css_for ['reset', 'print'], ['960', 'print']
|
|
65
72
|
#
|
|
66
73
|
# @see css()
|
|
67
|
-
# @param [Array] args An array containing either the names of all
|
|
68
|
-
#
|
|
74
|
+
# @param [Array] args An array containing either the names of all
|
|
75
|
+
# stylesheets to load or a collection of arrays of which each array
|
|
76
|
+
# defines the name, media and additional parameters.
|
|
69
77
|
# @return [String]
|
|
70
78
|
#
|
|
71
79
|
def css_for(*args)
|
|
@@ -73,8 +81,8 @@ module Ramaze
|
|
|
73
81
|
end
|
|
74
82
|
|
|
75
83
|
##
|
|
76
|
-
# Generates a Javascript tag that loads an external Javascript file. This
|
|
77
|
-
#
|
|
84
|
+
# Generates a Javascript tag that loads an external Javascript file. This
|
|
85
|
+
# tag can't be used for loading inline Javascript files.
|
|
78
86
|
#
|
|
79
87
|
# @example
|
|
80
88
|
#
|
|
@@ -84,11 +92,12 @@ module Ramaze
|
|
|
84
92
|
# # Let's change the directory to "some_other_directory"
|
|
85
93
|
# js 'jquery', :prefix => 'some_other_directory'
|
|
86
94
|
#
|
|
87
|
-
# @param [String] name The name of the Javascript file that should be
|
|
88
|
-
#
|
|
89
|
-
#
|
|
95
|
+
# @param [String] name The name of the Javascript file that should be
|
|
96
|
+
# loaded.
|
|
97
|
+
# @param [Hash] options Hash that can contain a :prefix key that defines
|
|
98
|
+
# the directory in which the JS file is located. By default this key is
|
|
99
|
+
# set to "js".
|
|
90
100
|
# @return [String]
|
|
91
|
-
# TODO: The js() method 2nd argument is a hash but only supports the :prefix key. Perhaps changing this hash into a string would be better - Yorick
|
|
92
101
|
#
|
|
93
102
|
def js(name, options={})
|
|
94
103
|
if name =~ /^http/ # consider it external full url
|
|
@@ -112,6 +121,6 @@ module Ramaze
|
|
|
112
121
|
def js_for(*args)
|
|
113
122
|
args.map{|arg| js(*arg) }.join("\n")
|
|
114
123
|
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
124
|
+
end # XHTML
|
|
125
|
+
end # Helper
|
|
126
|
+
end # Ramaze
|