padrino-core 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/padrino-core.rb +3 -3
  3. data/lib/padrino-core/application.rb +7 -6
  4. data/lib/padrino-core/application/rendering.rb +11 -7
  5. data/lib/padrino-core/application/routing.rb +24 -22
  6. data/lib/padrino-core/caller.rb +1 -1
  7. data/lib/padrino-core/cli/adapter.rb +1 -1
  8. data/lib/padrino-core/cli/base.rb +1 -2
  9. data/lib/padrino-core/cli/rake.rb +1 -1
  10. data/lib/padrino-core/command.rb +1 -1
  11. data/lib/padrino-core/images/404.png +0 -0
  12. data/lib/padrino-core/images/500.png +0 -0
  13. data/lib/padrino-core/loader.rb +1 -1
  14. data/lib/padrino-core/locale/no.yml +0 -0
  15. data/lib/padrino-core/logger.rb +1 -11
  16. data/lib/padrino-core/mounter.rb +2 -2
  17. data/lib/padrino-core/reloader.rb +2 -2
  18. data/lib/padrino-core/router.rb +1 -1
  19. data/lib/padrino-core/server.rb +1 -1
  20. data/lib/padrino-core/support_lite.rb +26 -8
  21. data/lib/padrino-core/tasks.rb +1 -1
  22. data/lib/padrino-core/version.rb +1 -1
  23. data/padrino-core.gemspec +3 -3
  24. data/test/fixtures/apps/complex.rb +6 -1
  25. data/test/fixtures/apps/simple.rb +2 -2
  26. data/test/fixtures/dependencies/a.rb +1 -1
  27. data/test/fixtures/dependencies/b.rb +1 -1
  28. data/test/fixtures/dependencies/c.rb +1 -1
  29. data/test/fixtures/dependencies/d.rb +1 -1
  30. data/test/helper.rb +3 -3
  31. data/test/test_application.rb +26 -2
  32. data/test/test_core.rb +2 -2
  33. data/test/test_logger.rb +1 -1
  34. data/test/test_mounter.rb +1 -1
  35. data/test/test_reloader_complex.rb +8 -1
  36. data/test/test_reloader_simple.rb +1 -1
  37. data/test/test_rendering.rb +1 -1
  38. data/test/test_restful_routing.rb +1 -1
  39. data/test/test_router.rb +1 -1
  40. data/test/test_routing.rb +108 -3
  41. metadata +42 -4
@@ -291,4 +291,4 @@ For a complete overview of Padrino terminal commands, check out the
291
291
 
292
292
  == Copyright
293
293
 
294
- Copyright (c) 2011 Padrino. See LICENSE for details.
294
+ Copyright (c) 2011 Padrino. See LICENSE for details.
@@ -9,7 +9,7 @@ PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless
9
9
  PADRINO_ROOT = ENV["PADRINO_ROOT"] ||= File.dirname(Padrino.first_caller) unless defined?(PADRINO_ROOT)
10
10
 
11
11
  module Padrino
12
- class ApplicationLoadError < RuntimeError #:nodoc:
12
+ class ApplicationLoadError < RuntimeError # @private
13
13
  end
14
14
 
15
15
  class << self
@@ -80,7 +80,7 @@ module Padrino
80
80
  $KCODE='u'
81
81
  else
82
82
  Encoding.default_external = Encoding::UTF_8
83
- Encoding.default_internal = nil # Encoding::UTF_8
83
+ Encoding.default_internal = Encoding::UTF_8
84
84
  end
85
85
  nil
86
86
  end
@@ -116,4 +116,4 @@ module Padrino
116
116
  middleware << [m, args, block]
117
117
  end
118
118
  end # self
119
- end # Padrino
119
+ end # Padrino
@@ -1,5 +1,5 @@
1
1
  module Padrino
2
- class ApplicationSetupError < RuntimeError #:nodoc:
2
+ class ApplicationSetupError < RuntimeError # @private
3
3
  end
4
4
 
5
5
  ##
@@ -11,7 +11,7 @@ module Padrino
11
11
 
12
12
  class << self
13
13
 
14
- def inherited(base) #:nodoc:
14
+ def inherited(base) # @private
15
15
  logger.devel "Setup #{base}"
16
16
  CALLERS_TO_IGNORE.concat(PADRINO_IGNORE_CALLERS)
17
17
  base.default_configuration!
@@ -54,11 +54,12 @@ module Padrino
54
54
  logger.devel "Reloading #{self}"
55
55
  @_dependencies = nil # Reset dependencies
56
56
  reset! # Reset sinatra app
57
- reset_routes! # Remove all existing user-defined application routes
57
+ reset_router! # Reset all routes
58
58
  Padrino.require_dependencies(self.app_file, :force => true) # Reload the app file
59
- require_dependencies # Reload dependencies
60
59
  register_initializers # Reload our middlewares
60
+ require_dependencies # Reload dependencies
61
61
  default_filters! # Reload filters
62
+ default_routes! # Reload default routes
62
63
  default_errors! # Reload our errors
63
64
  I18n.reload! if defined?(I18n) # Reload also our translations
64
65
  end
@@ -217,7 +218,7 @@ module Padrino
217
218
  response.status = 500
218
219
  content_type 'text/html'
219
220
  '<h1>Internal Server Error</h1>'
220
- end
221
+ end unless errors.has_key?(::Exception)
221
222
  end
222
223
  end
