padrino-core 0.10.3 → 0.10.4

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.
@@ -31,7 +31,7 @@ Mailer:: Fast and simple delivery support for sending emails (akin to ActionMail
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
33
  Reloading:: Automatically reloads server code during development.
34
- Localization:: Full support of I18n language localization and can auto-set users locale.
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
37
37
  {seperately into existing Sinatra applications}[http://www.padrinorb.com/guides/standalone-usage-in-sinatra]
@@ -4,8 +4,9 @@ require 'padrino-core/support_lite' unless defined?(SupportLite)
4
4
  FileSet.glob_require('padrino-core/application/*.rb', __FILE__)
5
5
  FileSet.glob_require('padrino-core/*.rb', __FILE__)
6
6
 
7
- # Defines our Constants
7
+ # The Padrino environment (falls back to the rack env or finally develop)
8
8
  PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
9
+ # The Padrino project root path (falls back to the first caller)
9
10
  PADRINO_ROOT = ENV["PADRINO_ROOT"] ||= File.dirname(Padrino.first_caller) unless defined?(PADRINO_ROOT)
10
11
 
11
12
  module Padrino
@@ -2,11 +2,14 @@ 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
5
+ # Padrino enhances the Sinatra 'render' method to have support for
6
6
  # automatic template engine detection, enhanced layout functionality,
7
7
  # locale enabled rendering, among other features.
8
8
  #
9
9
  module Rendering
10
+ ##
11
+ # Exception responsible for when an expected template did not exist.
12
+ #
10
13
  class TemplateNotFound < RuntimeError
11
14
  end
12
15
 
@@ -26,10 +29,10 @@ module Padrino
26
29
  #
27
30
  DEFAULT_RENDERING_OPTIONS = { :strict_format => false, :raise_exceptions => true } unless defined?(DEFAULT_RENDERING_OPTIONS)
28
31
 
29
- ##
30
- # Main class that register this extension.
31
- #
32
32
  class << self
33
+ ##
34
+ # Main class that register this extension.
35
+ #
33
36
  def registered(app)
34
37
  app.send(:include, InstanceMethods)
35
38
  app.extend(ClassMethods)
@@ -37,6 +40,9 @@ module Padrino
37
40
  alias :included :registered
38
41
  end
39
42
 
43
+ ##
44
+ # Class methods responsible for rendering templates as part of a request.
45
+ #
40
46
  module ClassMethods
41
47
  ##
42
48
  # Use layout like rails does or if a block given then like sinatra.
@@ -100,6 +106,7 @@ module Padrino
100
106
  end
101
107
  end
102
108
 
109
+ # Instance methods that allow enhanced rendering to function properly in Padrino.
103
110
  module InstanceMethods
104
111
  attr_reader :current_engine
105
112
 
@@ -270,7 +277,7 @@ module Padrino
270
277
 
271
278
  raise TemplateNotFound, "Template '#{template_path}' not found in '#{view_path}'!" if !located_template && options[:raise_exceptions]
272
279
  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)
280
+ logger.debug :template, began_at, located_template[0] if located_template && settings.logging? && defined?(logger)
274
281
  located_template
275
282
  end
276
283
 
@@ -60,6 +60,7 @@ class HttpRouter
60
60
  end
61
61
  end
62
62
 
63
+ # @private
63
64
  class Route
64
65
  attr_accessor :use_layout, :controller, :cache, :cache_key, :cache_expires_in
65
66
 
@@ -128,9 +129,12 @@ module Padrino
128
129
  # which can be used to refer to the url throughout the application.
129
130
  #
130
131
  module Routing
132
+ # Defines common content-type alias mappings
131
133
  CONTENT_TYPE_ALIASES = { :htm => :html } unless defined?(CONTENT_TYPE_ALIASES)
134
+ # Defines the available route priorities supporting route deferrals.
132
135
  ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
133
136
 
137
+ # Raised when a route was invalid or cannot be processed.
134
138
  class UnrecognizedException < RuntimeError; end
135
139
 
136
140
  class Parent < String # @private
@@ -159,6 +163,7 @@ module Padrino
159
163
  alias :included :registered
160
164
  end
161
165
 
166
+ # Class methods responsible for enhanced routing for controllers.
162
167
  module ClassMethods
163
168
  ##
164
169
  # Method for organize in a better way our routes.
@@ -294,6 +299,9 @@ module Padrino
294
299
  add_filter :after, &(args.empty? ? block : construct_filter(*args, &block))
295
300
  end
296
301
 
302
+ ##
303
+ # Adds a filter hook to a request.
304
+ #
297
305
  def add_filter(type, &block)
298
306
  filters[type] << block
299
307
  end
@@ -393,6 +401,7 @@ module Padrino
393
401
  end
394
402
  alias :urls :router
395
403
 
404
+ # Compiles the routes including deferred routes.
396
405
  def compiled_router
397
406
  if deferred_routes.empty?
398
407
  router
@@ -403,10 +412,14 @@ module Padrino
403
412
  end
404
413
  end
405
414
 
415
+ # Returns all routes that were deferred based on their priority.
406
416
  def deferred_routes
407
417
  @deferred_routes ||= Hash[ROUTE_PRIORITY.values.sort.map{|p| [p, []]}]
408
418
  end
409
419
 
420
+ ##
421
+ # Resets the http router and all deferred routes.
422
+ #
410
423
  def reset_router!
411
424
  @deferred_routes = nil
412
425
  router.reset!
@@ -480,13 +493,6 @@ module Padrino
480
493
  route('HEAD', path, *args, &block)
481
494
  end
482
495
 
483
- ##
484
- # Returns the lat controller, useful inside a layout/view.
485
- #
486
- def current_controller
487
- @_controller and @_controller[-1]
488
- end
489
-
490
496
  private
491
497
  # Parse params from the url method
492
498
  def value_to_param(value)
@@ -780,6 +786,9 @@ module Padrino
780
786
  end
781
787
  end
782
788
 
789
+ ##
790
+ # Instance methods related to recognizing and processing routes and serving static files.
791
+ #
783
792
  module InstanceMethods
784
793
  ##
785
794
  # Instance method for url generation.
@@ -802,10 +811,16 @@ module Padrino
802
811
  end
803
812
  alias :url_for :url
804
813
 
814
+ ##
815
+ # Returns the recognized path for a route.
816
+ #
805
817
  def recognize_path(path)
806
818
  settings.recognize_path(path)
807
819
  end
808
820
 
821
+ ##
822
+ # Returns the current path within a route from specified +path_params+.
823
+ #
809
824
  def current_path(*path_params)
810
825
  if path_params.last.is_a?(Hash)
811
826
  path_params[-1] = params.merge(path_params[-1])
@@ -815,6 +830,17 @@ module Padrino
815
830
  @route.url(*path_params)
816
831
  end
817
832
 
833
+ ##
834
+ # Returns the current route
835
+ #
836
+ # @example
837
+ # -if route.controller == :press
838
+ # %li=show_article
839
+ #
840
+ def route
841
+ @route
842
+ end
843
+
818
844
  ##
819
845
  # This is mostly just a helper so request.path_info isn't changed when
820
846
  # serving files from the public directory.
@@ -834,6 +860,7 @@ module Padrino
834
860
  def static!
835
861
  if path = static_file?(request.path_info)
836
862
  env['sinatra.static_file'] = path
863
+ cache_control *settings.static_cache_control if settings.static_cache_control?
837
864
  send_file(path, :disposition => nil)
838
865
  end
839
866
  end
@@ -1,4 +1,6 @@
1
1
  module Padrino
2
+
3
+ # List of callers in a Padrino application that should be ignored as part of a stack trace.
2
4
  PADRINO_IGNORE_CALLERS = [
3
5
  %r{lib/padrino-.*$}, # all padrino code
4
6
  %r{/padrino-.*/(lib|bin)}, # all padrino code
@@ -1,5 +1,6 @@
1
- # Defines our PADRINO_LOGGER constants
1
+ # Defines the log level for a Padrino project.
2
2
  PADRINO_LOG_LEVEL = ENV['PADRINO_LOG_LEVEL'] unless defined?(PADRINO_LOG_LEVEL)
3
+ # Defines the logger used for a Padrino project.
3
4
  PADRINO_LOGGER = ENV['PADRINO_LOGGER'] unless defined?(PADRINO_LOGGER)
4
5
 
5
6
  module Padrino
@@ -155,7 +156,7 @@ module Padrino
155
156
  # Either an IO object or a name of a logfile. Defaults to $stdout
156
157
  #
157
158
  # @option options [Symbol] :log_level (:production in the production environment and :debug otherwise)
158
- # The log level from, e.g. :fatal or :info.
159
+ # The log level from, e.g. :fatal or :info.
159
160
  #
160
161
  # @option options [Symbol] :auto_flush (true)
161
162
  # Whether the log should automatically flush after new messages are
@@ -318,12 +319,18 @@ module Padrino
318
319
  env["PATH_INFO"],
319
320
  env["QUERY_STRING"].empty? ? "" : "?" + env["QUERY_STRING"],
320
321
  ' - ',
321
- status.to_s[0..3].bold
322
+ status.to_s[0..3].bold,
323
+ ' ',
324
+ code_to_name(status)
322
325
  ] * '',
323
326
  :debug,
324
327
  :magenta
325
328
  )
