padrino-core 0.10.2 → 0.10.3

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.
Files changed (57) hide show
  1. data/.document +3 -3
  2. data/.yardopts +1 -0
  3. data/{LICENSE → LICENSE.txt} +0 -0
  4. data/README.rdoc +2 -2
  5. data/lib/padrino-core/application/rendering.rb +79 -26
  6. data/lib/padrino-core/application/routing.rb +215 -127
  7. data/lib/padrino-core/application/showexceptions.rb +2 -1
  8. data/lib/padrino-core/application.rb +67 -57
  9. data/lib/padrino-core/caller.rb +10 -4
  10. data/lib/padrino-core/command.rb +11 -0
  11. data/lib/padrino-core/loader.rb +52 -24
  12. data/lib/padrino-core/locale/cs.yml +4 -1
  13. data/lib/padrino-core/locale/da.yml +4 -1
  14. data/lib/padrino-core/locale/de.yml +4 -1
  15. data/lib/padrino-core/locale/en.yml +4 -1
  16. data/lib/padrino-core/locale/es.yml +4 -1
  17. data/lib/padrino-core/locale/fr.yml +4 -1
  18. data/lib/padrino-core/locale/hu.yml +4 -1
  19. data/lib/padrino-core/locale/it.yml +4 -1
  20. data/lib/padrino-core/locale/ja.yml +4 -1
  21. data/lib/padrino-core/locale/lv.yml +34 -0
  22. data/lib/padrino-core/locale/nl.yml +4 -1
  23. data/lib/padrino-core/locale/no.yml +4 -1
  24. data/lib/padrino-core/locale/pl.yml +4 -1
  25. data/lib/padrino-core/locale/pt_br.yml +4 -1
  26. data/lib/padrino-core/locale/ru.yml +4 -1
  27. data/lib/padrino-core/locale/tr.yml +4 -1
  28. data/lib/padrino-core/locale/uk.yml +4 -1
  29. data/lib/padrino-core/locale/zh_cn.yml +4 -1
  30. data/lib/padrino-core/locale/zh_tw.yml +4 -1
  31. data/lib/padrino-core/logger.rb +119 -128
  32. data/lib/padrino-core/mounter.rb +46 -14
  33. data/lib/padrino-core/reloader.rb +5 -3
  34. data/lib/padrino-core/router.rb +30 -11
  35. data/lib/padrino-core/server.rb +14 -5
  36. data/lib/padrino-core/support_lite.rb +54 -20
  37. data/lib/padrino-core/tasks.rb +1 -3
  38. data/lib/padrino-core/version.rb +8 -4
  39. data/lib/padrino-core.rb +58 -11
  40. data/padrino-core.gemspec +1 -1
  41. data/test/fixtures/apps/simple.rb +1 -1
  42. data/test/helper.rb +4 -24
  43. data/test/mini_shoulda.rb +45 -0
  44. data/test/test_application.rb +19 -18
  45. data/test/test_core.rb +2 -2
  46. data/test/test_dependencies.rb +5 -5
  47. data/test/test_filters.rb +2 -1
  48. data/test/test_locale.rb +1 -1
  49. data/test/test_logger.rb +1 -1
  50. data/test/test_mounter.rb +26 -25
  51. data/test/test_reloader_complex.rb +5 -3
  52. data/test/test_reloader_simple.rb +6 -5
  53. data/test/test_rendering.rb +8 -5
  54. data/test/test_restful_routing.rb +1 -1
  55. data/test/test_router.rb +1 -1
  56. data/test/test_routing.rb +33 -12
  57. metadata +13 -9
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- README.rdoc
2
1
  lib/**/*.rb
3
2
  bin/*
4
- features/**/*.feature
5
- LICENSE
3
+ -
4
+ README.rdoc
5
+ LICENSE.txt
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --title 'Padrino Core Documentation' --protected
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: relative_time_ago, js_escape_html, sanitize_html.
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:: Automatically reloads server code during development.
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 automatic template engine detection,
6
- # enhanced layout functionality, locale enabled rendering, among other features.
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 # @private
10
+ class TemplateNotFound < RuntimeError
10
11
  end
11
12
 
12
13
  ##
13
- # This is an array of file patterns to ignore.
14
- # If your editor add a suffix during editing to your files please add it like:
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
- # render_options = [template_path, content_type, locale]
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
- # render_options = [template_path, content_type, locale]
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
- def content_type(type=nil, params={}) # @private
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 (if available)
161
- #
162
- # ==== Example
195
+ # Returns the located layout tuple to be used for the rendered template
196
+ # (if available).
163
197
  #
164
- # resolve_layout
165
- # => ["/layouts/custom", :erb]
166
- # => [nil, nil]
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), I18n.locale.
209
+ # Returns the template path and engine that match content_type (if present),
210
+ # I18n.locale.
175
211
  #
176
- # === Options
212
+ # @param [String] template_path
213
+ # The path of the template.
177
214
  #
178
- # :strict_format:: The resolved template must match the content_type of the request (defaults to false)
179
- # :raise_exceptions:: Raises a +TemplateNotFound+ exception if the template cannot be located.
215
+ # @param [Hash] options
216
+ # Additional options.
180
217
  #
181
- # ==== Example
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
- return cached_template if cached_template
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)