223
224
 
@@ -256,4 +257,4 @@ module Padrino
256
257
  end
257
258
  end # render method
258
259
  end # Application
259
- end # Padrino
260
+ end # Padrino
@@ -6,7 +6,7 @@ module Padrino
6
6
  # enhanced layout functionality, locale enabled rendering, among other features.
7
7
  #
8
8
  module Rendering
9
- class TemplateNotFound < RuntimeError #:nodoc:
9
+ class TemplateNotFound < RuntimeError # @private
10
10
  end
11
11
 
12
12
  ##
@@ -90,8 +90,12 @@ module Padrino
90
90
  module InstanceMethods
91
91
  attr_reader :current_engine
92
92
 
93
- def content_type(type=nil, params={}) #:nodoc:
94
- type.nil? ? @_content_type : super(type, params)
93
+ def content_type(type=nil, params={}) # @private
94
+ unless type.nil?
95
+ super(type, params)
96
+ @_content_type = type
97
+ end
98
+ @_content_type
95
99
  end
96
100
 
97
101
  private
@@ -108,7 +112,7 @@ module Padrino
108
112
  #
109
113
  def render(engine, data=nil, options={}, locals={}, &block)
110
114
  # If engine is a hash then render data converted to json
111
- return engine.to_json if engine.is_a?(Hash)
115
+ content_type(:json, :charset => 'utf-8') and return engine.to_json if engine.is_a?(Hash)
112
116
 
113
117
  # If engine is nil, ignore engine parameter and shift up all arguments
114
118
  # render nil, "index", { :layout => true }, { :localvar => "foo" }
@@ -121,7 +125,7 @@ module Padrino
121
125
 
122
126
  # If data is unassigned then this is a likely a template to be resolved
123
127
  # This means that no engine was explicitly defined
124
- data, engine = *resolve_template(engine, options) if data.nil?
128
+ data, engine = *resolve_template(engine, options.dup) if data.nil?
125
129
 
126
130
  # Setup root
127
131
  root = settings.respond_to?(:root) ? settings.root : ""
@@ -182,7 +186,7 @@ module Padrino
182
186
  #
183
187
  def resolve_template(template_path, options={})
184
188
  # Fetch cached template for rendering options
185
- template_path = "/#{template_path}" unless template_path.to_s[0] == ?/
189
+ template_path = template_path.to_s[0] == ?/ ? template_path.to_s : "/#{template_path}"
186
190
  rendering_options = [template_path, content_type, locale]
187
191
  cached_template = settings.fetch_template_file(rendering_options)
188
192
  return cached_template if cached_template
@@ -225,4 +229,4 @@ module Padrino
225
229
  end
226
230
  end # InstanceMethods
227
231
  end # Rendering
228
- end # Padrino
232
+ end # Padrino
@@ -1,7 +1,7 @@
1
1
  require 'http_router' unless defined?(HttpRouter)
2
2
  require 'padrino-core/support_lite' unless defined?(SupportLite)
3
3
 
4
- class Sinatra::Request #:nodoc:
4
+ class Sinatra::Request # @private
5
5
  attr_accessor :route_obj
6
6
 
7
7
  def controller
@@ -9,7 +9,7 @@ class Sinatra::Request #:nodoc:
9
9
  end
10
10
  end
11
11
 
12
- class HttpRouter #:nodoc:
12
+ class HttpRouter # @private
13
13
  def rewrite_partial_path_info(env, request); end
14
14
  def rewrite_path_info(env, request); end
15
15
 
@@ -53,7 +53,7 @@ class HttpRouter #:nodoc:
53
53
  end
54
54
  end
55
55
 
56
- class Route #:nodoc:
56
+ class Route # @private
57
57
  attr_reader :before_filters, :after_filters
58
58
  attr_accessor :custom_conditions, :use_layout, :controller, :cache
59
59
 
@@ -123,9 +123,9 @@ module Padrino
123
123
  #
124
124
  module Routing
125
125
  CONTENT_TYPE_ALIASES = { :htm => :html } unless defined?(CONTENT_TYPE_ALIASES)
126
- ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2}
126
+ ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
127
127
 
128
- class UnrecognizedException < RuntimeError #:nodoc:
128
+ class UnrecognizedException < RuntimeError # @private
129
129
  end
130
130
 
131
131
  ##
@@ -248,14 +248,14 @@ module Padrino
248
248
  options = args.extract_options!
249
249
 
250
250
  # Controller defaults
251
- @_controller, original_controller = args, @_controller
252
- @_parents, original_parent = options.delete(:parent), @_parents
253
- @_provides, original_provides = options.delete(:provides), @_provides
251
+ @_controller, original_controller = args, @_controller
252
+ @_parents, original_parent = options.delete(:parent), @_parents
253
+ @_provides, original_provides = options.delete(:provides), @_provides
254
254
  @_use_format, original_use_format = options.delete(:use_format), @_use_format
255
- @_cache, original_cache = options.delete(:cache), @_cache
256
- @_map, original_map = options.delete(:map), @_map
255
+ @_cache, original_cache = options.delete(:cache), @_cache
256
+ @_map, original_map = options.delete(:map), @_map
257
257
  @_conditions, original_conditions = options.delete(:conditions), @_conditions
258
- @_defaults, original_defaults = options, @_defaults
258
+ @_defaults, original_defaults = options, @_defaults
259
259
 
260
260
  # Application defaults
