Pistos-ramaze 2009.04.08 → 2009.06.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/MANIFEST +37 -22
- data/{README.markdown → README.md} +5 -24
- data/Rakefile +33 -26
- data/benchmark/bench_templates/bench.rb +67 -0
- data/benchmark/bench_templates/view/large.erb +79 -0
- data/benchmark/bench_templates/view/large.haml +41 -0
- data/benchmark/bench_templates/view/large.xhtml +79 -0
- data/benchmark/bench_templates/view/small.erb +21 -0
- data/benchmark/bench_templates/view/small.haml +12 -0
- data/benchmark/bench_templates/view/small.xhtml +21 -0
- data/benchmark/run.rb +14 -21
- data/benchmark/suite/minimal.rb +3 -5
- data/benchmark/suite/no_informer.rb +0 -2
- data/benchmark/suite/no_sessions.rb +3 -4
- data/benchmark/suite/no_template.rb +1 -3
- data/benchmark/suite/simple.rb +1 -3
- data/benchmark/suite/template_erubis.rb +0 -2
- data/benchmark/suite/template_etanni.rb +8 -0
- data/benchmark/suite/template_ezamar.rb +1 -3
- data/benchmark/suite/template_haml.rb +0 -2
- data/benchmark/suite/template_liquid.rb +0 -2
- data/benchmark/suite/template_markaby.rb +0 -2
- data/benchmark/suite/template_nagoro.rb +1 -3
- data/benchmark/suite/template_redcloth.rb +0 -2
- data/benchmark/suite/template_tenjin.rb +0 -2
- data/bin/ramaze +11 -163
- data/doc/AUTHORS +15 -8
- data/doc/CHANGELOG +10094 -12262
- data/doc/meta/announcement.txt +93 -46
- data/doc/tutorial/todolist.html +22 -58
- data/doc/tutorial/todolist.txt +20 -39
- data/examples/app/auth/layout/{auth.nag → auth.xhtml} +0 -0
- data/examples/app/auth/view/{index.nag → index.xhtml} +0 -0
- data/examples/app/auth/view/{login.nag → login.xhtml} +0 -0
- data/examples/app/auth/view/{secret.nag → secret.xhtml} +0 -0
- data/examples/app/blog/app.rb +1 -1
- data/examples/app/blog/controller/comment.rb +1 -1
- data/examples/app/blog/controller/entry.rb +12 -3
- data/examples/app/blog/model/init.rb +5 -0
- data/examples/app/blog/model/tag.rb +2 -2
- data/examples/app/blog/view/entry/index.nag +3 -3
- data/examples/app/blog/view/feed.atom.nag +1 -1
- data/examples/app/blog/view/feed.rss.nag +1 -1
- data/examples/app/blog/view/index.nag +1 -1
- data/examples/app/blog/view/tag/index.nag +1 -1
- data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
- data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
- data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
- data/examples/app/localization/locale/de.yaml +5 -0
- data/examples/app/localization/locale/en.yaml +5 -0
- data/examples/app/localization/locale/ja.yaml +5 -0
- data/examples/app/localization/start.rb +33 -20
- data/examples/app/wikore/spec/wikore.rb +4 -6
- data/examples/app/wikore/src/controller.rb +9 -11
- data/examples/app/wikore/src/model.rb +7 -10
- data/examples/app/wikore/start.rb +1 -1
- data/examples/app/wikore/{template → view}/index.xhtml +0 -0
- data/examples/helpers/cache.rb +6 -4
- data/examples/misc/css.rb +6 -12
- data/examples/misc/rapp.rb +28 -17
- data/lib/proto/app.rb +14 -0
- data/lib/proto/config.ru +8 -5
- data/lib/proto/controller/init.rb +3 -3
- data/lib/proto/spec/main.rb +9 -11
- data/lib/proto/start.rb +6 -10
- data/lib/ramaze.rb +8 -9
- data/lib/ramaze/app.rb +4 -3
- data/lib/ramaze/cache/localmemcache.rb +2 -2
- data/lib/ramaze/cache/memcache.rb +26 -1
- data/lib/ramaze/cache/sequel.rb +24 -9
- data/lib/ramaze/contrib/addressable_route.rb +56 -0
- data/lib/ramaze/contrib/email.rb +2 -0
- data/lib/ramaze/contrib/facebook/facebook.rb +4 -4
- data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
- data/lib/ramaze/contrib/sequel/image.rb +9 -11
- data/lib/ramaze/contrib/sequel/relation.rb +17 -3
- data/lib/ramaze/controller.rb +26 -18
- data/lib/ramaze/gestalt.rb +4 -1
- data/lib/ramaze/helper.rb +1 -0
- data/lib/ramaze/helper/auth.rb +0 -5
- data/lib/ramaze/helper/cache.rb +65 -25
- data/lib/ramaze/helper/form.rb +14 -2
- data/lib/ramaze/helper/formatting.rb +3 -1
- data/lib/ramaze/helper/gestalt.rb +32 -0
- data/lib/ramaze/helper/identity.rb +3 -3
- data/lib/ramaze/helper/layout.rb +97 -0
- data/lib/ramaze/helper/link.rb +6 -25
- data/lib/ramaze/helper/localize.rb +13 -3
- data/lib/ramaze/helper/paginate.rb +4 -2
- data/lib/ramaze/helper/ultraviolet.rb +2 -0
- data/lib/ramaze/helper/user.rb +3 -3
- data/lib/ramaze/log/rotatinginformer.rb +10 -10
- data/lib/ramaze/request.rb +3 -5
- data/lib/ramaze/setup.rb +22 -9
- data/lib/ramaze/spec.rb +8 -12
- data/lib/ramaze/spec/bacon.rb +34 -0
- data/lib/ramaze/spec/helper/template_examples.rb +15 -22
- data/lib/ramaze/tool/bin.rb +340 -0
- data/lib/ramaze/tool/project_creator.rb +1 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +6 -11
- data/lib/ramaze/view/erubis.rb +2 -2
- data/lib/ramaze/view/ezamar.rb +2 -2
- data/lib/ramaze/view/gestalt.rb +14 -0
- data/lib/ramaze/view/haml.rb +2 -1
- data/lib/ramaze/view/liquid.rb +45 -11
- data/lib/ramaze/view/maruku.rb +2 -1
- data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/tenjin.rb +7 -4
- data/lib/vendor/etag.rb +4 -2
- data/lib/vendor/route_exceptions.rb +9 -15
- data/ramaze.gemspec +56 -9
- data/spec/contrib/addressable_route.rb +30 -0
- data/spec/contrib/rest.rb +2 -2
- data/spec/examples/caching.rb +5 -7
- data/spec/examples/css.rb +3 -3
- data/spec/examples/element.rb +4 -3
- data/spec/examples/hello.rb +3 -3
- data/spec/examples/helpers/httpdigest.rb +44 -69
- data/spec/examples/linking.rb +3 -3
- data/spec/examples/simple.rb +3 -3
- data/spec/examples/templates/template_erubis.rb +8 -4
- data/spec/examples/templates/template_ezamar.rb +9 -4
- data/spec/examples/templates/template_haml.rb +8 -4
- data/spec/examples/templates/template_liquid.rb +8 -4
- data/spec/examples/templates/template_markaby.rb +9 -5
- data/spec/examples/templates/template_nagoro.rb +9 -5
- data/spec/examples/templates/template_redcloth.rb +8 -4
- data/spec/examples/templates/template_remarkably.rb +8 -4
- data/spec/examples/templates/template_tenjin.rb +8 -4
- data/spec/helper.rb +1 -2
- data/spec/ramaze/action/render.rb +4 -1
- data/spec/ramaze/app.rb +5 -2
- data/spec/ramaze/bin/ramaze.rb +96 -0
- data/spec/ramaze/cache/localmemcache.rb +1 -1
- data/spec/ramaze/cache/memcache.rb +7 -1
- data/spec/ramaze/cache/sequel.rb +1 -1
- data/spec/ramaze/controller/actionless_templates.rb +2 -2
- data/spec/ramaze/controller/lonely_mapping.rb +18 -0
- data/spec/ramaze/controller/mapping.rb +4 -15
- data/spec/ramaze/controller/provide_inheritance.rb +5 -2
- data/spec/ramaze/controller/resolve.rb +2 -2
- data/spec/ramaze/controller/subclass.rb +2 -2
- data/spec/ramaze/controller/template_resolving.rb +2 -2
- data/spec/ramaze/dispatcher/directory.rb +5 -2
- data/spec/ramaze/dispatcher/file.rb +28 -26
- data/spec/ramaze/error.rb +3 -3
- data/spec/ramaze/files.rb +5 -2
- data/spec/ramaze/gestalt.rb +26 -17
- data/spec/ramaze/helper/auth.rb +30 -41
- data/spec/ramaze/helper/bench.rb +6 -2
- data/spec/ramaze/helper/cache.rb +45 -5
- data/spec/ramaze/helper/flash.rb +11 -15
- data/spec/ramaze/helper/form.rb +6 -3
- data/spec/ramaze/helper/formatting.rb +4 -1
- data/spec/ramaze/helper/gestalt.rb +4 -1
- data/spec/ramaze/helper/gravatar.rb +4 -1
- data/spec/ramaze/helper/httpdigest.rb +51 -66
- data/spec/ramaze/helper/layout.rb +79 -0
- data/spec/ramaze/helper/layout/default.xhtml +5 -0
- data/spec/ramaze/helper/link.rb +33 -12
- data/spec/ramaze/helper/localize.rb +9 -4
- data/spec/ramaze/helper/maruku.rb +5 -2
- data/spec/ramaze/helper/pager.rb +2 -2
- data/spec/ramaze/helper/paginate.rb +5 -2
- data/spec/ramaze/helper/request_accessor.rb +5 -2
- data/spec/ramaze/helper/sequel_form.rb +7 -2
- data/spec/ramaze/helper/simple_captcha.rb +10 -14
- data/spec/ramaze/helper/stack.rb +32 -40
- data/spec/ramaze/helper/user.rb +19 -14
- data/spec/ramaze/helper/xhtml.rb +4 -1
- data/spec/ramaze/log/informer.rb +1 -1
- data/spec/ramaze/log/logging.rb +4 -1
- data/spec/ramaze/log/syslog.rb +6 -6
- data/spec/ramaze/params.rb +5 -6
- data/spec/ramaze/request.rb +16 -1
- data/spec/ramaze/session/memcache.rb +66 -0
- data/spec/ramaze/struct.rb +4 -1
- data/spec/ramaze/view.rb +2 -2
- data/spec/ramaze/view/erubis.rb +2 -2
- data/spec/ramaze/view/ezamar.rb +2 -2
- data/spec/ramaze/view/gestalt.rb +94 -0
- data/spec/ramaze/view/gestalt/external.ges +8 -0
- data/spec/ramaze/view/haml.rb +2 -2
- data/spec/ramaze/view/liquid.rb +2 -2
- data/spec/ramaze/view/nagoro.rb +2 -2
- data/spec/ramaze/view/redcloth.rb +2 -2
- data/spec/ramaze/view/remarkably.rb +2 -2
- data/spec/ramaze/view/sass.rb +2 -2
- data/spec/ramaze/view/tagz.rb +2 -2
- data/spec/ramaze/view/tenjin.rb +2 -2
- data/spec/snippets/array/put_within.rb +30 -25
- data/spec/snippets/binding/locals.rb +4 -1
- data/spec/snippets/numeric/filesize_format.rb +4 -1
- data/spec/snippets/numeric/time.rb +5 -2
- data/spec/snippets/object/__dir__.rb +4 -1
- data/spec/snippets/ordered_set.rb +4 -1
- data/spec/snippets/ramaze/acquire.rb +4 -1
- data/spec/snippets/ramaze/dictionary.rb +4 -1
- data/spec/snippets/ramaze/struct.rb +4 -1
- data/spec/snippets/string/camel_case.rb +4 -1
- data/spec/snippets/string/color.rb +4 -1
- data/spec/snippets/string/snake_case.rb +4 -1
- data/spec/snippets/string/unindent.rb +4 -1
- data/spec/snippets/thread/into.rb +4 -1
- data/tasks/bacon.rake +5 -3
- data/tasks/changelog.rake +3 -1
- data/tasks/{gem_installer.rake → gem_setup.rake} +45 -22
- data/tasks/release.rake +12 -27
- data/tasks/setup.rake +6 -0
- data/tasks/todo.rake +2 -4
- metadata +205 -31
- data/CHANGELOG +0 -16546
- data/benchmark/suite/template_builder.rb +0 -12
- data/doc/tutorial/todolist.mkd +0 -787
- data/examples/helpers/provide.rb +0 -23
- data/lib/proto/view/page.xhtml +0 -27
- data/lib/ramaze/snippets/divide.rb +0 -22
- data/lib/ramaze/snippets/kernel/constant.rb +0 -41
- data/lib/ramaze/snippets/object/acquire.rb +0 -37
- data/lib/ramaze/snippets/string/each.rb +0 -19
- data/spec/ramaze/helper/partial.rb +0 -40
- data/spec/snippets/kernel/constant.rb +0 -23
- data/tasks/install_dependencies.rake +0 -6
data/lib/ramaze/helper/link.rb
CHANGED
@@ -7,39 +7,20 @@ module Ramaze
|
|
7
7
|
module Helper
|
8
8
|
# This is a modification of Innate::Helper::Link to respect the routing of
|
9
9
|
# Ramaze
|
10
|
+
#
|
10
11
|
# NOTE: The A/R/Rs methods have been deprecated.
|
11
12
|
module Link
|
12
|
-
|
13
|
-
# @return [String]
|
14
|
-
# @see Innate::Helper#anchor
|
15
|
-
def A(*args)
|
16
|
-
Ramaze.deprecated('Ramaze::Helper::Link#A', 'Ramaze::Helper::Link#a')
|
17
|
-
a(*args)
|
18
|
-
end
|
19
|
-
|
20
|
-
# @return [String]
|
21
|
-
# @see Innate::Helper#route
|
22
|
-
def R(arg, *args)
|
23
|
-
Ramaze.deprecated('Ramaze::Helper::Link#R', 'Ramaze::Helper::Link#r')
|
24
|
-
(arg < Controller ? arg.r(*args) : r(arg, *args)).to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [String]
|
28
|
-
# @see Innate::Helper#route
|
29
|
-
def Rs(*args)
|
30
|
-
Ramaze.deprecated('Ramaze::Helper::Link#Rs', 'Ramaze::Helper::Link#r')
|
31
|
-
r(*args).to_s
|
32
|
-
end
|
33
|
-
|
34
13
|
def route_location(klass)
|
35
|
-
|
14
|
+
prefix = Ramaze.options.prefix
|
15
|
+
location = Ramaze.to(klass) || Ramaze.to(klass.class)
|
16
|
+
[prefix, location].join('/')
|
36
17
|
end
|
37
18
|
|
38
19
|
# Give it a path with character to split at and one to join the crumbs with.
|
39
20
|
# It will generate a list of links that act as pointers to previous pages on
|
40
21
|
# this path.
|
41
22
|
#
|
42
|
-
#
|
23
|
+
# @example usage
|
43
24
|
# breadcrumbs('/path/to/somewhere')
|
44
25
|
#
|
45
26
|
# # results in this, newlines added for readability:
|
@@ -51,7 +32,7 @@ module Ramaze
|
|
51
32
|
# Optionally a href prefix can be specified which generate link
|
52
33
|
# names a above, but with the prefix prepended to the href path.
|
53
34
|
#
|
54
|
-
#
|
35
|
+
# @example usage
|
55
36
|
# breadcrumbs('/path/to/somewhere', '/', '/', '/mycontroller/action')
|
56
37
|
#
|
57
38
|
# # results in this, newlines added for readability:
|
@@ -19,7 +19,12 @@ module Ramaze
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def locales
|
22
|
-
|
22
|
+
locales = request.env['localize.locales']
|
23
|
+
return locales if locales
|
24
|
+
|
25
|
+
fallback = ancestral_trait[:localize_locale]
|
26
|
+
locales = Parser.new(request).locales(fallback)
|
27
|
+
request.env['localize.locales'] = locales
|
23
28
|
end
|
24
29
|
|
25
30
|
class Dictionary
|
@@ -105,7 +110,7 @@ module Ramaze
|
|
105
110
|
end
|
106
111
|
|
107
112
|
def parse
|
108
|
-
parse_params || parse_cookie || parse_header
|
113
|
+
parse_params || parse_session || parse_cookie || parse_header
|
109
114
|
end
|
110
115
|
|
111
116
|
def parse_params(key = 'lang')
|
@@ -113,13 +118,18 @@ module Ramaze
|
|
113
118
|
::Locale::Tag.parse(lang)
|
114
119
|
end
|
115
120
|
|
121
|
+
def parse_session(key = :lang)
|
122
|
+
return unless lang = Current.session[key]
|
123
|
+
::Locale::Tag.parse(lang)
|
124
|
+
end
|
125
|
+
|
116
126
|
def parse_cookie(key = 'lang')
|
117
127
|
return unless lang = request.cookies[key]
|
118
128
|
::Locale::Tag.parse(lang)
|
119
129
|
end
|
120
130
|
|
121
131
|
def parse_header
|
122
|
-
request.
|
132
|
+
request.accept_language.map{|lang|
|
123
133
|
::Locale::Tag.parse(lang) }
|
124
134
|
end
|
125
135
|
end
|
@@ -134,7 +134,7 @@ module Ramaze
|
|
134
134
|
end
|
135
135
|
|
136
136
|
out << '</div>'
|
137
|
-
out.
|
137
|
+
out.join
|
138
138
|
end
|
139
139
|
|
140
140
|
# Useful to omit pager if it's of no use.
|
@@ -154,6 +154,8 @@ module Ramaze
|
|
154
154
|
def last_page; @pager.last_page; end
|
155
155
|
def last_page?; @pager.last_page?; end
|
156
156
|
def next_page; @pager.next_page; end
|
157
|
+
def empty?; @pager.empty?; end
|
158
|
+
def count; @pager.count; end
|
157
159
|
|
158
160
|
private
|
159
161
|
|
@@ -173,7 +175,7 @@ module Ramaze
|
|
173
175
|
|
174
176
|
action = Current.action
|
175
177
|
params = request.params.merge(@var.to_s => n)
|
176
|
-
hash[:href] = action.node.r(action.
|
178
|
+
hash[:href] = action.node.r(action.path, params)
|
177
179
|
|
178
180
|
g.a(hash){ text }
|
179
181
|
end
|
data/lib/ramaze/helper/user.rb
CHANGED
@@ -170,7 +170,7 @@ module Ramaze
|
|
170
170
|
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
171
171
|
# model or callback
|
172
172
|
# @see Ramaze::Helper::User#user_login
|
173
|
-
# @
|
173
|
+
# @author manveru
|
174
174
|
def _login(creds = _persistence)
|
175
175
|
if @_user = _would_login?(creds)
|
176
176
|
self._persistence = creds
|
@@ -195,7 +195,7 @@ module Ramaze
|
|
195
195
|
|
196
196
|
# @api internal
|
197
197
|
# @see Ramaze::Helper::User#user_logout
|
198
|
-
# @
|
198
|
+
# @author manveru
|
199
199
|
def _logout
|
200
200
|
_persistence.clear
|
201
201
|
Current.request.env['ramaze.helper.user'] = nil
|
@@ -204,7 +204,7 @@ module Ramaze
|
|
204
204
|
# @return [true false] whether the current user is logged in.
|
205
205
|
# @api internal
|
206
206
|
# @see Ramaze::Helper::User#logged_in?
|
207
|
-
# @
|
207
|
+
# @author manveru
|
208
208
|
def _logged_in?
|
209
209
|
!!_user
|
210
210
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Ramaze
|
2
|
-
|
2
|
+
|
3
3
|
module Logger
|
4
4
|
|
5
5
|
# A customized logger (based on Informer) that creates multiple log files based on time
|
6
6
|
|
7
7
|
class RotatingInformer
|
8
|
-
|
8
|
+
include Innate::Traited
|
9
9
|
include Logging
|
10
10
|
|
11
11
|
attr_accessor :time_format, :log_levels
|
12
12
|
attr_reader :base_dir
|
13
|
-
|
13
|
+
|
14
14
|
# parameter for Time.now.strftime
|
15
15
|
trait :timestamp => "%Y-%m-%d %H:%M:%S"
|
16
16
|
|
@@ -47,24 +47,24 @@ module Ramaze
|
|
47
47
|
def initialize(base_dir, time_format = '%Y-%m-%d.log', log_levels = [:debug, :error, :info, :warn])
|
48
48
|
# Verify and set base directory
|
49
49
|
send :base_dir=, base_dir, true
|
50
|
-
|
50
|
+
|
51
51
|
@time_format = time_format
|
52
52
|
@log_levels = log_levels
|
53
|
-
|
53
|
+
|
54
54
|
# Keep track of log shutdown (to prevent StackErrors due to recursion)
|
55
55
|
@in_shutdown = false
|
56
56
|
end
|
57
57
|
|
58
58
|
# Set the base directory for log files
|
59
|
-
#
|
59
|
+
#
|
60
60
|
# If this method is called with the raise_exception
|
61
61
|
# parameter set to true the method will raise an exception
|
62
62
|
# if the specified directory does not exist or is unwritable.
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# If raise_exception is set to false, the method will just
|
65
65
|
# silently fail if the specified directory does not exist
|
66
66
|
# or is unwritable
|
67
|
-
|
67
|
+
|
68
68
|
def base_dir=(directory, raise_exception = false)
|
69
69
|
# Expand directory path
|
70
70
|
base_dir = File.expand_path(directory)
|
@@ -85,7 +85,7 @@ module Ramaze
|
|
85
85
|
raise Exception.new("#{base_dir} does not exist.") if raise_exception
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
# Close the file we log to if it isn't closed already.
|
90
90
|
|
91
91
|
def shutdown
|
@@ -106,7 +106,7 @@ module Ramaze
|
|
106
106
|
return unless @log_levels.include?(tag)
|
107
107
|
|
108
108
|
# Update current log
|
109
|
-
update_current_log
|
109
|
+
update_current_log
|
110
110
|
|
111
111
|
messages.flatten!
|
112
112
|
|
data/lib/ramaze/request.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
3
|
|
4
4
|
module Ramaze
|
5
5
|
# The purpose of this class is to act as a simple wrapper for Rack::Request
|
6
6
|
# and provide some convinient methods for our own use.
|
7
7
|
class Request < Innate::Request
|
8
|
-
# Currently active request out of STATE[:request]
|
9
|
-
def self.current; Current.request; end
|
10
8
|
|
11
9
|
# you can access the original @request via this method_missing,
|
12
10
|
# first it tries to match your method with any of the HTTP parameters
|
13
11
|
# then, in case that fails, it will relay to @request
|
14
|
-
|
15
12
|
def method_missing meth, *args
|
16
13
|
key = meth.to_s.upcase
|
17
14
|
return env[key] if env.has_key?(key)
|
@@ -27,13 +24,14 @@ module Ramaze
|
|
27
24
|
# @name # => 'manveru'
|
28
25
|
# @lang # => nil
|
29
26
|
|
30
|
-
def
|
27
|
+
def to_instance_variables(*args)
|
31
28
|
instance = Action.current.instance
|
32
29
|
args.each do |arg|
|
33
30
|
next unless value = self[arg]
|
34
31
|
instance.instance_variable_set("@#{arg}", value)
|
35
32
|
end
|
36
33
|
end
|
34
|
+
alias to_ivs to_instance_variables
|
37
35
|
|
38
36
|
def accept_charset(default = 'UTF-8')
|
39
37
|
return default unless charsets = env['HTTP_ACCEPT_CHARSET']
|
data/lib/ramaze/setup.rb
CHANGED
@@ -4,7 +4,8 @@ module Ramaze
|
|
4
4
|
# It's almost like Kernel#gem but also installs automatically if a gem is
|
5
5
|
# missing.
|
6
6
|
#
|
7
|
-
# @
|
7
|
+
# @example
|
8
|
+
#
|
8
9
|
# Ramaze.setup :verbose => true do
|
9
10
|
# # gem and specific version
|
10
11
|
# gem 'makura', '>=2009.01'
|
@@ -65,14 +66,20 @@ module Ramaze
|
|
65
66
|
|
66
67
|
# first try to activate, install and try to activate again if activation
|
67
68
|
# fails the first time
|
68
|
-
def setup_gem(name, options
|
69
|
+
def setup_gem(name, options)
|
70
|
+
version = [options[:version]].compact
|
71
|
+
lib_name = options[:lib] || name
|
72
|
+
|
69
73
|
log "activating #{name}"
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
|
75
|
+
Gem.activate(name, *version)
|
76
|
+
require(lib_name)
|
77
|
+
|
78
|
+
rescue LoadError
|
79
|
+
|
80
|
+
install_gem(name, options)
|
81
|
+
Gem.activate(name, *version)
|
82
|
+
require(lib_name)
|
76
83
|
end
|
77
84
|
|
78
85
|
# tell rubygems to install a gem
|
@@ -101,7 +108,13 @@ module Ramaze
|
|
101
108
|
private
|
102
109
|
|
103
110
|
def log(msg)
|
104
|
-
|
111
|
+
return unless @verbose
|
112
|
+
|
113
|
+
if defined?(Log)
|
114
|
+
Log.info(msg)
|
115
|
+
else
|
116
|
+
puts(msg)
|
117
|
+
end
|
105
118
|
end
|
106
119
|
|
107
120
|
def rubyforge; 'http://gems.rubyforge.org/' end
|
data/lib/ramaze/spec.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'bacon'
|
3
|
-
|
4
|
-
require 'innate/spec'
|
1
|
+
require File.expand_path('../', __FILE__) unless defined?(Ramaze)
|
5
2
|
|
6
3
|
def spec_requires(*libs)
|
7
4
|
spec_precondition 'require' do
|
@@ -26,12 +23,11 @@ module Ramaze
|
|
26
23
|
middleware!(:spec){|m| m.run(AppMap) }
|
27
24
|
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
26
|
+
# FIXME: will remove that in 2009.07, and then we can offer integration with
|
27
|
+
# any other test-framework we like and they can share this code.
|
28
|
+
# Then Ramaze can be:
|
29
|
+
# Any ruby, any ORM, any templating-engine, any test-framework
|
30
|
+
unless defined?(Bacon)
|
31
|
+
Ramaze.deprecated "require('ramaze/spec')", "require('ramaze/spec/bacon')"
|
32
|
+
require 'ramaze/spec/bacon'
|
37
33
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bacon'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bacon'
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.expand_path('../', __FILE__) unless defined?(Ramaze)
|
9
|
+
|
10
|
+
require 'innate/spec/bacon'
|
11
|
+
|
12
|
+
shared :rack_test do
|
13
|
+
Ramaze.setup_dependencies
|
14
|
+
extend Rack::Test::Methods
|
15
|
+
|
16
|
+
def app; Ramaze; end
|
17
|
+
end
|
18
|
+
|
19
|
+
shared :webrat do
|
20
|
+
behaves_like :rack_test
|
21
|
+
|
22
|
+
require 'webrat'
|
23
|
+
|
24
|
+
Webrat.configure{|config| config.mode = :rack_test }
|
25
|
+
|
26
|
+
extend Webrat::Methods
|
27
|
+
extend Webrat::Matchers
|
28
|
+
end
|
29
|
+
|
30
|
+
# Backwards compatibility
|
31
|
+
shared(:mock){
|
32
|
+
Ramaze.deprecated('behaves_like(:mock)', 'behaves_like(:rack_test)')
|
33
|
+
behaves_like :rack_test
|
34
|
+
}
|
@@ -1,28 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Examples
|
4
|
-
module Templates
|
5
|
-
def self.tests( describe, spec_engine )
|
1
|
+
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
6
3
|
|
7
|
-
|
4
|
+
shared :template_spec do
|
5
|
+
behaves_like :rack_test
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
%w[/internal /external].each do |url|
|
15
|
-
describe.it url do
|
16
|
-
html = get(url).body
|
17
|
-
html.should.not == nil
|
18
|
-
html.should =~ %r{<title>Template::#{spec_engine} (internal|external)</title>}
|
19
|
-
html.should =~ %r{<h1>The (internal|external) Template for #{spec_engine}</h1>}
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
7
|
+
def spec_template(spec_engine)
|
8
|
+
it 'works on /' do
|
9
|
+
get('/').body.strip.
|
10
|
+
should =~ %r{<a href\s*=\s*"/">Home</a>\s+\|\s+<a href\s*=\s*"/internal">internal</a>\s+\|\s+<a href\s*=\s*"/external">external</a>}
|
11
|
+
end
|
25
12
|
|
13
|
+
%w[/internal /external].each do |url|
|
14
|
+
it "works on #{url}" do
|
15
|
+
html = get(url).body
|
16
|
+
html.should.not == nil
|
17
|
+
html.should =~ %r{<title>Template::#{spec_engine} (internal|external)</title>}
|
18
|
+
html.should =~ %r{<h1>The (internal|external) Template for #{spec_engine}</h1>}
|
26
19
|
end
|
27
20
|
end
|
28
21
|
end
|
@@ -0,0 +1,340 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
### This module offers the functionality to start, stop, restart, create,
|
3
|
+
### Check status, or run a console of a ramaze application
|
4
|
+
### see ramaze -h for usage
|
5
|
+
module Ramaze
|
6
|
+
module Tool
|
7
|
+
module Bin
|
8
|
+
module Helpers # Helper methods {{{
|
9
|
+
|
10
|
+
def default_pidfile # {{{
|
11
|
+
return @default_pidfile if @default_pidfile
|
12
|
+
require "pathname"
|
13
|
+
@default_pidfile = (Pathname.new(".").expand_path.basename.to_s + ".pid").strip
|
14
|
+
end # }}}
|
15
|
+
|
16
|
+
# We're really only concerned about win32ole, so we focus our check on its
|
17
|
+
# ability to load that
|
18
|
+
def is_windows? # {{{
|
19
|
+
return @is_win if @is_win
|
20
|
+
begin
|
21
|
+
require "win32ole"
|
22
|
+
rescue LoadError
|
23
|
+
end
|
24
|
+
@is_win ||= Object.const_defined?("WIN32OLE")
|
25
|
+
end # }}}
|
26
|
+
|
27
|
+
# Find the path to rackup, by searching for -R (undocumented cli argument),
|
28
|
+
# then checking RUBYLIB for the _first_ rack it can find there, finally
|
29
|
+
# falling back to gems and looking for rackup in the gem bindir.
|
30
|
+
# If we can't find rackup we're raising; not even #usage is sane without
|
31
|
+
# rackup.
|
32
|
+
def rackup_path # {{{
|
33
|
+
return @rackup_path if @rackup_path
|
34
|
+
# Use the supplied path if the user supplied -R
|
35
|
+
if path_supplied = ARGV.delete("-R")
|
36
|
+
@rackup_path = ARGV.delete(@ourargs[@ourargs.index("-R") + 1])
|
37
|
+
if @rackup_path and File.file?(@rackup_path)
|
38
|
+
return @rackup_path
|
39
|
+
else
|
40
|
+
$stderr.puts "rackup does not exist at #{@rackup_path} (given with -R)"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# Check with 'which' on platforms which support it
|
44
|
+
unless is_windows?
|
45
|
+
@rackup_path = %x{which rackup}.to_s.chomp
|
46
|
+
if @rackup_path.size > 0 and File.file?(@rackup_path)
|
47
|
+
return @rackup_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
# check for rackup in RUBYLIB
|
51
|
+
libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
|
52
|
+
if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
|
53
|
+
require "pathname"
|
54
|
+
@rackup_path = Pathname.new(rack_lib).parent.join("bin").join("rackup").expand_path
|
55
|
+
return @rackup_path if File.file?(@rackup_path)
|
56
|
+
end
|
57
|
+
begin
|
58
|
+
require "rubygems"
|
59
|
+
require "rack"
|
60
|
+
require "pathname"
|
61
|
+
@rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
|
62
|
+
return @rackup_path if File.file?(@rackup_path)
|
63
|
+
rescue LoadError
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
@rackup_path = nil
|
67
|
+
raise "Cannot find path to rackup, please supply full path to rackup with -R"
|
68
|
+
end # }}}
|
69
|
+
|
70
|
+
def is_running?(pid) # {{{
|
71
|
+
if is_windows?
|
72
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
73
|
+
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
74
|
+
processes.each { |process| ours << process.Name }
|
75
|
+
ours.first.nil?
|
76
|
+
else
|
77
|
+
begin
|
78
|
+
prio = Process.getpriority(Process::PRIO_PROCESS, pid)
|
79
|
+
true
|
80
|
+
rescue Errno::ESRCH
|
81
|
+
false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end # }}}
|
85
|
+
|
86
|
+
def check_running?(pid_file) # {{{
|
87
|
+
return false unless File.file?(pid_file)
|
88
|
+
is_running?(File.read(pid_file).to_i)
|
89
|
+
end # }}}
|
90
|
+
|
91
|
+
def find_pid(pid_file) # {{{
|
92
|
+
if pid_file.nil? or not File.file?(pid_file)
|
93
|
+
pid_file = default_pidfile
|
94
|
+
end
|
95
|
+
unless File.file?(pid_file)
|
96
|
+
$stderr.puts "Could not find running process id."
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
pid_file
|
100
|
+
end # }}}
|
101
|
+
end # End helper methods }}}
|
102
|
+
|
103
|
+
class Cmd # This class contains the command methods {{{
|
104
|
+
include Helpers
|
105
|
+
attr_accessor :command
|
106
|
+
|
107
|
+
def initialize(args = nil)
|
108
|
+
args ||= ARGV
|
109
|
+
raise "arguments must be an array!" unless args.respond_to?(:detect)
|
110
|
+
@ourargs = args.dup
|
111
|
+
@command = args.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console|status)/) }
|
112
|
+
if command.nil?
|
113
|
+
@command = ""
|
114
|
+
else
|
115
|
+
args.delete(@command)
|
116
|
+
end
|
117
|
+
ARGV.replace(args)
|
118
|
+
end
|
119
|
+
|
120
|
+
# {{{ #run is called when we're interactive ($0 == __FILE__)
|
121
|
+
def self.run(args = nil)
|
122
|
+
cmd = new(args)
|
123
|
+
case cmd.command
|
124
|
+
when /^(?:--?)?status$/
|
125
|
+
cmd.status(cmd.command)
|
126
|
+
when /^(?:--?)?restart$/
|
127
|
+
cmd.stop(cmd.command)
|
128
|
+
cmd.start
|
129
|
+
when /^(?:--?)?start$/
|
130
|
+
cmd.start
|
131
|
+
when /^(?:--?)?create$/
|
132
|
+
cmd.create(cmd.command)
|
133
|
+
when /^(?:--?)?stop$/
|
134
|
+
if cmd.stop(cmd.command)
|
135
|
+
puts "Ramazement has ended, go in peace."
|
136
|
+
$stdout.flush
|
137
|
+
else
|
138
|
+
puts "Ramaze failed to stop (or was not running)"
|
139
|
+
end
|
140
|
+
when /^(?:--?)?console$/
|
141
|
+
require "ramaze"
|
142
|
+
require "irb"
|
143
|
+
require "irb/completion"
|
144
|
+
Ramaze.options.started = true
|
145
|
+
require "start"
|
146
|
+
IRB.start
|
147
|
+
puts "Ramazement has ended, go in peace."
|
148
|
+
when /^(?:--?)?h(elp)?$/
|
149
|
+
puts cmd.usage
|
150
|
+
when /^(?:--?)?v(ersion)?$/
|
151
|
+
cmd.include_ramaze
|
152
|
+
puts Ramaze::VERSION
|
153
|
+
exit
|
154
|
+
when /^$/
|
155
|
+
puts "Must supply a valid command"
|
156
|
+
puts cmd.usage
|
157
|
+
exit 1
|
158
|
+
else
|
159
|
+
puts "#{command} not implemented"
|
160
|
+
puts cmd.usage
|
161
|
+
exit 1
|
162
|
+
end
|
163
|
+
end # }}}
|
164
|
+
|
165
|
+
def include_ramaze # {{{
|
166
|
+
begin
|
167
|
+
$:.unshift File.join(File.dirname(__FILE__), '/../lib')
|
168
|
+
require 'ramaze'
|
169
|
+
rescue LoadError
|
170
|
+
$:.shift
|
171
|
+
|
172
|
+
begin
|
173
|
+
require 'rubygems'
|
174
|
+
rescue LoadError
|
175
|
+
end
|
176
|
+
require 'ramaze'
|
177
|
+
end
|
178
|
+
end # }}}
|
179
|
+
|
180
|
+
def usage # {{{
|
181
|
+
txt = [
|
182
|
+
"\n Usage:",
|
183
|
+
"ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|status [PIDFILE]|create PROJECT|console> [ruby/rack options]\n",
|
184
|
+
"Commands:\n",
|
185
|
+
" * All commands which take an optional PIDFILE (defaults to PROJECT.pid otherwise).",
|
186
|
+
" * All commands which start a ramaze instance will default to webrick on port 7000",
|
187
|
+
" unless you supply the rack options -p/--port PORT and/or * -s/--server SERVER.\n",
|
188
|
+
" start - Starts an instance of this application.\n",
|
189
|
+
" stop - Stops a running instance of this application.\n",
|
190
|
+
" restart - Stops running instance of this application, then starts it back up. Pidfile",
|
191
|
+
" (if supplied) is used for both stop and start.\n",
|
192
|
+
" status - Gives status of a running ramaze instance\n",
|
193
|
+
" create - Creates a new prototype Ramaze application in a directory named PROJECT in",
|
194
|
+
" the current directory. ramaze create foo would make ./foo containing an",
|
195
|
+
" application prototype. Rack options are ignored here.\n",
|
196
|
+
" console - Starts an irb console with app.rb (and irb completion) loaded. This command",
|
197
|
+
" ignores rack options, ARGV is passed on to IRB.\n\n\t"
|
198
|
+
].join("\n\t")
|
199
|
+
|
200
|
+
if is_windows?
|
201
|
+
txt << %x{ruby #{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
|
202
|
+
else
|
203
|
+
txt << %x{#{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
|
204
|
+
end
|
205
|
+
|
206
|
+
txt.gsub(/^\t$/, '')
|
207
|
+
end # }}}
|
208
|
+
|
209
|
+
### Methods for commands {{{
|
210
|
+
def start # {{{
|
211
|
+
include_ramaze
|
212
|
+
|
213
|
+
# Find the name of this app
|
214
|
+
app_name = default_pidfile.sub(/\.pid$/,'')
|
215
|
+
rack_args = []
|
216
|
+
|
217
|
+
if daemonize = @ourargs.detect { |arg| arg.match(/^(-[dD]|--daemonize)$/) }
|
218
|
+
if pid_arg = @ourargs.detect { |arg| arg.match(/^(-P|--pid)/) }
|
219
|
+
puts "User supplied pid: #{pid_arg}"
|
220
|
+
pid_file = @ourargs[@ourargs.index(pid_arg) + 1]
|
221
|
+
puts "Starting daemon with user defined pidfile: #{pid_file}"
|
222
|
+
else
|
223
|
+
puts "Starting daemon with default pidfile: #{pid_file = default_pidfile}"
|
224
|
+
rack_args += ["-P", pid_file]
|
225
|
+
end
|
226
|
+
if check_running?(pid_file)
|
227
|
+
$stderr.puts "Ramaze is already running with pidfile: #{pid_file}"
|
228
|
+
exit 127
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
port = Ramaze.options.adapter.port.to_s
|
233
|
+
rack_args += ["-p", port ] if @ourargs.grep(/^(-p|--port)/).empty?
|
234
|
+
|
235
|
+
handler = Ramaze.options.adapter.handler.to_s
|
236
|
+
rack_args += ["-s", handler] if @ourargs.grep(/^(-s|--server)/).empty?
|
237
|
+
|
238
|
+
if is_windows?
|
239
|
+
exec("ruby", rackup_path.to_s, "config.ru", *(ARGV + rack_args))
|
240
|
+
else
|
241
|
+
exec(rackup_path.to_s, "config.ru", *(ARGV + rack_args))
|
242
|
+
end
|
243
|
+
end # }}}
|
244
|
+
|
245
|
+
def create(command) # {{{
|
246
|
+
opts = {}
|
247
|
+
if forced = @ourargs.detect { |arg| arg.match(/^(--force)/) }
|
248
|
+
puts "Overwriting any existing files as requested."
|
249
|
+
opts[:force] = true
|
250
|
+
@ourargs.delete(forced)
|
251
|
+
end
|
252
|
+
if amended = @ourargs.detect { |arg| arg.match(/^(--amend)/) }
|
253
|
+
puts "Only amending missing files as requested."
|
254
|
+
opts[:amend] = true
|
255
|
+
@ourargs.delete(amended)
|
256
|
+
end
|
257
|
+
project_name = @ourargs[@ourargs.index(command) + 1]
|
258
|
+
if project_name.nil?
|
259
|
+
$stderr.puts "Must supply a project name" if project_name.nil?
|
260
|
+
puts usage
|
261
|
+
exit 1
|
262
|
+
end
|
263
|
+
include_ramaze
|
264
|
+
require 'ramaze/tool/create'
|
265
|
+
Ramaze::Tool::Create.create(project_name, opts)
|
266
|
+
end # }}}
|
267
|
+
|
268
|
+
def stop(command) # {{{
|
269
|
+
unless pid_file = find_pid(@ourargs[@ourargs.index(command) + 1])
|
270
|
+
$stderr.puts "No pid_file found! Cannot stop ramaze (may not be started)."
|
271
|
+
return false
|
272
|
+
end
|
273
|
+
pid = File.read(pid_file).to_i
|
274
|
+
puts "Stopping pid #{pid}"
|
275
|
+
Process.kill("INT", pid)
|
276
|
+
sleep 2
|
277
|
+
if is_running?(pid)
|
278
|
+
$stderr.puts "Process #{pid} did not die, forcing it with -9"
|
279
|
+
Process.kill(9, pid)
|
280
|
+
File.unlink(pid_file) if File.file?(pid_file)
|
281
|
+
true
|
282
|
+
else
|
283
|
+
File.unlink(pid_file) if File.file?(pid_file)
|
284
|
+
true
|
285
|
+
end
|
286
|
+
end # }}}
|
287
|
+
|
288
|
+
def status(command) # {{{
|
289
|
+
unless pid_file = find_pid(@ourargs[@ourargs.index(command) + 1])
|
290
|
+
$stderr.puts "No pid_file found! Ramaze may not be started."
|
291
|
+
exit 1
|
292
|
+
end
|
293
|
+
puts "Pid file #{pid_file} found, PID is #{pid = File.read(pid_file)}"
|
294
|
+
unless is_running?(pid.to_i)
|
295
|
+
$stderr.puts "PID #{pid} is not running"
|
296
|
+
exit 1
|
297
|
+
end
|
298
|
+
if is_windows?
|
299
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
300
|
+
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
301
|
+
processes.each { |p| ours << [p.Name, p.CommandLine, p.VirtualSize, p.CreationDate, p.ExecutablePath, p.Status ] }
|
302
|
+
puts "Ramaze is running!\n\tName: %s\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % ours.first
|
303
|
+
else
|
304
|
+
require "pathname"
|
305
|
+
# Check for /proc
|
306
|
+
if File.directory?(proc_dir = Pathname.new("/proc"))
|
307
|
+
proc_dir = proc_dir.join(pid)
|
308
|
+
# If we have a "stat" file, we'll assume linux and get as much info
|
309
|
+
# as we can
|
310
|
+
if File.file?(stat_file = proc_dir.join("stat"))
|
311
|
+
stats = File.read(stat_file).split
|
312
|
+
puts "Ramaze is running!\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % [
|
313
|
+
File.read(proc_dir.join("cmdline")).split("\000").join(" "),
|
314
|
+
"%s k" % (stats[22].to_f / 1024),
|
315
|
+
File.mtime(proc_dir),
|
316
|
+
File.readlink(proc_dir.join("exe")),
|
317
|
+
stats[2]
|
318
|
+
]
|
319
|
+
exit
|
320
|
+
end
|
321
|
+
end
|
322
|
+
# Fallthrough status, just print a ps
|
323
|
+
puts "Ramaze process #{pid} is running!"
|
324
|
+
begin
|
325
|
+
puts %x{ps l #{pid}}
|
326
|
+
rescue
|
327
|
+
puts "No further information available"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end # }}}
|
331
|
+
|
332
|
+
### End of command methods }}}
|
333
|
+
end # }}}
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
if $0 == __FILE__
|
339
|
+
Ramaze::Tool::Bin::Cmd.run(ARGV)
|
340
|
+
end
|