326
329
  end
330
+
331
+ def code_to_name(status)
332
+ ::Rack::Utils::HTTP_STATUS_CODES[status.to_i] || ''
333
+ end
327
334
  end # Rack
328
335
  end # Logger
329
336
  end # Padrino
@@ -12,8 +12,12 @@ module Padrino
12
12
  # Please note that this will not reload files in the background, and does so
13
13
  # only when explicitly invoked.
14
14
  #
15
+
16
+ # The modification times for every file in a project.
15
17
  MTIMES = {}
18
+ # The list of files loaded as part of a project.
16
19
  LOADED_FILES = {}
20
+ # The list of object constants and classes loaded as part of the project.
17
21
  LOADED_CLASSES = {}
18
22
 
19
23
  class << self
@@ -237,6 +241,7 @@ module Padrino
237
241
  @last = (Time.now - cooldown)
238
242
  end
239
243
 
244
+ # Invoked in order to perform the reload as part of the request stack.
240
245
  def call(env)
241
246
  if @cooldown && Time.now > @last + @cooldown
242
247
  Thread.list.size > 1 ? Thread.exclusive { Padrino.reload! } : Padrino.reload!
@@ -24,7 +24,7 @@ module Padrino
24
24
  # end
25
25
  # run routes
26
26
  #