261
261
  @filters, original_filters = { :before => @filters[:before].dup, :after => @filters[:after].dup }, @filters
@@ -268,9 +268,9 @@ module Padrino
268
268
  @layout = original_layout
269
269
 
270
270
  # Controller defaults
271
- @_controller, @_parents, @_cache = original_controller, original_parent, original_cache
272
- @_defaults, @_provides, @_map = original_defaults, original_provides, original_map
273
- @_conditions, @_use_format = original_conditions, original_use_format
271
+ @_controller, @_parents, @_cache = original_controller, original_parent, original_cache
272
+ @_defaults, @_provides, @_map = original_defaults, original_provides, original_map
273
+ @_conditions, @_use_format = original_conditions, original_use_format
274
274
  else
275
275
  include(*args) if extensions.any?
276
276
  end
@@ -353,9 +353,8 @@ module Padrino
353
353
  end
354
354
 
355
355
  def recognize_path(path)
356
- if response = @router.recognize(Rack::MockRequest.env_for(path))
357
- [response.path.route.named, response.params]
358
- end
356
+ responses = @router.recognize(Rack::MockRequest.env_for(path))
357
+ [responses[0].path.route.named, responses[0].params]
359
358
  end
360
359
 
361
360
  ##
@@ -537,8 +536,8 @@ module Padrino
537
536
  map = options.delete(:map)
538
537
 
539
538
  if path.kind_of?(Symbol) # path i.e :index or :show
540
- name = path # The route name
541
- path = map ? map.dup : path.to_s # The route path
539
+ name = path # The route name
540
+ path = map ? map.dup : (path == :index ? '/' : path.to_s) # The route path
542
541
  end
543
542
 
544
543
  if path.kind_of?(String) # path i.e "/index" or "/show"
@@ -586,11 +585,11 @@ module Padrino
586
585
 
587
586
  # Small reformats
588
587
  path.gsub!(%r{/\?$}, '(/)') # Remove index path
