padrino-core 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -3
- data/.yardopts +1 -0
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.rdoc +2 -2
- data/lib/padrino-core/application/rendering.rb +79 -26
- data/lib/padrino-core/application/routing.rb +215 -127
- data/lib/padrino-core/application/showexceptions.rb +2 -1
- data/lib/padrino-core/application.rb +67 -57
- data/lib/padrino-core/caller.rb +10 -4
- data/lib/padrino-core/command.rb +11 -0
- data/lib/padrino-core/loader.rb +52 -24
- data/lib/padrino-core/locale/cs.yml +4 -1
- data/lib/padrino-core/locale/da.yml +4 -1
- data/lib/padrino-core/locale/de.yml +4 -1
- data/lib/padrino-core/locale/en.yml +4 -1
- data/lib/padrino-core/locale/es.yml +4 -1
- data/lib/padrino-core/locale/fr.yml +4 -1
- data/lib/padrino-core/locale/hu.yml +4 -1
- data/lib/padrino-core/locale/it.yml +4 -1
- data/lib/padrino-core/locale/ja.yml +4 -1
- data/lib/padrino-core/locale/lv.yml +34 -0
- data/lib/padrino-core/locale/nl.yml +4 -1
- data/lib/padrino-core/locale/no.yml +4 -1
- data/lib/padrino-core/locale/pl.yml +4 -1
- data/lib/padrino-core/locale/pt_br.yml +4 -1
- data/lib/padrino-core/locale/ru.yml +4 -1
- data/lib/padrino-core/locale/tr.yml +4 -1
- data/lib/padrino-core/locale/uk.yml +4 -1
- data/lib/padrino-core/locale/zh_cn.yml +4 -1
- data/lib/padrino-core/locale/zh_tw.yml +4 -1
- data/lib/padrino-core/logger.rb +119 -128
- data/lib/padrino-core/mounter.rb +46 -14
- data/lib/padrino-core/reloader.rb +5 -3
- data/lib/padrino-core/router.rb +30 -11
- data/lib/padrino-core/server.rb +14 -5
- data/lib/padrino-core/support_lite.rb +54 -20
- data/lib/padrino-core/tasks.rb +1 -3
- data/lib/padrino-core/version.rb +8 -4
- data/lib/padrino-core.rb +58 -11
- data/padrino-core.gemspec +1 -1
- data/test/fixtures/apps/simple.rb +1 -1
- data/test/helper.rb +4 -24
- data/test/mini_shoulda.rb +45 -0
- data/test/test_application.rb +19 -18
- data/test/test_core.rb +2 -2
- data/test/test_dependencies.rb +5 -5
- data/test/test_filters.rb +2 -1
- data/test/test_locale.rb +1 -1
- data/test/test_logger.rb +1 -1
- data/test/test_mounter.rb +26 -25
- data/test/test_reloader_complex.rb +5 -3
- data/test/test_reloader_simple.rb +6 -5
- data/test/test_rendering.rb +8 -5
- data/test/test_restful_routing.rb +1 -1
- data/test/test_router.rb +1 -1
- data/test/test_routing.rb +33 -12
- metadata +13 -9
data/.document
CHANGED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--title 'Padrino Core Documentation' --protected
|
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/README.rdoc
CHANGED
@@ -26,11 +26,11 @@ Routing:: Full url named routes, named params, respond_to support, before/after
|
|
26
26
|
Tag Helpers:: View helpers such as: tag, content_tag, input_tag.
|
27
27
|
Asset Helpers:: View helpers such as: link_to, image_tag, javascript_include_tag.
|
28
28
|
Form Helpers:: Builder support such as: form_tag, form_for, field_set_tag, text_field.
|
29
|
-
Text Helpers:: Useful formatting like:
|
29
|
+
Text Helpers:: Useful formatting like: time_ago_in_words, js_escape_html, sanitize_html.
|
30
30
|
Mailer:: Fast and simple delivery support for sending emails (akin to ActionMailer).
|
31
31
|
Admin:: Builtin Admin interface (like Django)
|
32
32
|
Logging:: Provide a unified logger that can interact with your ORM or any library.
|
33
|
-
Reloading::
|
33
|
+
Reloading:: Automatically reloads server code during development.
|
34
34
|
Localization:: Full support of I18n language localization and can auto-set user’s locale.
|
35
35
|
|
36
36
|
Keep in mind, the user will be able to pull in these components
|
@@ -2,17 +2,19 @@ require 'padrino-core/support_lite' unless defined?(SupportLite)
|
|
2
2
|
|
3
3
|
module Padrino
|
4
4
|
##
|
5
|
-
# Padrino enhances the Sinatra ‘render’ method to have support for
|
6
|
-
#
|
5
|
+
# Padrino enhances the Sinatra ‘render’ method to have support for
|
6
|
+
# automatic template engine detection, enhanced layout functionality,
|
7
|
+
# locale enabled rendering, among other features.
|
7
8
|
#
|
8
9
|
module Rendering
|
9
|
-
class TemplateNotFound < RuntimeError
|
10
|
+
class TemplateNotFound < RuntimeError
|
10
11
|
end
|
11
12
|
|
12
13
|
##
|
13
|
-
# This is an array of file patterns to ignore.
|
14
|
-
#
|
14
|
+
# This is an array of file patterns to ignore. If your editor add a
|
15
|
+
# suffix during editing to your files please add it like:
|
15
16
|
#
|
17
|
+
# @example
|
16
18
|
# Padrino::Rendering::IGNORE_FILE_PATTERN << /~$/
|
17
19
|
#
|
18
20
|
IGNORE_FILE_PATTERN = [
|
@@ -20,12 +22,12 @@ module Padrino
|
|
20
22
|
] unless defined?(IGNORE_FILE_PATTERN)
|
21
23
|
|
22
24
|
##
|
23
|
-
# Default rendering options used in the #render-method
|
25
|
+
# Default rendering options used in the #render-method.
|
24
26
|
#
|
25
27
|
DEFAULT_RENDERING_OPTIONS = { :strict_format => false, :raise_exceptions => true } unless defined?(DEFAULT_RENDERING_OPTIONS)
|
26
28
|
|
27
29
|
##
|
28
|
-
# Main class that register this extension
|
30
|
+
# Main class that register this extension.
|
29
31
|
#
|
30
32
|
class << self
|
31
33
|
def registered(app)
|
@@ -49,6 +51,11 @@ module Padrino
|
|
49
51
|
# +app+/+views+/+layouts+/+custom+.(+haml+|+erb+|+xxx+)
|
50
52
|
# +app+/+views+/+custom+.(+haml+|+erb+|+xxx+)
|
51
53
|
#
|
54
|
+
# @param [Symbol] name (:layout)
|
55
|
+
# The layout to use.
|
56
|
+
#
|
57
|
+
# @yield []
|
58
|
+
#
|
52
59
|
def layout(name=:layout, &block)
|
53
60
|
return super(name, &block) if block_given?
|
54
61
|
@layout = name
|
@@ -57,16 +64,19 @@ module Padrino
|
|
57
64
|
##
|
58
65
|
# Returns the cached template file to render for a given url, content_type and locale.
|
59
66
|
#
|
60
|
-
#
|
67
|
+
# @param [Array<template_path, content_type, locale>] render_options
|
61
68
|
#
|
62
69
|
def fetch_template_file(render_options)
|
63
70
|
(@_cached_templates ||= {})[render_options]
|
64
71
|
end
|
65
72
|
|
66
|
-
|
73
|
+
##
|
67
74
|
# Caches the template file for the given rendering options
|
68
75
|
#
|
69
|
-
#
|
76
|
+
# @param [String] template_file
|
77
|
+
# The path of the template file.
|
78
|
+
#
|
79
|
+
# @param [Array<template_path, content_type, locale>] render_options
|
70
80
|
#
|
71
81
|
def cache_template_file!(template_file, render_options)
|
72
82
|
(@_cached_templates ||= {})[render_options] = template_file || []
|
@@ -75,6 +85,9 @@ module Padrino
|
|
75
85
|
##
|
76
86
|
# Returns the cached layout path.
|
77
87
|
#
|
88
|
+
# @param [Symbol, nil] given_layout
|
89
|
+
# The requested layout.
|
90
|
+
#
|
78
91
|
def fetch_layout_path(given_layout=nil)
|
79
92
|
layout_name = given_layout || @layout || :application
|
80
93
|
@_cached_layout ||= {}
|
@@ -90,7 +103,31 @@ module Padrino
|
|
90
103
|
module InstanceMethods
|
91
104
|
attr_reader :current_engine
|
92
105
|
|
93
|
-
|
106
|
+
##
|
107
|
+
# Get/Set the content_type
|
108
|
+
#
|
109
|
+
# @param [String, nil] type
|
110
|
+
# The Content-Type to use.
|
111
|
+
#
|
112
|
+
# @param [Symbol, nil] type.
|
113
|
+
# Look and parse the given symbol to the matched Content-Type.
|
114
|
+
#
|
115
|
+
# @param [Hash] params
|
116
|
+
# Additional params to append to the Content-Type.
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# case content_type
|
120
|
+
# when :js then do_some
|
121
|
+
# when :css then do_another
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# content_type :js
|
125
|
+
# # => set the response with 'application/javascript' Content-Type
|
126
|
+
# content_type 'text/html'
|
127
|
+
#
|
128
|
+
# # => set directly the Content-Type to 'text/html'
|
129
|
+
#
|
130
|
+
def content_type(type=nil, params={})
|
94
131
|
unless type.nil?
|
95
132
|
super(type, params)
|
96
133
|
@_content_type = type
|
@@ -139,10 +176,8 @@ module Padrino
|
|
139
176
|
options[:layout] = layout_path || false # We need to force layout false so sinatra don't try to render it
|
140
177
|
options[:layout] = false unless layout_engine == engine # TODO allow different layout engine
|
141
178
|
options[:layout_engine] = layout_engine || engine if options[:layout]
|
142
|
-
logger.debug "Resolving layout #{root}/views#{options[:layout]}" if defined?(logger) && options[:layout].present?
|
143
179
|
elsif options[:layout].present?
|
144
180
|
options[:layout] = settings.fetch_layout_path(options[:layout] || @layout)
|
145
|
-
logger.debug "Resolving layout #{root}/views#{options[:layout]}" if defined?(logger)
|
146
181
|
end
|
147
182
|
|
148
183
|
# Cleanup the template
|
@@ -157,13 +192,13 @@ module Padrino
|
|
157
192
|
end
|
158
193
|
|
159
194
|
##
|
160
|
-
# Returns the located layout tuple to be used for the rendered template
|
161
|
-
#
|
162
|
-
# ==== Example
|
195
|
+
# Returns the located layout tuple to be used for the rendered template
|
196
|
+
# (if available).
|
163
197
|
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
# => [
|
198
|
+
# @example
|
199
|
+
# resolve_layout
|
200
|
+
# # => ["/layouts/custom", :erb]
|
201
|
+
# # => [nil, nil]
|
167
202
|
#
|
168
203
|
def resolved_layout
|
169
204
|
located_layout = resolve_template(settings.fetch_layout_path, :raise_exceptions => false, :strict_format => true)
|
@@ -171,25 +206,42 @@ module Padrino
|
|
171
206
|
end
|
172
207
|
|
173
208
|
##
|
174
|
-
# Returns the template path and engine that match content_type (if present),
|
209
|
+
# Returns the template path and engine that match content_type (if present),
|
210
|
+
# I18n.locale.
|
175
211
|
#
|
176
|
-
#
|
212
|
+
# @param [String] template_path
|
213
|
+
# The path of the template.
|
177
214
|
#
|
178
|
-
#
|
179
|
-
#
|
215
|
+
# @param [Hash] options
|
216
|
+
# Additional options.
|
180
217
|
#
|
181
|
-
#
|
218
|
+
# @option options [Boolean] :strict_format (false)
|
219
|
+
# The resolved template must match the content_type of the request.
|
182
220
|
#
|
221
|
+
# @option options [Boolean] :raise_exceptions (false)
|
222
|
+
# Raises a {TemplateNotFound} exception if the template cannot be located.
|
223
|
+
#
|
224
|
+
# @return [Array<Symbol, Symbol>]
|
225
|
+
# The path and format of the template.
|
226
|
+
#
|
227
|
+
# @raise [TemplateNotFound]
|
228
|
+
# The template could not be found.
|
229
|
+
#
|
230
|
+
# @example
|
183
231
|
# get "/foo", :provides => [:html, :js] do; render 'path/to/foo'; end
|
184
232
|
# # If you request "/foo.js" with I18n.locale == :ru => [:"/path/to/foo.ru.js", :erb]
|
185
233
|
# # If you request "/foo" with I18n.locale == :de => [:"/path/to/foo.de.haml", :haml]
|
186
234
|
#
|
187
235
|
def resolve_template(template_path, options={})
|
236
|
+
began_at = Time.now
|
188
237
|
# Fetch cached template for rendering options
|
189
238
|
template_path = template_path.to_s[0] == ?/ ? template_path.to_s : "/#{template_path}"
|
190
239
|
rendering_options = [template_path, content_type, locale]
|
191
240
|
cached_template = settings.fetch_template_file(rendering_options)
|
192
|
-
|
241
|
+
if cached_template
|
242
|
+
logger.debug :cached, began_at, cached_template[0] if settings.logging? && defined?(logger)
|
243
|
+
return cached_template
|
244
|
+
end
|
193
245
|
|
194
246
|
# Resolve view path and options
|
195
247
|
options.reverse_merge!(DEFAULT_RENDERING_OPTIONS)
|
@@ -218,11 +270,12 @@ module Padrino
|
|
218
270
|
|
219
271
|
raise TemplateNotFound, "Template '#{template_path}' not found in '#{view_path}'!" if !located_template && options[:raise_exceptions]
|
220
272
|
settings.cache_template_file!(located_template, rendering_options) unless settings.reload_templates?
|
273
|
+
logger.debug :template, began_at, located_template[0] if settings.logging? && defined?(logger)
|
221
274
|
located_template
|
222
275
|
end
|
223
276
|
|
224
277
|
##
|
225
|
-
# Return the I18n.locale if I18n is defined
|
278
|
+
# Return the I18n.locale if I18n is defined.
|
226
279
|
#
|
227
280
|
def locale
|
228
281
|
I18n.locale if defined?(I18n)
|