padrino-core 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +5 -5
- data/lib/padrino-core.rb +3 -9
- data/lib/padrino-core/application.rb +39 -35
- data/lib/padrino-core/application/flash.rb +7 -7
- data/lib/padrino-core/application/rendering.rb +136 -139
- data/lib/padrino-core/application/rendering/extensions/erubis.rb +15 -6
- data/lib/padrino-core/application/routing.rb +371 -369
- data/lib/padrino-core/application/showexceptions.rb +13 -12
- data/lib/padrino-core/caller.rb +40 -40
- data/lib/padrino-core/cli/adapter.rb +4 -4
- data/lib/padrino-core/cli/base.rb +40 -39
- data/lib/padrino-core/cli/rake.rb +2 -2
- data/lib/padrino-core/cli/rake_tasks.rb +2 -4
- data/lib/padrino-core/command.rb +2 -2
- data/lib/padrino-core/loader.rb +14 -15
- data/lib/padrino-core/locale/cs.yml +0 -1
- data/lib/padrino-core/locale/da.yml +0 -1
- data/lib/padrino-core/locale/de.yml +0 -1
- data/lib/padrino-core/locale/en.yml +0 -1
- data/lib/padrino-core/locale/es.yml +1 -2
- data/lib/padrino-core/locale/fr.yml +2 -3
- data/lib/padrino-core/locale/hu.yml +1 -2
- data/lib/padrino-core/locale/it.yml +0 -1
- data/lib/padrino-core/locale/ja.yml +1 -2
- data/lib/padrino-core/locale/lv.yml +0 -1
- data/lib/padrino-core/locale/nl.yml +0 -1
- data/lib/padrino-core/locale/no.yml +0 -2
- data/lib/padrino-core/locale/pl.yml +0 -1
- data/lib/padrino-core/locale/pt_br.yml +0 -1
- data/lib/padrino-core/locale/ro.yml +0 -1
- data/lib/padrino-core/locale/ru.yml +0 -1
- data/lib/padrino-core/locale/sv.yml +0 -1
- data/lib/padrino-core/locale/tr.yml +0 -1
- data/lib/padrino-core/locale/uk.yml +0 -1
- data/lib/padrino-core/locale/zh_cn.yml +0 -1
- data/lib/padrino-core/locale/zh_tw.yml +0 -1
- data/lib/padrino-core/logger.rb +26 -27
- data/lib/padrino-core/module.rb +3 -3
- data/lib/padrino-core/mounter.rb +59 -59
- data/lib/padrino-core/reloader.rb +23 -23
- data/lib/padrino-core/router.rb +10 -13
- data/lib/padrino-core/server.rb +17 -19
- data/lib/padrino-core/tasks.rb +3 -3
- data/lib/padrino-core/version.rb +1 -1
- data/padrino-core.gemspec +1 -1
- data/test/test_application.rb +7 -7
- data/test/test_rendering.rb +15 -2
- data/test/test_routing.rb +34 -10
- metadata +13 -27
@@ -13,7 +13,7 @@ ja:
|
|
13
13
|
abbr_day_names: [日, 月, 火, 水, 木, 金, 土]
|
14
14
|
month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
|
15
15
|
abbr_month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
|
16
|
-
order:
|
16
|
+
order:
|
17
17
|
- year
|
18
18
|
- month
|
19
19
|
- day
|
@@ -26,7 +26,6 @@ ja:
|
|
26
26
|
am: "午前"
|
27
27
|
pm: "午後"
|
28
28
|
|
29
|
-
# Used in array.to_sentence.
|
30
29
|
support:
|
31
30
|
array:
|
32
31
|
words_connector: ", "
|
data/lib/padrino-core/logger.rb
CHANGED
@@ -17,13 +17,13 @@ module Padrino
|
|
17
17
|
end
|
18
18
|
|
19
19
|
##
|
20
|
-
# Set the padrino logger
|
20
|
+
# Set the padrino logger.
|
21
21
|
#
|
22
22
|
# @param [Object] value
|
23
23
|
# an object that respond to <<, write, puts, debug, warn etc..
|
24
24
|
#
|
25
25
|
# @return [Object]
|
26
|
-
#
|
26
|
+
# The given value.
|
27
27
|
#
|
28
28
|
# @example using ruby default logger
|
29
29
|
# require 'logger'
|
@@ -44,7 +44,7 @@ module Padrino
|
|
44
44
|
##
|
45
45
|
# Ruby (standard) logger levels:
|
46
46
|
#
|
47
|
-
# :fatal:: An
|
47
|
+
# :fatal:: An not handleable error that results in a program crash
|
48
48
|
# :error:: A handleable error condition
|
49
49
|
# :warn:: A warning
|
50
50
|
# :info:: generic (useful) information about system operation
|
@@ -80,16 +80,16 @@ module Padrino
|
|
80
80
|
end
|
81
81
|
|
82
82
|
##
|
83
|
-
# Append a to development logger a given action with time
|
83
|
+
# Append a to development logger a given action with time.
|
84
84
|
#
|
85
85
|
# @param [string] action
|
86
|
-
# The action
|
86
|
+
# The action.
|
87
87
|
#
|
88
88
|
# @param [float] time
|
89
|
-
# Time duration for the given action
|
89
|
+
# Time duration for the given action.
|
90
90
|
#
|
91
91
|
# @param [message] string
|
92
|
-
# The message that you want to log
|
92
|
+
# The message that you want to log.
|
93
93
|
#
|
94
94
|
# @example
|
95
95
|
# logger.bench 'GET', started_at, '/blog/categories'
|
@@ -110,10 +110,10 @@ module Padrino
|
|
110
110
|
# the output of this block will be appended to the message.
|
111
111
|
#
|
112
112
|
# @param [String] message
|
113
|
-
# The message that you want write to your stream
|
113
|
+
# The message that you want write to your stream.
|
114
114
|
#
|
115
115
|
# @param [String] level
|
116
|
-
# The level one of :debug, :warn etc...
|
116
|
+
# The level one of :debug, :warn etc. ...
|
117
117
|
#
|
118
118
|
#
|
119
119
|
def push(message = nil, level = nil)
|
@@ -125,10 +125,10 @@ module Padrino
|
|
125
125
|
# logger components such as {Padrino::Logger}.
|
126
126
|
#
|
127
127
|
# @param [String] message
|
128
|
-
# The message to format
|
128
|
+
# The message to format.
|
129
129
|
#
|
130
130
|
# @param [String,Symbol] level
|
131
|
-
# The log level, one of :debug, :warn...
|
131
|
+
# The log level, one of :debug, :warn ...
|
132
132
|
def format(message, level)
|
133
133
|
message
|
134
134
|
end
|
@@ -140,7 +140,7 @@ module Padrino
|
|
140
140
|
# stylized_level(:debug) => DEBUG
|
141
141
|
#
|
142
142
|
# @param [String,Symbol] level
|
143
|
-
# The log level
|
143
|
+
# The log level.
|
144
144
|
#
|
145
145
|
def stylized_level(level)
|
146
146
|
level.to_s.upcase.rjust(7)
|
@@ -186,7 +186,7 @@ module Padrino
|
|
186
186
|
} unless defined?(ColoredLevels)
|
187
187
|
|
188
188
|
##
|
189
|
-
# Colorize our level
|
189
|
+
# Colorize our level.
|
190
190
|
#
|
191
191
|
# @param [String, Symbol] level
|
192
192
|
#
|
@@ -263,7 +263,7 @@ module Padrino
|
|
263
263
|
end
|
264
264
|
|
265
265
|
##
|
266
|
-
# Setup a new logger
|
266
|
+
# Setup a new logger.
|
267
267
|
#
|
268
268
|
# @return [Padrino::Logger]
|
269
269
|
# A {Padrino::Logger} instance
|
@@ -308,16 +308,16 @@ module Padrino
|
|
308
308
|
# added. Defaults to true.
|
309
309
|
#
|
310
310
|
# @option options [Symbol] :format_datetime (" [%d/%b/%Y %H:%M:%S] ")
|
311
|
-
# Format of datetime
|
311
|
+
# Format of datetime.
|
312
312
|
#
|
313
313
|
# @option options [Symbol] :format_message ("%s -%s%s")
|
314
|
-
# Format of message
|
314
|
+
# Format of message.
|
315
315
|
#
|
316
316
|
# @option options [Symbol] :log_static (false)
|
317
317
|
# Whether or not to show log messages for static files.
|
318
318
|
#
|
319
319
|
# @option options [Symbol] :colorize_logging (true)
|
320
|
-
# Whether or not to colorize log messages. Defaults to: true
|
320
|
+
# Whether or not to colorize log messages. Defaults to: true.
|
321
321
|
#
|
322
322
|
def initialize(options={})
|
323
323
|
@buffer = []
|
@@ -357,7 +357,6 @@ module Padrino
|
|
357
357
|
##
|
358
358
|
# Adds a message to the log - for compatibility with other loggers.
|
359
359
|
#
|
360
|
-
# @private
|
361
360
|
def add(level, message = nil)
|
362
361
|
write(message)
|
363
362
|
end
|
@@ -383,18 +382,17 @@ module Padrino
|
|
383
382
|
end
|
384
383
|
|
385
384
|
##
|
386
|
-
# Padrino::
|
385
|
+
# Padrino::Logger::Rack forwards every request to an +app+ given, and
|
387
386
|
# logs a line in the Apache common log format to the +logger+, or
|
388
387
|
# rack.errors by default.
|
389
388
|
#
|
390
389
|
class Rack
|
391
|
-
|
392
|
-
def initialize(app, uri_root) # @private
|
390
|
+
def initialize(app, uri_root)
|
393
391
|
@app = app
|
394
392
|
@uri_root = uri_root.sub(/\/$/,"")
|
395
393
|
end
|
396
394
|
|
397
|
-
def call(env)
|
395
|
+
def call(env)
|
398
396
|
env['rack.logger'] = Padrino.logger
|
399
397
|
began_at = Time.now
|
400
398
|
status, header, body = @app.call(env)
|
@@ -403,6 +401,7 @@ module Padrino
|
|
403
401
|
end
|
404
402
|
|
405
403
|
private
|
404
|
+
|
406
405
|
def log(env, status, header, began_at)
|
407
406
|
return if env['sinatra.static_file'] && (!logger.respond_to?(:log_static) || !logger.log_static)
|
408
407
|
logger.bench(
|
@@ -425,15 +424,15 @@ module Padrino
|
|
425
424
|
def code_to_name(status)
|
426
425
|
::Rack::Utils::HTTP_STATUS_CODES[status.to_i] || ''
|
427
426
|
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
431
430
|
|
432
|
-
module Kernel
|
431
|
+
module Kernel
|
433
432
|
##
|
434
433
|
# Define a logger available every where in our app
|
435
434
|
#
|
436
435
|
def logger
|
437
436
|
Padrino.logger
|
438
437
|
end
|
439
|
-
end
|
438
|
+
end
|
data/lib/padrino-core/module.rb
CHANGED
@@ -32,9 +32,9 @@ module Padrino
|
|
32
32
|
def root(*args)
|
33
33
|
File.expand_path(File.join(@root, *args))
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
##
|
37
|
-
# Returns the list of path globs to load as dependencies
|
37
|
+
# Returns the list of path globs to load as dependencies.
|
38
38
|
# Appends custom dependency patterns to the be loaded for Padrino.
|
39
39
|
#
|
40
40
|
# @return [Array<String>]
|
@@ -55,4 +55,4 @@ module Padrino
|
|
55
55
|
]
|
56
56
|
end
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|
data/lib/padrino-core/mounter.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
module Padrino
|
2
2
|
##
|
3
|
-
# Represents a particular mounted
|
4
|
-
# Stores the name of the application (app folder name) and url mount path
|
3
|
+
# Represents a particular mounted Padrino application.
|
4
|
+
# Stores the name of the application (app folder name) and url mount path.
|
5
5
|
#
|
6
6
|
# @example
|
7
7
|
# Mounter.new("blog_app", :app_class => "Blog").to("/blog")
|
8
8
|
# Mounter.new("blog_app", :app_file => "/path/to/blog/app.rb").to("/blog")
|
9
9
|
#
|
10
10
|
class Mounter
|
11
|
-
class MounterException < RuntimeError
|
11
|
+
class MounterException < RuntimeError
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host
|
15
15
|
|
16
16
|
##
|
17
17
|
# @param [String, Padrino::Application] name
|
18
|
-
# The app name or the {Padrino::Application} class
|
18
|
+
# The app name or the {Padrino::Application} class.
|
19
19
|
#
|
20
20
|
# @param [Hash] options
|
21
21
|
# @option options [Symbol] :app_class (Detected from name)
|
@@ -37,10 +37,10 @@ module Padrino
|
|
37
37
|
end
|
38
38
|
|
39
39
|
##
|
40
|
-
# Registers the mounted application onto Padrino
|
40
|
+
# Registers the mounted application onto Padrino.
|
41
41
|
#
|
42
42
|
# @param [String] mount_url
|
43
|
-
# Path where we mount the app
|
43
|
+
# Path where we mount the app.
|
44
44
|
#
|
45
45
|
# @example
|
46
46
|
# Mounter.new("blog_app").to("/blog")
|
@@ -52,10 +52,10 @@ module Padrino
|
|
52
52
|
end
|
53
53
|
|
54
54
|
##
|
55
|
-
# Registers the mounted application onto Padrino for the given host
|
55
|
+
# Registers the mounted application onto Padrino for the given host.
|
56
56
|
#
|
57
57
|
# @param [String] mount_host
|
58
|
-
# Host name
|
58
|
+
# Host name.
|
59
59
|
#
|
60
60
|
# @example
|
61
61
|
# Mounter.new("blog_app").to("/blog").host("blog.padrino.org")
|
@@ -69,8 +69,8 @@ module Padrino
|
|
69
69
|
end
|
70
70
|
|
71
71
|
##
|
72
|
-
# Maps Padrino application onto a Padrino::Router
|
73
|
-
# For use in constructing a Rack application
|
72
|
+
# Maps Padrino application onto a Padrino::Router.
|
73
|
+
# For use in constructing a Rack application.
|
74
74
|
#
|
75
75
|
# @param [Padrino::Router]
|
76
76
|
#
|
@@ -92,17 +92,17 @@ module Padrino
|
|
92
92
|
end
|
93
93
|
|
94
94
|
###
|
95
|
-
# Returns the route objects for the mounted application
|
95
|
+
# Returns the route objects for the mounted application.
|
96
96
|
#
|
97
97
|
def routes
|
98
98
|
app_obj.routes
|
99
99
|
end
|
100
100
|
|
101
101
|
###
|
102
|
-
# Returns the basic route information for each named route
|
102
|
+
# Returns the basic route information for each named route.
|
103
103
|
#
|
104
104
|
# @return [Array]
|
105
|
-
# Array of routes
|
105
|
+
# Array of routes.
|
106
106
|
#
|
107
107
|
def named_routes
|
108
108
|
app_obj.routes.map { |route|
|
@@ -116,7 +116,7 @@ module Padrino
|
|
116
116
|
end
|
117
117
|
|
118
118
|
##
|
119
|
-
# Makes two Mounters equal if they have the same name and uri_root
|
119
|
+
# Makes two Mounters equal if they have the same name and uri_root.
|
120
120
|
#
|
121
121
|
# @param [Padrino::Mounter] other
|
122
122
|
#
|
@@ -126,7 +126,7 @@ module Padrino
|
|
126
126
|
|
127
127
|
##
|
128
128
|
# @return [Padrino::Application]
|
129
|
-
# the class object for the app if defined, nil otherwise
|
129
|
+
# the class object for the app if defined, nil otherwise.
|
130
130
|
#
|
131
131
|
def app_constant
|
132
132
|
klass = Object
|
@@ -142,51 +142,51 @@ module Padrino
|
|
142
142
|
end
|
143
143
|
|
144
144
|
protected
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
145
|
+
##
|
146
|
+
# Locates and requires the file to load the app constant.
|
147
|
+
#
|
148
|
+
def locate_app_object
|
149
|
+
@_app_object ||= begin
|
150
|
+
ensure_app_file!
|
151
|
+
Padrino.require_dependencies(app_file)
|
152
|
+
app_constant
|
154
153
|
end
|
154
|
+
end
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
156
|
+
##
|
157
|
+
# Returns the determined location of the mounted application main file.
|
158
|
+
#
|
159
|
+
def locate_app_file
|
160
|
+
candidates = []
|
161
|
+
candidates << app_constant.app_file if app_constant.respond_to?(:app_file) && File.exist?(app_constant.app_file.to_s)
|
162
|
+
candidates << Padrino.first_caller if File.identical?(Padrino.first_caller.to_s, Padrino.called_from.to_s)
|
163
|
+
candidates << Padrino.mounted_root(name.downcase, "app.rb")
|
164
|
+
simple_name = name.split("::").last.downcase
|
165
|
+
mod_name = name.split("::")[0..-2].join("::")
|
166
|
+
Padrino.modules.each do |mod|
|
167
|
+
if mod.name == mod_name
|
168
|
+
candidates << mod.root(simple_name, "app.rb")
|
170
169
|
end
|
171
|
-
candidates << Padrino.root("app", "app.rb")
|
172
|
-
candidates.find { |candidate| File.exist?(candidate) }
|
173
170
|
end
|
171
|
+
candidates << Padrino.root("app", "app.rb")
|
172
|
+
candidates.find { |candidate| File.exist?(candidate) }
|
173
|
+
end
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
175
|
+
###
|
176
|
+
# Raises an exception unless app_file is located properly.
|
177
|
+
#
|
178
|
+
def ensure_app_file!
|
179
|
+
message = "Unable to locate source file for app '#{app_class}', try with :app_file => '/path/app.rb'"
|
180
|
+
raise MounterException, message unless @app_file
|
181
|
+
end
|
182
182
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
183
|
+
###
|
184
|
+
# Raises an exception unless app_obj is defined properly.
|
185
|
+
#
|
186
|
+
def ensure_app_object!
|
187
|
+
message = "Unable to locate app for '#{app_class}', try with :app_class => 'MyAppClass'"
|
188
|
+
raise MounterException, message unless @app_obj
|
189
|
+
end
|
190
190
|
end
|
191
191
|
|
192
192
|
class << self
|
@@ -196,7 +196,7 @@ module Padrino
|
|
196
196
|
# @param [Array] args
|
197
197
|
#
|
198
198
|
# @return [String]
|
199
|
-
# the root to the mounted apps base directory
|
199
|
+
# the root to the mounted apps base directory.
|
200
200
|
#
|
201
201
|
def mounted_root(*args)
|
202
202
|
Padrino.root(@mounted_root ||= "", *args)
|
@@ -211,7 +211,7 @@ module Padrino
|
|
211
211
|
end
|
212
212
|
|
213
213
|
##
|
214
|
-
# Inserts a Mounter object into the mounted applications (avoids duplicates)
|
214
|
+
# Inserts a Mounter object into the mounted applications (avoids duplicates).
|
215
215
|
#
|
216
216
|
# @param [Padrino::Mounter] mounter
|
217
217
|
#
|
@@ -220,7 +220,7 @@ module Padrino
|
|
220
220
|
end
|
221
221
|
|
222
222
|
##
|
223
|
-
# Mounts a new sub-application onto Padrino project
|
223
|
+
# Mounts a new sub-application onto Padrino project.
|
224
224
|
#
|
225
225
|
# @see Padrino::Mounter#new
|
226
226
|
#
|
@@ -230,5 +230,5 @@ module Padrino
|
|
230
230
|
def mount(name, options={})
|
231
231
|
Mounter.new(name, options)
|
232
232
|
end
|
233
|
-
end
|
234
|
-
end
|
233
|
+
end
|
234
|
+
end
|