ramaze 2011.07.25 → 2011.10.23
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.mailmap +3 -2
- data/.travis.yml +17 -0
- data/.yardopts +13 -0
- data/README.md +95 -352
- data/examples/app/blog/app.rb +25 -64
- data/examples/app/blog/config.ru +11 -9
- data/examples/app/blog/controller/init.rb +29 -86
- data/examples/app/blog/controller/posts.rb +232 -0
- data/examples/app/blog/controller/users.rb +160 -0
- data/examples/app/blog/layout/default.xhtml +61 -0
- data/examples/app/blog/migrations/01_create_schema.rb +50 -0
- data/examples/app/blog/model/comment.rb +41 -54
- data/examples/app/blog/model/init.rb +41 -13
- data/examples/app/blog/model/post.rb +35 -0
- data/examples/app/blog/model/user.rb +105 -0
- data/examples/app/blog/public/.htaccess +24 -0
- data/examples/app/blog/public/css/grid.css +107 -0
- data/examples/app/blog/public/css/layout.css +203 -0
- data/examples/app/blog/public/css/reset.css +123 -0
- data/examples/app/blog/public/css/text.css +109 -0
- data/examples/app/blog/public/dispatch.fcgi +11 -0
- data/examples/app/blog/public/favicon.ico +0 -0
- data/examples/app/blog/public/images/bg.png +0 -0
- data/examples/app/blog/start.rb +18 -3
- data/examples/app/blog/view/feed.xhtml +23 -0
- data/examples/app/blog/view/form.xhtml +11 -0
- data/examples/app/blog/view/index.xhtml +44 -0
- data/examples/app/blog/view/users/form.xhtml +12 -0
- data/examples/app/blog/view/users/index.xhtml +30 -0
- data/examples/app/blog/view/users/login.xhtml +8 -0
- data/examples/app/blog/view/view.xhtml +68 -0
- data/{doc → guide}/AUTHORS +5 -3
- data/{doc → guide}/CHANGELOG +428 -0
- data/{doc/GPL → guide/GPL_LICENSE} +0 -0
- data/{doc/COPYING → guide/RUBY_LICENSE} +3 -6
- data/guide/_static/logo.png +0 -0
- data/guide/_static/logo.svg +49 -0
- data/guide/_static/ramaze_console.png +0 -0
- data/guide/css/common.css +20 -0
- data/guide/general/cache.md +167 -0
- data/guide/general/configuration.md +168 -0
- data/guide/general/contributing.md +108 -0
- data/guide/general/controllers.md +115 -0
- data/guide/general/helpers.md +76 -0
- data/guide/general/installation.md +58 -0
- data/guide/general/logging.md +99 -0
- data/guide/general/middlewares.md +100 -0
- data/guide/general/models.md +78 -0
- data/guide/general/principles.md +53 -0
- data/guide/general/ramaze_command.md +155 -0
- data/guide/general/routes.md +81 -0
- data/guide/general/sessions.md +140 -0
- data/guide/general/special_thanks.md +67 -0
- data/guide/general/testing.md +61 -0
- data/guide/general/views.md +322 -0
- data/guide/tutorials/introduction.md +259 -0
- data/lib/proto/config.ru +1 -1
- data/lib/proto/public/favicon.ico +0 -0
- data/lib/proto/view/index.xhtml +7 -7
- data/lib/ramaze.rb +4 -4
- data/lib/ramaze/app.rb +11 -11
- data/lib/ramaze/app_graph.rb +2 -4
- data/lib/ramaze/bin/console.rb +3 -3
- data/lib/ramaze/bin/create.rb +2 -2
- data/lib/ramaze/bin/restart.rb +4 -4
- data/lib/ramaze/bin/runner.rb +5 -5
- data/lib/ramaze/bin/start.rb +19 -4
- data/lib/ramaze/bin/status.rb +3 -3
- data/lib/ramaze/bin/stop.rb +3 -3
- data/lib/ramaze/cache.rb +1 -0
- data/lib/ramaze/cache/lru.rb +8 -4
- data/lib/ramaze/cache/memcache.rb +32 -13
- data/lib/ramaze/cache/redis.rb +164 -0
- data/lib/ramaze/cache/sequel.rb +43 -28
- data/lib/ramaze/controller.rb +1 -2
- data/lib/ramaze/dependencies.rb +40 -3
- data/lib/ramaze/helper/bench.rb +26 -16
- data/lib/ramaze/helper/blue_form.rb +46 -73
- data/lib/ramaze/helper/cache.rb +10 -6
- data/lib/ramaze/helper/csrf.rb +35 -39
- data/lib/ramaze/helper/disqus.rb +5 -4
- data/lib/ramaze/helper/email.rb +35 -24
- data/lib/ramaze/helper/erector.rb +9 -13
- data/lib/ramaze/helper/flash.rb +7 -9
- data/lib/ramaze/helper/formatting.rb +194 -179
- data/lib/ramaze/helper/gravatar.rb +4 -8
- data/lib/ramaze/helper/identity.rb +3 -3
- data/lib/ramaze/helper/layout.rb +23 -8
- data/lib/ramaze/helper/markaby.rb +1 -1
- data/lib/ramaze/helper/paginate.rb +46 -39
- data/lib/ramaze/helper/request_accessor.rb +3 -1
- data/lib/ramaze/helper/simple_captcha.rb +18 -17
- data/lib/ramaze/helper/stack.rb +1 -1
- data/lib/ramaze/helper/tagz.rb +4 -2
- data/lib/ramaze/helper/upload.rb +523 -0
- data/lib/ramaze/helper/user.rb +4 -8
- data/lib/ramaze/helper/xhtml.rb +11 -15
- data/lib/ramaze/log.rb +9 -6
- data/lib/ramaze/log/rotatinginformer.rb +62 -27
- data/lib/ramaze/log/syslog.rb +20 -15
- data/lib/ramaze/log/xosd.rb +2 -1
- data/lib/ramaze/reloader.rb +2 -0
- data/lib/ramaze/request.rb +11 -10
- data/lib/ramaze/setup.rb +23 -6
- data/lib/ramaze/snippets/array/put_within.rb +3 -9
- data/lib/ramaze/snippets/binding/locals.rb +5 -10
- data/lib/ramaze/snippets/fiber.rb +1 -23
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +3 -6
- data/lib/ramaze/snippets/numeric/filesize_format.rb +3 -5
- data/lib/ramaze/snippets/numeric/time.rb +3 -7
- data/lib/ramaze/snippets/object/__dir__.rb +3 -7
- data/lib/ramaze/snippets/object/instance_variable_defined.rb +3 -6
- data/lib/ramaze/snippets/object/pretty.rb +3 -7
- data/lib/ramaze/snippets/object/scope.rb +7 -9
- data/lib/ramaze/snippets/proc/locals.rb +12 -12
- data/lib/ramaze/snippets/ramaze/acquire.rb +15 -14
- data/lib/ramaze/snippets/ramaze/deprecated.rb +1 -1
- data/lib/ramaze/snippets/ramaze/fiber.rb +1 -1
- data/lib/ramaze/snippets/ramaze/lru_hash.rb +2 -3
- data/lib/ramaze/snippets/ramaze/struct.rb +2 -4
- data/lib/ramaze/snippets/string/camel_case.rb +8 -10
- data/lib/ramaze/snippets/string/color.rb +3 -4
- data/lib/ramaze/snippets/string/end_with.rb +3 -6
- data/lib/ramaze/snippets/string/esc.rb +3 -8
- data/lib/ramaze/snippets/string/ord.rb +3 -8
- data/lib/ramaze/snippets/string/snake_case.rb +6 -9
- data/lib/ramaze/snippets/string/start_with.rb +3 -8
- data/lib/ramaze/snippets/string/unindent.rb +3 -6
- data/lib/ramaze/snippets/thread/into.rb +1 -3
- data/lib/ramaze/spec.rb +2 -31
- data/lib/ramaze/spec/bacon.rb +18 -2
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +1 -1
- data/ramaze.gemspec +1 -1
- data/spec/helper.rb +2 -1
- data/spec/ramaze/bin/start.rb +16 -20
- data/spec/ramaze/cache/localmemcache.rb +4 -7
- data/spec/ramaze/cache/memcache.rb +3 -1
- data/spec/ramaze/cache/redis.rb +62 -0
- data/spec/ramaze/helper/blue_form.rb +33 -4
- data/spec/ramaze/helper/layout.rb +40 -7
- data/spec/ramaze/helper/upload.rb +149 -0
- data/spec/ramaze/helper/uploads/text_1.txt +1 -0
- data/spec/ramaze/helper/uploads/text_2.txt +1 -0
- data/spec/ramaze/log/growl.rb +4 -6
- data/spec/ramaze/log/syslog.rb +6 -0
- data/spec/ramaze/view/lokar.rb +5 -0
- data/spec/ramaze/view/nagoro.rb +5 -0
- data/tasks/authors.rake +1 -1
- data/tasks/bacon.rake +14 -5
- data/tasks/changelog.rake +1 -1
- data/tasks/yard.rake +12 -4
- metadata +277 -239
- data/doc/LEGAL +0 -26
- data/examples/app/blog/README +0 -3
- data/examples/app/blog/controller/comment.rb +0 -45
- data/examples/app/blog/controller/entry.rb +0 -85
- data/examples/app/blog/controller/main.rb +0 -20
- data/examples/app/blog/controller/tag.rb +0 -9
- data/examples/app/blog/layout/default.nag +0 -31
- data/examples/app/blog/model/entry.rb +0 -89
- data/examples/app/blog/model/tag.rb +0 -36
- data/examples/app/blog/public/css/screen.css +0 -273
- data/examples/app/blog/spec/blog.rb +0 -87
- data/examples/app/blog/view/comment/form.nag +0 -10
- data/examples/app/blog/view/comment/show.nag +0 -16
- data/examples/app/blog/view/entry/edit.nag +0 -14
- data/examples/app/blog/view/entry/feed.atom.nag +0 -8
- data/examples/app/blog/view/entry/feed.rss.nag +0 -7
- data/examples/app/blog/view/entry/index.nag +0 -7
- data/examples/app/blog/view/entry/new.nag +0 -13
- data/examples/app/blog/view/entry/show.nag +0 -36
- data/examples/app/blog/view/feed.atom.nag +0 -18
- data/examples/app/blog/view/feed.rss.nag +0 -25
- data/examples/app/blog/view/index.nag +0 -6
- data/examples/app/blog/view/tag/index.nag +0 -5
- data/lib/proto/public/ramaze.png +0 -0
- data/lib/ramaze/rest.rb +0 -36
- data/spec/ramaze/rest.rb +0 -28
- data/tasks/rcov.rake +0 -22
data/lib/ramaze/helper/user.rb
CHANGED
@@ -9,7 +9,6 @@ module Ramaze
|
|
9
9
|
# request.env, usually this will involve a request to your database.
|
10
10
|
#
|
11
11
|
# @example Basic usage with User::authenticate
|
12
|
-
#
|
13
12
|
# # We assume that User::[] will make a query and returns the requested
|
14
13
|
# # User instance. This instance will be wrapped and cached.
|
15
14
|
#
|
@@ -50,7 +49,6 @@ module Ramaze
|
|
50
49
|
# You can however, add your own caching quite easily.
|
51
50
|
#
|
52
51
|
# @example caching the authentication lookup with memcached
|
53
|
-
#
|
54
52
|
# # Add the name of the cache you are going to use for the authentication
|
55
53
|
# # and set all caches to use memcached
|
56
54
|
#
|
@@ -76,7 +74,6 @@ module Ramaze
|
|
76
74
|
# end
|
77
75
|
#
|
78
76
|
# @example Using a lambda instead of User::authenticate
|
79
|
-
#
|
80
77
|
# # assumes all your controllers inherit from this one
|
81
78
|
#
|
82
79
|
# class Controller < Ramaze::Controller
|
@@ -86,7 +83,6 @@ module Ramaze
|
|
86
83
|
# end
|
87
84
|
#
|
88
85
|
# @example Using a different model instead of User
|
89
|
-
#
|
90
86
|
# # assumes all your controllers inherit from this one
|
91
87
|
#
|
92
88
|
# class Controller < Ramaze::Controller
|
@@ -94,7 +90,7 @@ module Ramaze
|
|
94
90
|
# end
|
95
91
|
#
|
96
92
|
# @author manveru
|
97
|
-
#
|
93
|
+
#
|
98
94
|
module UserHelper
|
99
95
|
# Using this as key in request.env
|
100
96
|
RAMAZE_HELPER_USER = 'ramaze.helper.user'.freeze
|
@@ -103,7 +99,7 @@ module Ramaze
|
|
103
99
|
# Use this method in your application, but do not use it in conditionals
|
104
100
|
# as it will never be nil or false.
|
105
101
|
#
|
106
|
-
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
102
|
+
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
107
103
|
# model or callback
|
108
104
|
#
|
109
105
|
# @api external
|
@@ -122,7 +118,7 @@ module Ramaze
|
|
122
118
|
##
|
123
119
|
# shortcut for user._login but default argument are request.params
|
124
120
|
#
|
125
|
-
# @param [Hash] creds the credentials that will be passed to callback or
|
121
|
+
# @param [Hash] creds the credentials that will be passed to callback or
|
126
122
|
# model
|
127
123
|
# @return [nil Hash] the given creds are returned on successful login
|
128
124
|
#
|
@@ -178,7 +174,7 @@ module Ramaze
|
|
178
174
|
end
|
179
175
|
|
180
176
|
##
|
181
|
-
# @param [Hash] creds this hash will be stored in the session on
|
177
|
+
# @param [Hash] creds this hash will be stored in the session on
|
182
178
|
# successful login
|
183
179
|
# @return [Ramaze::Helper::User::Wrapper] wrapped return value from
|
184
180
|
# model or callback
|
data/lib/ramaze/helper/xhtml.rb
CHANGED
@@ -6,7 +6,7 @@ module Ramaze
|
|
6
6
|
# The XHTML helper can be used for generating CSS and Javascript tags.
|
7
7
|
# Generating a CSS tag can be done by calling the css() method:
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# css 'reset', 'screen', :only => 'ie'
|
10
10
|
#
|
11
11
|
# This would result in a stylesheet named "reset.css" being loaded only when
|
12
12
|
# the user is using Internet Explorer.
|
@@ -24,10 +24,9 @@ module Ramaze
|
|
24
24
|
# @param [String] name The name of the CSS file to load.
|
25
25
|
# @param [String] media The media type for which the stylesheet should be
|
26
26
|
# loaded.
|
27
|
-
# @param [Hash] options A hash containing additional options for the
|
27
|
+
# @param [Hash] options A hash containing additional options for the
|
28
28
|
# stylesheet tag.
|
29
29
|
# @example
|
30
|
-
#
|
31
30
|
# # A very basic example.
|
32
31
|
# css 'reset'
|
33
32
|
#
|
@@ -50,7 +49,7 @@ module Ramaze
|
|
50
49
|
else
|
51
50
|
prefix = options[:prefix] || 'css'
|
52
51
|
LINK_TAG % [
|
53
|
-
"#{Ramaze.options.prefix.chomp("/")}/#{prefix}/#{name}.css",
|
52
|
+
"#{Ramaze.options.prefix.chomp("/")}/#{prefix}/#{name}.css",
|
54
53
|
media
|
55
54
|
]
|
56
55
|
end
|
@@ -63,7 +62,6 @@ module Ramaze
|
|
63
62
|
# again.
|
64
63
|
#
|
65
64
|
# @example
|
66
|
-
#
|
67
65
|
# # This is pretty basic
|
68
66
|
# css_for 'reset', '960', 'style'
|
69
67
|
#
|
@@ -71,8 +69,8 @@ module Ramaze
|
|
71
69
|
# css_for ['reset', 'print'], ['960', 'print']
|
72
70
|
#
|
73
71
|
# @see css()
|
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
|
72
|
+
# @param [Array] args An array containing either the names of all
|
73
|
+
# stylesheets to load or a collection of arrays of which each array
|
76
74
|
# defines the name, media and additional parameters.
|
77
75
|
# @return [String]
|
78
76
|
#
|
@@ -81,24 +79,23 @@ module Ramaze
|
|
81
79
|
end
|
82
80
|
|
83
81
|
##
|
84
|
-
# Generates a Javascript tag that loads an external Javascript file. This
|
82
|
+
# Generates a Javascript tag that loads an external Javascript file. This
|
85
83
|
# tag can't be used for loading inline Javascript files.
|
86
84
|
#
|
87
85
|
# @example
|
88
|
-
#
|
89
86
|
# # Simple isn't it?
|
90
87
|
# js 'jquery'
|
91
88
|
#
|
92
89
|
# # Let's change the directory to "some_other_directory"
|
93
90
|
# js 'jquery', :prefix => 'some_other_directory'
|
94
91
|
#
|
95
|
-
# @param [String] name The name of the Javascript file that should be
|
92
|
+
# @param [String] name The name of the Javascript file that should be
|
96
93
|
# loaded.
|
97
94
|
# @param [Hash] options Hash that can contain a :prefix key that defines
|
98
95
|
# the directory in which the JS file is located. By default this key is
|
99
96
|
# set to "js".
|
100
97
|
# @return [String]
|
101
|
-
#
|
98
|
+
#
|
102
99
|
def js(name, options={})
|
103
100
|
if name =~ /^http/ # consider it external full url
|
104
101
|
SCRIPT_TAG % name
|
@@ -106,21 +103,20 @@ module Ramaze
|
|
106
103
|
SCRIPT_TAG % "#{Ramaze.options.prefix.chomp("/")}/#{options[:prefix] || 'js'}/#{name}.js"
|
107
104
|
end
|
108
105
|
end
|
109
|
-
|
106
|
+
|
110
107
|
##
|
111
108
|
# Generate multiple Javascript tags using the js() method.
|
112
109
|
#
|
113
110
|
# @example
|
114
|
-
#
|
115
111
|
# # Pretty simple isn't it?
|
116
112
|
# js_for 'jquery', 'application', 'jquery.gritter'
|
117
113
|
#
|
118
114
|
# @param [Array] args Array containing the Javascript files to load.
|
119
115
|
# @return [String]
|
120
|
-
#
|
116
|
+
#
|
121
117
|
def js_for(*args)
|
122
118
|
args.map{|arg| js(*arg) }.join("\n")
|
123
119
|
end
|
124
120
|
end # XHTML
|
125
|
-
end # Helper
|
121
|
+
end # Helper
|
126
122
|
end # Ramaze
|
data/lib/ramaze/log.rb
CHANGED
@@ -21,11 +21,14 @@ module Ramaze
|
|
21
21
|
# @since 11-08-2009
|
22
22
|
#
|
23
23
|
module Logger
|
24
|
-
autoload :Analogger, 'ramaze/log/analogger'
|
25
|
-
autoload :
|
26
|
-
autoload :
|
27
|
-
autoload :
|
28
|
-
autoload :
|
29
|
-
autoload :
|
24
|
+
autoload :Analogger , 'ramaze/log/analogger'
|
25
|
+
autoload :Growl , 'ramaze/log/growl'
|
26
|
+
autoload :LogHub , 'ramaze/log/hub'
|
27
|
+
autoload :Knotify , 'ramaze/log/knotify'
|
28
|
+
autoload :RotatingInformer, 'ramaze/log/rotatinginformer'
|
29
|
+
autoload :Syslog , 'ramaze/log/syslog'
|
30
|
+
autoload :Growl , 'ramaze/log/growl'
|
31
|
+
autoload :Xosd , 'ramaze/log/xosd'
|
32
|
+
autoload :Logger , 'ramaze/log/logger'
|
30
33
|
end
|
31
34
|
end
|
@@ -1,10 +1,45 @@
|
|
1
1
|
module Ramaze
|
2
|
-
|
3
2
|
module Logger
|
4
|
-
|
5
3
|
##
|
6
|
-
# A
|
7
|
-
#
|
4
|
+
# A logger that rotates log files based on the current date. Log files are
|
5
|
+
# named after the date on which they were created. If the date changes a new
|
6
|
+
# log file is used.
|
7
|
+
#
|
8
|
+
# In order to use this logger you'll have to specify a base directory for
|
9
|
+
# all log files. This directory will not be created for you so make sure it
|
10
|
+
# exists. Loading the class can be done as following:
|
11
|
+
#
|
12
|
+
# logger = Ramaze::Logger::RotatingInformer.new('./log')
|
13
|
+
#
|
14
|
+
# This creates a new instance that uses the directory ``./log`` for all it's
|
15
|
+
# log files.
|
16
|
+
#
|
17
|
+
# The default log format is ``%Y-%m-%d.log``. If you want to change this you
|
18
|
+
# can specify an alternative format (including the extension) as the
|
19
|
+
# secondary parameter of the ``.new()`` method:
|
20
|
+
#
|
21
|
+
# logger = Ramaze::Logger::RotatingInformer.new('./log', '%d-%m-%Y.log')
|
22
|
+
#
|
23
|
+
# In this case the instance will use the date format ``dd-mm-yyyy`` along
|
24
|
+
# with the ``.log`` extension.
|
25
|
+
#
|
26
|
+
# Besides the date format you can also customize the timestamp format as
|
27
|
+
# well as the format of each logged messages. Both these are set in a trait.
|
28
|
+
# The timestamp format is located in the trait ``:timestamp`` while the
|
29
|
+
# message format is stored in the ``:format`` trait. These can be set as
|
30
|
+
# following:
|
31
|
+
#
|
32
|
+
# logger = Ramaze::Logger::RotatingInformer.new('./log')
|
33
|
+
#
|
34
|
+
# logger.trait[:timestamp] = '...'
|
35
|
+
# logger.trait[:format] = '...'
|
36
|
+
#
|
37
|
+
# When setting the ``:format`` trait you can use 3 tags that will be
|
38
|
+
# replaced by their corresponding values. These are the following tags:
|
39
|
+
#
|
40
|
+
# * ``%time``: will be replaced by the current time.
|
41
|
+
# * ``%prefix``: the log level such as "ERROR" or "INFO".
|
42
|
+
# * ``%text``: the actual log message.
|
8
43
|
#
|
9
44
|
class RotatingInformer
|
10
45
|
include Innate::Traited
|
@@ -24,16 +59,14 @@ module Ramaze
|
|
24
59
|
#
|
25
60
|
# base_dir is the directory where all log files will be stored
|
26
61
|
#
|
27
|
-
# time_format is the time format used to name the log files.
|
28
|
-
#
|
29
|
-
# accepted by Time.strftime
|
62
|
+
# time_format is the time format used to name the log files. Possible
|
63
|
+
# formats are identical to those accepted by Time.strftime
|
30
64
|
#
|
31
|
-
# log_levelse is an array describing what kind of messages
|
32
|
-
#
|
33
|
-
#
|
65
|
+
# log_levelse is an array describing what kind of messages that the log
|
66
|
+
# receives. The array may contain any or all of the symbols :debug,
|
67
|
+
# :error, :info and/or :warn
|
34
68
|
#
|
35
69
|
# @example
|
36
|
-
#
|
37
70
|
# # Creates logs in directory called logs. The generated filenames
|
38
71
|
# # will be in the form YYYY-MM-DD.log
|
39
72
|
# RotatingInformer.new('logs')
|
@@ -57,7 +90,7 @@ module Ramaze
|
|
57
90
|
send :base_dir=, base_dir, true
|
58
91
|
|
59
92
|
@time_format = time_format
|
60
|
-
@log_levels
|
93
|
+
@log_levels = log_levels
|
61
94
|
|
62
95
|
# Keep track of log shutdown (to prevent StackErrors due to recursion)
|
63
96
|
@in_shutdown = false
|
@@ -66,13 +99,12 @@ module Ramaze
|
|
66
99
|
##
|
67
100
|
# Set the base directory for log files
|
68
101
|
#
|
69
|
-
# If this method is called with the raise_exception
|
70
|
-
#
|
71
|
-
#
|
102
|
+
# If this method is called with the raise_exception parameter set to true
|
103
|
+
# the method will raise an exception if the specified directory does not
|
104
|
+
# exist or is unwritable.
|
72
105
|
#
|
73
|
-
# If raise_exception is set to false, the method will just
|
74
|
-
#
|
75
|
-
# or is unwritable.
|
106
|
+
# If raise_exception is set to false, the method will just silently fail
|
107
|
+
# if the specified directory does not exist or is unwritable.
|
76
108
|
#
|
77
109
|
# @param [String] directory The base directory specified by the developer.
|
78
110
|
# @param [Bool] raise_exception Boolean that indicates if an exception
|
@@ -119,7 +151,7 @@ module Ramaze
|
|
119
151
|
# @param [String] tag The type of message we're logging.
|
120
152
|
# @param [Array] messages An array of messages to log.
|
121
153
|
#
|
122
|
-
def log
|
154
|
+
def log(tag, *messages)
|
123
155
|
return unless @log_levels.include?(tag)
|
124
156
|
|
125
157
|
# Update current log
|
@@ -144,7 +176,7 @@ module Ramaze
|
|
144
176
|
# @param [String] text
|
145
177
|
# @param [Integer] time
|
146
178
|
#
|
147
|
-
def log_interpolate
|
179
|
+
def log_interpolate(prefix, text, time = timestamp)
|
148
180
|
message = class_trait[:format].dup
|
149
181
|
|
150
182
|
vars = { '%time' => time, '%prefix' => prefix, '%text' => text }
|
@@ -155,8 +187,9 @@ module Ramaze
|
|
155
187
|
|
156
188
|
##
|
157
189
|
# This uses timestamp trait or a date in the format of
|
158
|
-
#
|
159
|
-
#
|
190
|
+
# ``%Y-%m-%d %H:%M:%S``
|
191
|
+
#
|
192
|
+
# @return [String]
|
160
193
|
#
|
161
194
|
def timestamp
|
162
195
|
mask = class_trait[:timestamp]
|
@@ -164,7 +197,9 @@ module Ramaze
|
|
164
197
|
end
|
165
198
|
|
166
199
|
##
|
167
|
-
# Is
|
200
|
+
# Is ``@out`` closed?
|
201
|
+
#
|
202
|
+
# @return [TrueClass|FalseClass]
|
168
203
|
#
|
169
204
|
def closed?
|
170
205
|
@out.respond_to?(:closed?) && @out.closed?
|
@@ -176,19 +211,19 @@ module Ramaze
|
|
176
211
|
# @author Yorick Peterse
|
177
212
|
# @param [String] message The data that has to be logged.
|
178
213
|
#
|
179
|
-
def write
|
214
|
+
def write(message)
|
180
215
|
log(:info, message)
|
181
216
|
end
|
182
217
|
|
183
218
|
private
|
184
219
|
|
185
220
|
##
|
186
|
-
# Checks whether current filename is still valid.
|
187
|
-
#
|
188
|
-
# filename
|
221
|
+
# Checks whether current filename is still valid. If not, update the
|
222
|
+
# current log to point at the new filename.
|
189
223
|
#
|
190
224
|
def update_current_log
|
191
225
|
out = File.join(@base_dir, Time.now.strftime(@time_format))
|
226
|
+
|
192
227
|
if @out.nil? || @out.path != out
|
193
228
|
# Close old log if necessary
|
194
229
|
shutdown unless @out.nil? || closed?
|
data/lib/ramaze/log/syslog.rb
CHANGED
@@ -4,14 +4,6 @@
|
|
4
4
|
|
5
5
|
require 'syslog'
|
6
6
|
|
7
|
-
# Add aliases for the levelnames used by Ramaze logging
|
8
|
-
module Syslog
|
9
|
-
alias dev debug
|
10
|
-
alias warn warning
|
11
|
-
alias error err
|
12
|
-
module_function :dev, :warn, :error
|
13
|
-
end
|
14
|
-
|
15
7
|
module Ramaze
|
16
8
|
module Logger
|
17
9
|
##
|
@@ -21,19 +13,25 @@ module Ramaze
|
|
21
13
|
class Syslog
|
22
14
|
include Logging
|
23
15
|
|
16
|
+
# Hash containing various method aliases. Rbx and Jruby don't seem to like
|
17
|
+
# the combination of alias() and module_function() so this works around
|
18
|
+
# that.
|
19
|
+
ALIASES = {:dev => :debug, :warn => :warning, :error => :err}
|
20
|
+
|
24
21
|
##
|
25
22
|
# Open the syslog library, if it is allready open, we reopen it using the
|
26
|
-
# new argument list.
|
27
|
-
# so please check that, and man syslog for detailed information.
|
23
|
+
# new argument list. The argument list is passed on to the Syslog library
|
24
|
+
# so please check that, and man syslog for detailed information.
|
25
|
+
#
|
28
26
|
# There are 3 parameters:
|
29
27
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
28
|
+
# * ident: The identification used in the log file, defaults to $0
|
29
|
+
# * options: defaults to Syslog::LOG_PID | Syslog::LOG_CONS
|
30
|
+
# * facility: defaults to Syslog::LOG_USER
|
33
31
|
#
|
34
|
-
def initialize(
|
32
|
+
def initialize(*args)
|
35
33
|
::Syslog.close if ::Syslog.opened?
|
36
|
-
::Syslog.open(
|
34
|
+
::Syslog.open(*args)
|
37
35
|
end
|
38
36
|
|
39
37
|
##
|
@@ -41,8 +39,15 @@ module Ramaze
|
|
41
39
|
# We simply return if the log was closed for some reason, this behavior
|
42
40
|
# was copied from Informer. We do not handle levels here. This will
|
43
41
|
# be done by te syslog daemon based on it's configuration.
|
42
|
+
#
|
44
43
|
def log(tag, *messages)
|
45
44
|
return if !::Syslog.opened?
|
45
|
+
tag = tag.to_sym
|
46
|
+
|
47
|
+
if ALIASES.key?(tag)
|
48
|
+
tag = ALIASES[tag]
|
49
|
+
end
|
50
|
+
|
46
51
|
::Syslog.send(tag, *messages)
|
47
52
|
end
|
48
53
|
|
data/lib/ramaze/log/xosd.rb
CHANGED
data/lib/ramaze/reloader.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
3
|
|
4
4
|
module Ramaze
|
5
|
+
##
|
5
6
|
# High performant source reloader
|
6
7
|
#
|
7
8
|
# This class acts as Rack middleware.
|
@@ -24,6 +25,7 @@ module Ramaze
|
|
24
25
|
#
|
25
26
|
# A number of hooks will be executed during the reload cycle, see
|
26
27
|
# Ramaze::ReloaderHooks for more information.
|
28
|
+
#
|
27
29
|
class Reloader
|
28
30
|
OPTIONS = {
|
29
31
|
# At most check every n seconds
|
data/lib/ramaze/request.rb
CHANGED
@@ -19,11 +19,13 @@ module Ramaze
|
|
19
19
|
# Sets any arguments passed as @instance_variables for the current action.
|
20
20
|
#
|
21
21
|
# Usage:
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
22
|
+
#
|
23
|
+
# request.params # => {'name' => 'manveru', 'q' => 'google', 'lang' => 'de'}
|
24
|
+
# request.to_ivs(:name, :q)
|
25
|
+
#
|
26
|
+
# @q # => 'google'
|
27
|
+
# @name # => 'manveru'
|
28
|
+
# @lang # => nil
|
27
29
|
#
|
28
30
|
def to_instance_variables(*args)
|
29
31
|
instance = Current.action.instance
|
@@ -49,8 +51,7 @@ module Ramaze
|
|
49
51
|
#
|
50
52
|
# Usage:
|
51
53
|
#
|
52
|
-
#
|
53
|
-
# # => ['en-us', 'en', 'de-at', 'de']
|
54
|
+
# request.accept_language # => ['en-us', 'en', 'de-at', 'de']
|
54
55
|
#
|
55
56
|
# @param [String #to_s] string the value of HTTP_ACCEPT_LANGUAGE
|
56
57
|
# @return [Array] list of locales
|
@@ -67,14 +68,14 @@ module Ramaze
|
|
67
68
|
##
|
68
69
|
# Transform the HTTP_ACCEPT_LANGUAGE header into an Array with:
|
69
70
|
#
|
70
|
-
#
|
71
|
+
# [[lang, weight], [lang, weight], ...]
|
71
72
|
#
|
72
73
|
# This algorithm was taken and improved from the locales library.
|
73
74
|
#
|
74
75
|
# Usage:
|
75
76
|
#
|
76
|
-
#
|
77
|
-
#
|
77
|
+
# request.accept_language_with_weight
|
78
|
+
# # => [["en-us", 1.0], ["en", 0.8], ["de-at", 0.5], ["de", 0.3]]
|
78
79
|
#
|
79
80
|
# @param [String #to_s] string the value of HTTP_ACCEPT_LANGUAGE
|
80
81
|
# @return [Array] array of [lang, weight] arrays
|