27
- # @semipublic
27
+ # @api semipublic
28
28
  class Router
29
29
 
30
30
  # Constructs a new route mapper instance
@@ -5,7 +5,8 @@
5
5
  # without include full padrino core.
6
6
  #
7
7
  module Padrino
8
- VERSION = '0.10.3' unless defined?(Padrino::VERSION)
8
+ # The version constant for the current version of Padrino.
9
+ VERSION = '0.10.4' unless defined?(Padrino::VERSION)
9
10
 
10
11
  #
11
12
  # The current Padrino version.
@@ -23,15 +23,15 @@ Gem::Specification.new do |s|
23
23
  s.rdoc_options = ["--charset=UTF-8"]
24
24
 
25
25
  # TODO remove after a couple versions
26
- s.post_install_message = "\e[32m" + ("*" * 20)
27
- s.post_install_message << "\n UPGRADE NOTES\n\n\e[31m When upgrading, please 'enable :sessions' for each application"
28
- s.post_install_message << " as shown here:\e[0m http://bit.ly/kODKMx\n"
29
- s.post_install_message << "\e[31m When upgrading, please 'register Padrino::Rendering' for each application"
30
- s.post_install_message << " as shown here:\e[0m https://gist.github.com/1d36a35794dbbd664ea4"
31
- s.post_install_message << "\n\e[32m" + ("*" * 20) + "\n\e[0m"
26
+ # s.post_install_message = "\e[32m" + ("*" * 20)
27
+ # s.post_install_message << "\n UPGRADE NOTES\n\n\e[31m When upgrading, please 'enable :sessions' for each application"
28
+ # s.post_install_message << " as shown here:\e[0m http://bit.ly/kODKMx\n"
29
+ # s.post_install_message << "\e[31m When upgrading, please 'register Padrino::Rendering' for each application"
30
+ # s.post_install_message << " as shown here:\e[0m https://gist.github.com/1d36a35794dbbd664ea4"
31
+ # s.post_install_message << "\n\e[32m" + ("*" * 20) + "\n\e[0m"
32
32
 