589
- path.gsub!(%r{/?index/?}, '/') # Remove index path
590
588
  path.gsub!(%r{//$}, '/') # Remove index path
591
589
  path[0,0] = "/" unless path =~ %r{^\(?/} # Paths must start with a /
592
590
  path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
593
591
  path.gsub!(/\/(\(\.|$)/, '\\1') # Remove trailing slashes
592
+ path.squeeze!('/')
594
593
  end
595
594
 
596
595
  # Merge in option defaults
@@ -660,7 +659,6 @@ module Padrino
660
659
  @_use_format = true
661
660
  condition do
662
661
  mime_types = types.map { |t| mime_type(t) }
663
- request.path_info =~ /\.([^\.\/]+)$/
664
662
  url_format = params[:format].to_sym if params[:format]
665
663
  accepts = request.accept.map { |a| a.split(";")[0].strip }
666
664
 
@@ -770,7 +768,11 @@ module Padrino
770
768
  # end
771
769
  #
772
770
  def content_type(type=nil, params={})
773
- type.nil? ? @_content_type : super(type, params)
771
+ unless type.nil?
772
+ super(type, params)
773
+ @_content_type = type
774
+ end
775
+ @_content_type
774
776
  end
775
777
 
776
778
  private
@@ -42,4 +42,4 @@ module Padrino
42
42
  reject { |file,line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }.
43
43
  map { |file,line| file }
44
44
  end
45
- end # Padrino
45
+ end # Padrino
@@ -21,4 +21,4 @@ module Padrino
21
21
  end # self
22
22
  end # Adapter
23
23
  end # Cli
24
- end # Padrino
24
+ end # Padrino
@@ -109,8 +109,7 @@ module Padrino
109
109
  help(task.to_s)
110
110
  raise SystemExit
111
111
  end
112
- ENV["PADRINO_ENV"] ||= options.environment.to_s
113
- ENV["RACK_ENV"] = ENV["PADRINO_ENV"] # Also set this for middleware
112
+ ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= options.environment.to_s
114
113
  chdir(options.chdir)
115
114
  unless File.exist?('config/boot.rb')
116
115
  puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
@@ -21,4 +21,4 @@ end
21
21
 
22
22
  def shell
23
23
  @_shell ||= Thor::Base.shell.new
24
- end
24
+ end
@@ -24,4 +24,4 @@ module Padrino
24
24
  ruby
25
25
  end
26
26
  end
27
- end # Padrino
27
+ end # Padrino
@@ -179,4 +179,4 @@ module Padrino
179
179
  $:.uniq!; load_paths.uniq!
180
180
  end
181
181
  end # self
182
- end # Padrino
182
+ end # Padrino
File without changes
@@ -104,23 +104,14 @@ module Padrino
104
104
 
105
105
  # Embed in a String to clear all previous ANSI sequences.
106
106
  CLEAR = "\e[0m"
107
- # The start of an ANSI bold sequence.
108
107
  BOLD = "\e[1m"
109
- # Set the terminal's foreground ANSI color to black.
110
108
  BLACK = "\e[30m"
111
- # Set the terminal's foreground ANSI color to red.
112
109
  RED = "\e[31m"
113
- # Set the terminal's foreground ANSI color to green.
114
110
  GREEN = "\e[32m"
115
- # Set the terminal's foreground ANSI color to yellow.
116
111
  YELLOW = "\e[33m"
117
- # Set the terminal's foreground ANSI color to blue.
118
112
  BLUE = "\e[34m"
119
- # Set the terminal's foreground ANSI color to magenta.
120
113
  MAGENTA = "\e[35m"
121
- # Set the terminal's foreground ANSI color to cyan.
122
114
  CYAN = "\e[36m"
123
- # Set the terminal's foreground ANSI color to white.
124
115
  WHITE = "\e[37m"
125
116
 
126
117
  # Colors for levels
@@ -245,7 +236,6 @@ module Padrino
245
236
  #
246
237
  Levels.each_pair do |name, number|
247
238
  class_eval <<-LEVELMETHODS, __FILE__, __LINE__
248
-
249
239
  # Appends a message to the log if the log level is at least as high as
250
240
  # the log level of the logger.
251
241
  #
@@ -347,7 +337,7 @@ module Padrino
347
337
  end # Logger
348
338
  end # Padrino
349
339
 
350
- module Kernel #:nodoc:
340
+ module Kernel # @private
351
341
  ##
352
342
  # Define a logger available every where in our app
353
343
  #
@@ -9,7 +9,7 @@ module Padrino
9
9
  # Mounter.new("blog_app", :app_file => "/path/to/blog/app.rb").to("/blog")
10
10
  #
11
11
  class Mounter
12
- class MounterException < RuntimeError #:nodoc:
12
+ class MounterException < RuntimeError # @private
13
13
  end
14
14
 
15
15
  attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host
@@ -189,4 +189,4 @@ module Padrino
189
189
  Mounter.new(name, options)
190
190
  end
191
191
  end # Mounter
192
- end # Padrino
192
+ end # Padrino
@@ -98,7 +98,7 @@ module Padrino
98
98
  # We lock dependencies sets to prevent reloading of protected constants
99
99
  #
100
100
  def lock!
101
- klasses = ObjectSpace.classes.map { |klass| klass.to_s.split("::")[0] }.uniq
101
+ klasses = ObjectSpace.classes.map { |klass| klass.name.to_s.split("::")[0] }.uniq
102
102
  klasses = klasses | Padrino.mounted_apps.map { |app| app.app_class }
103
103
  Padrino::Reloader.exclude_constants.concat(klasses)
104
104
  end
@@ -244,4 +244,4 @@ module Padrino
244
244
  end
245
245
  end
246
246
  end # Reloader
247
- end # Padrino
247
+ end # Padrino
@@ -76,4 +76,4 @@ module Padrino
76
76
  [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{rPath}"]]
77
77
  end
78
78
  end # Router
79
- end # Padrino
79
+ end # Padrino
@@ -67,4 +67,4 @@ module Padrino
67
67
  fail "Server handler (#{Handlers.join(', ')}) not found."
68
68
  end
69
69
  end # Server
70
- end # Padrino
70
+ end # Padrino
@@ -1,9 +1,7 @@
1
1
  ##
2
2
  # This file loads certain extensions required by Padrino from ActiveSupport.
3
3
  #
4
- require 'active_support/core_ext/kernel' # silence_warnings
5
4
  require 'active_support/core_ext/module/aliasing' # alias_method_chain
6
- require 'active_support/core_ext/class/attribute_accessors' # cattr_reader
7
5
  require 'active_support/core_ext/hash/keys' # symbolize_keys
8
6
  require 'active_support/core_ext/hash/reverse_merge' # reverse_merge
9
7
  require 'active_support/core_ext/hash/slice' # slice
@@ -20,6 +18,7 @@ require 'active_support/inflections' # load default infle
20
18
  # Issue: https://github.com/rails/rails/issues/1526
21
19
  #
22
20
  class String
21
+ ##
23
22
  # Returns the plural form of the word in the string.
24
23
  #
25
24
  # "post".pluralize # => "posts"
@@ -28,10 +27,12 @@ class String
28
27
  # "words".pluralize # => "words"
29
28
  # "the blue mailman".pluralize # => "the blue mailmen"
30
29
  # "CamelOctopus".pluralize # => "CamelOctopi"
30
+ #
31
31
  def pluralize
32
32
  ActiveSupport::Inflector.pluralize(self)
33
33
  end
34
34
 
35
+ ##
35
36
  # Returns the singular form of the word in the string.
36
37
  #
37
38
  # "posts".singularize # => "post"
@@ -40,10 +41,12 @@ class String
40
41
  # "words".singularize # => "word"
41
42
  # "the blue mailmen".singularize # => "the blue mailman"
42
43
  # "CamelOctopi".singularize # => "CamelOctopus"
44
+ #
43
45
  def singularize
44
46
  ActiveSupport::Inflector.singularize(self)
45
47
  end
46
48
 
49
+ ##
47
50
  # +constantize+ tries to find a declared constant with the name specified
48
51
  # in the string. It raises a NameError when the name is not in CamelCase
49
52
  # or is not initialized.
@@ -51,10 +54,12 @@ class String
51
54
  # Examples
52
55
  # "Module".constantize # => Module
53
56
  # "Class".constantize # => Class
57
+ #
54
58
  def constantize
55
59
  ActiveSupport::Inflector.constantize(self)
56
60
  end
57
61
 
62
+ ##
58
63
  # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize
59
64
  # is set to <tt>:lower</tt> then camelize produces lowerCamelCase.
60
65
  #
@@ -64,6 +69,7 @@ class String
64
69
  # "active_record".camelize(:lower) # => "activeRecord"
65
70
  # "active_record/errors".camelize # => "ActiveRecord::Errors"
66
71
  # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
72
+ #
67
73
  def camelize(first_letter = :upper)
68
74
  case first_letter
69
75
  when :upper then ActiveSupport::Inflector.camelize(self, true)
@@ -72,16 +78,19 @@ class String
72
78
  end
73
79
  alias_method :camelcase, :camelize
74
80
 
81
+ ##
75
82
  # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
76
83
  #
77
84
  # +underscore+ will also change '::' to '/' to convert namespaces to paths.
78
85
  #
79
86
  # "ActiveRecord".underscore # => "active_record"
80
87
  # "ActiveRecord::Errors".underscore # => active_record/errors
88
+ #
81
89
  def underscore
82
90
  ActiveSupport::Inflector.underscore(self)
83
91
  end
84
92
 
93
+ ##
85
94
  # Create a class name from a plural table name like Rails does for table names to models.
86
95
  # Note that this returns a string and not a class. (To convert to an actual class
87
96
  # follow +classify+ with +constantize+.)
@@ -92,6 +101,7 @@ class String
92
101
  # Singular names are not handled correctly.
93
102
  #
94
103
  # "business".classify # => "Busines"
104
+ #
95
105
  def classify
96
106
  ActiveSupport::Inflector.classify(self)
97
107
  end
@@ -102,7 +112,10 @@ module ObjectSpace
102
112
  # Returns all the classes in the object space.
103
113
  def classes
104
114
  ObjectSpace.each_object(Module).select do |klass|
105
- Class.class_eval { klass } rescue false
115
+ # Why this? Ruby when you remove a constant don't clean it from
116
+ # rb_tables, this mean that here we can found classes that was
117
+ # removed.
118
+ klass.name rescue false
106
119
  end
107
120
  end
108
121
  end
@@ -111,21 +124,26 @@ end
111
124
  ##
112
125
  # FileSet helper method for iterating and interacting with files inside a directory
113
126
  #
114
- class FileSet
127
+ module FileSet
128
+ extend self
129
+ ##
115
130
  # Iterates over every file in the glob pattern and yields to a block
116
131
  # Returns the list of files matching the glob pattern
117
132
  # FileSet.glob('padrino-core/application/*.rb', __FILE__) { |file| load file }
118
- def self.glob(glob_pattern, file_path=nil, &block)
133
+ #
134
+ def glob(glob_pattern, file_path=nil, &block)
119
135
  glob_pattern = File.join(File.dirname(file_path), glob_pattern) if file_path
120
136
  file_list = Dir.glob(glob_pattern).sort
121
137
  file_list.each { |file| block.call(file) }
122
138
  file_list
123
139
  end
124
140
 
141
+ ##
125
142
  # Requires each file matched in the glob pattern into the application
126
143
  # FileSet.glob_require('padrino-core/application/*.rb', __FILE__)
127
- def self.glob_require(glob_pattern, file_path=nil)
128
- self.glob(glob_pattern, file_path) { |f| require f }
144
+ #
145
+ def glob_require(glob_pattern, file_path=nil)
146
+ glob(glob_pattern, file_path) { |f| require f }
129
147
  end
130
148
  end
131
149
 
@@ -144,4 +162,4 @@ I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n
144
162
  ##
145
163
  # Used to know if this file has already been required
146
164
  #
147
- module SupportLite; end
165
+ module SupportLite; end
@@ -20,4 +20,4 @@ module Padrino
20
20
  @files ||= []
21
21
  end
22
22
  end # Tasks
23
- end # Padrino
23
+ end # Padrino
@@ -5,7 +5,7 @@
5
5
  # without include full padrino core.
6
6
  #
7
7
  module Padrino
8
- VERSION = '0.10.1' unless defined?(Padrino::VERSION)
8
+ VERSION = '0.10.2' unless defined?(Padrino::VERSION)
9
9
  ##
10
10
  # Return the current Padrino version
11
11
  #
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
 
33
33
  s.add_dependency("tilt", "~> 1.3.0")
34
34
  s.add_dependency("sinatra", "~> 1.2.6")
35
- s.add_dependency("http_router", "~> 0.9.4")
35
+ s.add_dependency("http_router", "~> 0.10.2")
36
36
  s.add_dependency("thor", "~> 0.14.3")
37
- s.add_dependency("activesupport", "~> 3.0.0")
38
- end
37
+ s.add_dependency("activesupport", "~> 3.1.0")
38
+ end
@@ -14,6 +14,11 @@ end
14
14
  class Complex2Demo < Padrino::Application
15
15
  set :reload, true
16
16
  get("/old"){ "Old Sinatra Way" }
17
+
18
+ controllers :var do
19
+ get(:destroy){ params.inspect }
20
+ end
21
+
17
22
  get("/"){ "The magick number is: 12!" } # Change only the number!!!
18
23
  end
19
24
 
@@ -24,4 +29,4 @@ end
24
29
  Complex2Demo.controllers do
25
30
  end
26
31
 
27
- Padrino.load!
32
+ Padrino.load!
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  SimpleDemo.controllers do
16
16
  get "/" do
17
- 'The magick number is: 72!' # Change only the number!!!
17
+ 'The magick number is: 724274705032786548110472817755585178605481536388041566742570203174924198689!' # Change only the number!!!
18
18
  end
19
19
 
20
20
  get "/rand" do
@@ -30,4 +30,4 @@ end
30
30
  # Then run it from your console: ruby -I"lib" test/fixtures/apps/simple.rb
31
31
  #
32
32
 
33
- Padrino.load!
33
+ Padrino.load!
@@ -6,4 +6,4 @@
6
6
  # But here we need some of b.rb
7
7
  A_result = [B, C]
8
8
 
9
- A = "A"
9
+ A = "A"
@@ -1,4 +1,4 @@
1
1
  # But here we need some of c.rb and a.rb
2
2
  B_result = C
3
3
 
4
- B = "B"
4
+ B = "B"
@@ -1 +1 @@
1
- C = "C"
1
+ C = "C"
@@ -1,4 +1,4 @@
1
1
  D = 0 unless defined?(D)
2
2
  D += 1
3
3
 
4
- raise "SomeThing"
4
+ raise "SomeThing"
@@ -1,13 +1,13 @@
1
1
  ENV['PADRINO_ENV'] = 'test'
2
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
+ PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
3
3
 
4
4
  require File.expand_path('../../../load_paths', __FILE__)
5
5
  require 'padrino-core'
6
+ require 'json'
6
7
  require 'test/unit'
7
8
  require 'rack/test'
8
9
  require 'rack'
9
10
  require 'shoulda'
10
- require 'phocus'
11
11
 
12
12
  # Rubies < 1.9 don't handle hashes in the properly order so to prevent
13
13
  # this issue for now we remove extra values from mimetypes.
@@ -98,4 +98,4 @@ class Test::Unit::TestCase
98
98
  end
99
99
  alias :with_view :with_template
100
100
  alias :with_layout :with_template
101
- end
101
+ end
@@ -78,6 +78,30 @@ class TestApplication < Test::Unit::TestCase
78
78
  get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
79
79
  assert_equal "Foo in html", body
80
80
  end # content_type to :html
81
- end # application functionality
82
81
 
83
- end
82
+ context "errors" do
83
+ should "haven't mapped errors on development" do
84
+ mock_app { get('/'){ 'HI' } }
85
+ get "/"
86
+ assert @app.errors.empty?
87
+ end
88
+
89
+ should "have mapped errors on production" do
90
+ mock_app { set :environment, :production; get('/'){ 'HI' } }
91
+ get "/"
92
+ assert_equal 1, @app.errors.size
93
+ end
94
+
95
+ should "overide errors" do
96
+ mock_app do
97
+ set :environment, :production
98
+ get('/'){ raise }
99
+ error(::Exception){ 'custom error' }
100
+ end
101
+ get "/"
102
+ assert_equal 1, @app.errors.size
103
+ assert_equal 'custom error', body
104
+ end
105
+ end
106
+ end # application functionality
107
+ end
@@ -33,7 +33,7 @@ class TestCore < Test::Unit::TestCase
33
33
  assert_equal 'UTF8', $KCODE
34
34
  else
35
35
  assert_equal Encoding.default_external, Encoding::UTF_8
36
- assert_equal Encoding.default_internal, nil # Encoding::UTF_8
36
+ assert_equal Encoding.default_internal, Encoding::UTF_8
37
37
  end
38
38
  end
39
39
 
@@ -76,4 +76,4 @@ class TestCore < Test::Unit::TestCase
76
76
  assert_equal "yes", res["Middleware-Called"]
77
77
  end
78
78
  end
79
- end
79
+ end
@@ -88,4 +88,4 @@ class TestPadrinoLogger < Test::Unit::TestCase
88
88
  end
89
89
  end
90
90
  end
91
- end
91
+ end
@@ -173,4 +173,4 @@ class TestMounter < Test::Unit::TestCase
173
173
  assert_equal File.read(__FILE__), res.body
174
174
  end
175
175
  end
176
- end
176
+ end
@@ -36,9 +36,13 @@ class TestComplexReloader < Test::Unit::TestCase
36
36
  get "/complex_2_demo/old"
37
37
  assert_equal 200, status
38
38
 
39
+ get "/complex_2_demo/var/destroy"
40
+ assert_equal '{}', body
41
+
39
42
  new_phrase = "The magick number is: #{rand(2**255)}!"
40
43
  buffer = File.read(Complex1Demo.app_file)
41
44
  new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
45
+ new_buffer.gsub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)')
42
46
  begin
43
47
  File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) }
44
48
  sleep 1.2 # We need at least a cooldown of 1 sec.
@@ -57,10 +61,13 @@ class TestComplexReloader < Test::Unit::TestCase
57
61
 
58
62
  get "/complex_2_demo/old"
59
63
  assert_equal 200, status
64
+
65
+ get "/complex_2_demo/var/destroy/variable"
66
+ assert_equal '{:id=>"variable"}', body
60
67
  ensure
61
68
  # Now we need to prevent to commit a new changed file so we revert it
62
69
  File.open(Complex1Demo.app_file, "w") { |f| f.write(buffer) }
63
70
  end
64
71
  end
65
72
  end
66
- end
73
+ end
@@ -94,4 +94,4 @@ class TestSimpleReloader < Test::Unit::TestCase
94
94
  assert_equal 0, @app.templates.size
95
95
  end
96
96
  end
97
- end
97
+ end
@@ -434,4 +434,4 @@ class TestRendering < Test::Unit::TestCase
434
434
  assert_equal 'THIS. IS. SPARTA!', body
435
435
  end
436
436
  end
437
- end
437
+ end
@@ -30,4 +30,4 @@ class TestRouting < Test::Unit::TestCase
30
30
  delete "/parents/1/hi"
31
31
  assert_equal "/parents/1/hi delete", body
32
32
  end
33
- end
33
+ end
@@ -143,4 +143,4 @@ class TestRouter < Test::Unit::TestCase
143
143
  res = Rack::MockRequest.new(Padrino.application).get("/foo/", "HTTP_HOST" => "bar.padrino.org")
144
144
  assert res.ok?
145
145
  end
146
- end
146
+ end
@@ -37,6 +37,9 @@ class TestRouting < Test::Unit::TestCase
37
37
  get %r{/([0-9]+)/} do |num|
38
38
  "Your lucky number: #{num} #{params[:captures].first}"
39
39
  end
40
+ get /\/page\/([0-9]+)|\// do |num|
41
+ "My lucky number: #{num} #{params[:captures].first}"
42
+ end
40
43
  end
41
44
  get "/foo"
42
45
  assert_equal "str", body
@@ -46,6 +49,8 @@ class TestRouting < Test::Unit::TestCase
46
49
  assert_equal "regexp", body
47
50
  get "/1234/"
48
51
  assert_equal "Your lucky number: 1234 1234", body
52
+ get "/page/99"
53
+ assert_equal "My lucky number: 99 99", body
49
54
  end
50
55
 
51
56
  should "parse routes with question marks" do
@@ -239,6 +244,24 @@ class TestRouting < Test::Unit::TestCase
239
244
  assert_equal 'json', body
240
245
  end
241
246
 
247
+ should "set content_type to :json if render => :json" do
248
+ mock_app do
249
+ get("/foo"){ render :foo => :bar }
250
+ end
251
+
252
+ get '/foo'
253
+ assert_equal 'application/json;charset=utf-8', content_type
254
+ end
255
+
256
+ should 'set and get content_type' do
257
+ mock_app do
258
+ get("/foo"){ content_type(:json); content_type.to_s }
259
+ end
260
+ get "/foo"
261
+ assert_equal 'application/json', content_type
262
+ assert_equal 'json', body
263
+ end
264
+
242
265
  should "send the appropriate number of params" do
243
266
  mock_app do
244
267
  get('/id/:user_id', :provides => [:json]) { |user_id| user_id}
@@ -432,7 +455,7 @@ class TestRouting < Test::Unit::TestCase
432
455
  get "/"
433
456
  assert_equal "index", body
434
457
  assert_equal "/", @app.url(:index)
435
- get "/accounts"
458
+ get "/accounts/index"
436
459
  assert_equal "accounts", body
437
460
  end
438
461
 
@@ -626,6 +649,20 @@ class TestRouting < Test::Unit::TestCase
626
649
  assert_equal "foo_bar_index", body
627
650
  end
628
651
 
652
+ should "support a reindex action and remove index inside controller" do
653
+ mock_app do
654
+ controller :posts do
655
+ get(:index){ "index" }
656
+ get(:reindex){ "reindex" }
657
+ end
658
+ end
659
+ get "/posts"
660
+ assert_equal "index", body
661
+ get "/posts/reindex"
662
+ assert_equal "/posts/reindex", @app.url(:posts, :reindex)
663
+ assert_equal "reindex", body
664
+ end
665
+
629
666
  should 'use uri_root' do
630
667
  mock_app do
631
668
  get(:foo){ "foo" }
@@ -888,7 +925,7 @@ class TestRouting < Test::Unit::TestCase
888
925
  assert_equal 406, status
889
926
  end
890
927
 
891
- should "works allow global provides" do
928
+ should "does not allow global provides" do
892
929
  mock_app do
893
930
  provides :xml
894
931
 
@@ -905,6 +942,39 @@ class TestRouting < Test::Unit::TestCase
905
942
  assert_equal 'Bar in html', body
906
943
  end
907
944
 
945
+ should "does not allow global provides in controller" do
946
+ mock_app do
947
+ controller :base do
948
+ provides :xml
949
+
950
+ get(:foo, "/foo"){ "Foo in #{content_type}" }
951
+ get(:bar, "/bar"){ "Bar in #{content_type}" }
952
+ end
953
+ end
954
+
955
+ get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
956
+ assert_equal 'Foo in xml', body
957
+ get '/foo'
958
+ assert_equal 'Foo in xml', body
959
+
960
+ get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
961
+ assert_equal 'Bar in html', body
962
+ end
963
+
964
+ should "map non named routes in controllers" do
965
+ mock_app do
966
+ controller :base do
967
+ get("/foo") { "ok" }
968
+ get("/bar") { "ok" }
969
+ end
970
+ end
971
+
972
+ get "/base/foo"
973
+ assert ok?
974
+ get "/base/bar"
975
+ assert ok?
976
+ end
977
+
908
978
  should "set content_type to :html for both empty Accept as well as Accept text/html" do
909
979
  mock_app do
910
980
  provides :html
@@ -1445,6 +1515,29 @@ class TestRouting < Test::Unit::TestCase
1445
1515
  assert_equal 'okay', body
1446
1516
  end
1447
1517
 
1518
+ should 'return value from params' do
1519
+ mock_app do
1520
+ get("/foo/:bar"){ raise "'bar' should be a string" unless params[:bar].kind_of? String}
1521
+ end
1522
+ assert_nothing_raised do
1523
+ get "/foo/50"
1524
+ end
1525
+ end
1526
+
1527
+ should 'have MethodOverride middleware with more options' do
1528
+ mock_app do
1529
+ put('/', :with => :id, :provides => [:json]) { params[:id] }
1530
+ end
1531
+ post '/hi', {'_method'=>'PUT'}
1532
+ assert_equal 200, status
1533
+ assert_equal 'hi', body
1534
+ post '/hi.json', {'_method'=>'PUT'}
1535
+ assert_equal 200, status
1536
+ assert_equal 'hi', body
1537
+ post '/hi.json'
1538
+ assert_equal 405, status
1539
+ end
1540
+
1448
1541
  should 'parse nested params' do
1449
1542
  mock_app do
1450
1543
  get(:index) { "%s %s" % [params[:account][:name], params[:account][:surname]] }
@@ -1459,7 +1552,7 @@ class TestRouting < Test::Unit::TestCase
1459
1552
  mock_app { set :environment, :development }
1460
1553
  get "/"
1461
1554
  assert_equal 404, status
1462
- assert_match /Sinatra doesn&rsquo;t know this ditty./, body
1555
+ assert_match %r{(Sinatra doesn&rsquo;t know this ditty.|<h1>Not Found</h1>)}, body
1463
1556
  end
1464
1557
 
1465
1558
  should 'render a custom NotFound page' do
@@ -1510,6 +1603,18 @@ class TestRouting < Test::Unit::TestCase
1510
1603
  assert_equal "/paginate/10", body
1511
1604
  end
1512
1605
 
1606
+ should 'accept :map and :parent' do
1607
+ mock_app do
1608
+ controller :posts do
1609
+ get :show, :parent => :users, :map => "posts/:id" do
1610
+ "#{params[:user_id]}-#{params[:id]}"
1611
+ end
1612
+ end
1613
+ end
1614
+ get '/users/123/posts/321'
1615
+ assert_equal "123-321", body
1616
+ end
1617
+
1513
1618
  should 'change params in current_path' do
1514
1619
  mock_app do
1515
1620
  get :index, :map => "/paginate/:page" do
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 51
4
5
  prerelease:
5
- version: 0.10.1
6
+ segments:
7
+ - 0
8
+ - 10
9
+ - 2
10
+ version: 0.10.2
6
11
  platform: ruby
7
12
  authors:
8
13
  - Padrino Team
@@ -13,7 +18,7 @@ autorequire:
13
18
  bindir: bin
14
19
  cert_chain: []
15
20
 
16
- date: 2011-08-01 00:00:00 -07:00
21
+ date: 2011-08-31 00:00:00 -07:00
17
22
  default_executable:
18
23
  dependencies:
19
24
  - !ruby/object:Gem::Dependency
@@ -24,6 +29,11 @@ dependencies:
24
29
  requirements:
25
30
  - - ~>
26
31
  - !ruby/object:Gem::Version
32
+ hash: 27
33
+ segments:
34
+ - 1
35
+ - 3
36
+ - 0
27
37
  version: 1.3.0
28
38
  type: :runtime
29
39
  version_requirements: *id001
@@ -35,6 +45,11 @@ dependencies:
35
45
  requirements:
36
46
  - - ~>
37
47
  - !ruby/object:Gem::Version
48
+ hash: 19
49
+ segments:
50
+ - 1
51
+ - 2
52
+ - 6
38
53
  version: 1.2.6
39
54
  type: :runtime
40
55
  version_requirements: *id002
@@ -46,7 +61,12 @@ dependencies:
46
61
  requirements:
47
62
  - - ~>
48
63
  - !ruby/object:Gem::Version
49
- version: 0.9.4
64
+ hash: 51
65
+ segments:
66
+ - 0
67
+ - 10
68
+ - 2
69
+ version: 0.10.2
50
70
  type: :runtime
51
71
  version_requirements: *id003
52
72
  - !ruby/object:Gem::Dependency
@@ -57,6 +77,11 @@ dependencies:
57
77
  requirements:
58
78
  - - ~>
59
79
  - !ruby/object:Gem::Version
80
+ hash: 33
81
+ segments:
82
+ - 0
83
+ - 14
84
+ - 3
60
85
  version: 0.14.3
61
86
  type: :runtime
62
87
  version_requirements: *id004
@@ -68,7 +93,12 @@ dependencies:
68
93
  requirements:
69
94
  - - ~>
70
95
  - !ruby/object:Gem::Version
71
- version: 3.0.0
96
+ hash: 3
97
+ segments:
98
+ - 3
99
+ - 1
100
+ - 0
101
+ version: 3.1.0
72
102
  type: :runtime
73
103
  version_requirements: *id005
74
104
  description: The Padrino core gem required for use of this framework
@@ -171,12 +201,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
201
  requirements:
172
202
  - - ">="
173
203
  - !ruby/object:Gem::Version
204
+ hash: 3
205
+ segments:
206
+ - 0
174
207
  version: "0"
175
208
  required_rubygems_version: !ruby/object:Gem::Requirement
176
209
  none: false
177
210
  requirements:
178
211
  - - ">="
179
212
  - !ruby/object:Gem::Version
213
+ hash: 23
214
+ segments:
215
+ - 1
216
+ - 3
217
+ - 6
180
218
  version: 1.3.6
181
219
  requirements: []
182
220