33
33
  s.add_dependency("tilt", "~> 1.3.0")
34
- s.add_dependency("sinatra", "~> 1.3.0")
34
+ s.add_dependency("sinatra", "~> 1.3.1")
35
35
  s.add_dependency("http_router", "~> 0.10.2")
36
36
  s.add_dependency("thor", "~> 0.14.3")
37
37
  s.add_dependency("activesupport", "~> 3.1.0")
@@ -64,6 +64,15 @@ describe "PadrinoLogger" do
64
64
  assert_match /GET/, Padrino.logger.log.string
65
65
  end
66
66
 
67
+ should 'log an application\'s status code' do
68
+ mock_app do
69
+ enable :logging
70
+ get("/"){ "Foo" }
71
+ end
72
+ get "/"
73
+ assert_match /\e\[1m200\e\[0m OK/, Padrino.logger.log.string
74
+ end
75
+
67
76
  context "static asset logging" do
68
77
  should 'not log static assets by default' do
69
78
  mock_app do
@@ -203,6 +203,27 @@ describe "Rendering" do
203
203
 
204
204
  context 'for application render functionality' do
205
205
 
206
+ should "work properly with logging and missing layout" do
207
+ create_view :index, "<%= foo %>"
208
+ mock_app do
209
+ enable :logging
210
+ get("/") { render "index", { :layout => true }, { :foo => "bar" } }
211
+ end
212
+ get "/"
213
+ assert_equal "bar", body
214
+ end
215
+
216
+ should "work properly with logging and layout" do
217
+ create_layout :application, "layout <%= yield %>"
218
+ create_view :index, "<%= foo %>"
219
+ mock_app do
220
+ enable :logging
221
+ get("/") { render "index", { :layout => true }, { :foo => "bar" } }
222
+ end
223
+ get "/"
224
+ assert_equal "layout bar", body
225
+ end
226
+
206
227
  should 'be compatible with sinatra render' do
207
228
  mock_app do
208
229
  get("/"){ render :erb, "<%= 1+2 %>" }
@@ -4,6 +4,31 @@ class FooError < RuntimeError; end
4
4
 
5
5
 
6
6
  describe "Routing" do
7
+ setup do
8
+ Padrino::Application.send(:register, Padrino::Rendering)
9
+ Padrino::Rendering::DEFAULT_RENDERING_OPTIONS[:strict_format] = false
10
+ end
11
+
12
+ should "serve static files with simple cache control" do
13
+ mock_app do
14
+ set :static_cache_control, :public
15
+ set :public_folder, File.dirname(__FILE__)
16
+ end
17
+ get "/#{File.basename(__FILE__)}"
18
+ assert headers.has_key?('Cache-Control')
19
+ assert_equal headers['Cache-Control'], 'public'
20
+ end # static simple
21
+
22
+ should "serve static files with cache control and max_age" do
23
+ mock_app do
24
+ set :static_cache_control, [:public, :must_revalidate, {:max_age => 300}]
25
+ set :public_folder, File.dirname(__FILE__)
26
+ end
27
+ get "/#{File.basename(__FILE__)}"
28
+ assert headers.has_key?('Cache-Control')
29
+ assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
30
+ end # static max_age
31
+
7
32
  should 'ignore trailing delimiters for basic route' do
8
33
  mock_app do
9
34
  get("/foo"){ "okey" }
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 3
10
- version: 0.10.3
5
+ version: 0.10.4
11
6
  platform: ruby
12
7
  authors:
13
8
  - Padrino Team
@@ -18,8 +13,7 @@ autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
15
 
21
- date: 2011-10-03 00:00:00 -07:00
22
- default_executable:
16
+ date: 2011-10-12 00:00:00 Z
23
17
  dependencies:
24
18
  - !ruby/object:Gem::Dependency
25
19
  name: tilt
@@ -29,11 +23,6 @@ dependencies:
29
23
  requirements:
30
24
  - - ~>
31
25
  - !ruby/object:Gem::Version
32
- hash: 27
33
- segments:
34
- - 1
35
- - 3
36
- - 0
37
26
  version: 1.3.0
38
27
  type: :runtime
39
28
  version_requirements: *id001
@@ -45,12 +34,7 @@ dependencies:
45
34
  requirements:
46
35
  - - ~>
47
36
  - !ruby/object:Gem::Version
48
- hash: 27
49
- segments:
50
- - 1
51
- - 3
52
- - 0
53
- version: 1.3.0
37
+ version: 1.3.1
54
38
  type: :runtime
55
39
  version_requirements: *id002
56
40
  - !ruby/object:Gem::Dependency
@@ -61,11 +45,6 @@ dependencies:
61
45
  requirements:
62
46
  - - ~>
63
47
  - !ruby/object:Gem::Version
64
- hash: 51
65
- segments:
66
- - 0
67
- - 10
68
- - 2
69
48
  version: 0.10.2
70
49
  type: :runtime
71
50
  version_requirements: *id003
@@ -77,11 +56,6 @@ dependencies:
77
56
  requirements:
78
57
  - - ~>
79
58
  - !ruby/object:Gem::Version
80
- hash: 33
81
- segments:
82
- - 0
83
- - 14
84
- - 3
85
59
  version: 0.14.3
86
60
  type: :runtime
87
61
  version_requirements: *id004
@@ -93,11 +67,6 @@ dependencies:
93
67
  requirements:
94
68
  - - ~>
95
69
  - !ruby/object:Gem::Version
96
- hash: 3
97
- segments:
98
- - 3
99
- - 1
100
- - 0
101
70
  version: 3.1.0
102
71
  type: :runtime
103
72
  version_requirements: *id005
@@ -186,15 +155,10 @@ files:
186
155
  - test/test_restful_routing.rb
187
156
  - test/test_router.rb
188
157
  - test/test_routing.rb
189
- has_rdoc: true
190
158
  homepage: http://www.padrinorb.com
191
159
  licenses: []
192
160
 
193
- post_install_message: "\e[32m********************\n UPGRADE NOTES\n\n\
194
- \e[31m When upgrading, please 'enable :sessions' for each application as shown here:\e[0m http://bit.ly/kODKMx\n\
195
- \e[31m When upgrading, please 'register Padrino::Rendering' for each application as shown here:\e[0m https://gist.github.com/1d36a35794dbbd664ea4\n\
196
- \e[32m********************\n\
197
- \e[0m"
161
+ post_install_message:
198
162
  rdoc_options:
199
163
  - --charset=UTF-8
200
164
  require_paths:
@@ -204,25 +168,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
168
  requirements:
205
169
  - - ">="
206
170
  - !ruby/object:Gem::Version
207
- hash: 3
208
- segments:
209
- - 0
210
171
  version: "0"
211
172
  required_rubygems_version: !ruby/object:Gem::Requirement
212
173
  none: false
213
174
  requirements:
214
175
  - - ">="
215
176
  - !ruby/object:Gem::Version
216
- hash: 23
217
- segments:
218
- - 1
219
- - 3
220
- - 6
221
177
  version: 1.3.6
222
178
  requirements: []
223
179
 
224
180
  rubyforge_project: padrino-core
225
- rubygems_version: 1.6.2
181
+ rubygems_version: 1.8.10
226
182
  signing_key:
227
183
  specification_version: 3
228
184
  summary: The required Padrino core gem