padrino-core 0.9.14 → 0.9.15

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/padrino CHANGED
@@ -1,25 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rubygems' unless defined?(Gem)
2
+ require 'rubygems' unless defined?(Gem) # Useful only on --dev mode
3
3
 
4
- # We load Padrino libs
5
4
  padrino_core_path = File.expand_path('../../lib', __FILE__)
6
5
  $:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)
7
6
 
8
- # Build Padrino g as an alias of padrino-gen
9
- if %w(g gen).include?(ARGV[0])
10
- ARGV.shift
11
- begin
12
- # We try to load the vendored padrino-gen if exist
13
- padrino_gen_path = File.expand_path('../../../padrino-gen/lib', __FILE__)
14
- $:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include?(padrino_gen_path)
15
- require 'padrino-core/command'
16
- require 'padrino-gen/command'
17
- Padrino.bin_gen(ARGV)
18
- rescue
19
- puts "<= You need padrino-gen! Run: gem install padrino-gen"
20
- end
21
- else
22
- # We load our cli
23
- require 'padrino-core/cli/base'
24
- Padrino::Cli::Base.start(ARGV)
25
- end
7
+ require 'padrino-core/cli/base'
8
+ Padrino::Cli::Base.start(ARGV)
data/lib/padrino-core.rb CHANGED
@@ -44,11 +44,14 @@ module Padrino
44
44
  end
45
45
 
46
46
  ##
47
- # Default encoding to UTF8 if it has not already been set to something else.
47
+ # Default encoding to UTF8.
48
48
  #
49
49
  def set_encoding
50
- unless RUBY_VERSION >= '1.9'
51
- $KCODE = 'U' if $KCODE == 'NONE' || $KCODE.blank?
50
+ if RUBY_VERSION < '1.9'
51
+ $KCODE='u'
52
+ else
53
+ Encoding.default_external = Encoding::UTF_8
54
+ Encoding.default_internal = Encoding::UTF_8
52
55
  end
53
56
  nil
54
57
  end
@@ -12,19 +12,38 @@ module Padrino
12
12
  module Routing
13
13
  CONTENT_TYPE_ALIASES = { :htm => :html }
14
14
 
15
- class ::HttpRouter::Route
16
- attr_accessor :custom_conditions, :before_filters, :after_filters, :use_layout, :controller
17
- end
15
+ class ::HttpRouter #:nodoc:
16
+ attr_accessor :runner
17
+ class Route #:nodoc:
18
+ attr_accessor :custom_conditions, :before_filters, :after_filters, :use_layout, :controller
19
+
20
+ def process_arbitrary_blocks(blocks)
21
+ blocks.each { |blk| arbitrary { |env| router.runner.instance_eval(&blk) != false } } if blocks
22
+ end
18
23
 
19
- class ::Sinatra::Request
20
- attr_accessor :match
24
+ def before_filters=(before_filters)
25
+ process_arbitrary_blocks(before_filters)
26
+ @before_filters = before_filters
27
+ end
21
28
 
22
- def controller
23
- route && route.controller
29
+ def custom_conditions=(custom_conditions)
30
+ process_arbitrary_blocks(custom_conditions)
31
+ @custom_conditions = custom_conditions
32
+ end
24
33
  end
34
+ end
35
+
36
+ module ::Sinatra #:nodoc:
37
+ class Request #:nodoc:
38
+ attr_accessor :match
25
39
 
26
- def route
27
- match.matched? ? match.path.route : nil
40
+ def controller
41
+ route && route.controller
42
+ end
43
+
44
+ def route
45
+ match.matched? ? match.path.route : nil
46
+ end
28
47
  end
29
48
  end
30
49
 
@@ -140,13 +159,11 @@ module Padrino
140
159
  #
141
160
  # ==== Examples
142
161
  #
143
- # router.add('/greedy/{!:greed,.*}')
162
+ # router.add('/greedy/:greed')
144
163
  # router.recognize('/simple')
145
164
  #
146
165
  def router
147
- unless @router
148
- @router = HttpRouter.new
149
- end
166
+ @router ||= HttpRouter.new
150
167
  block_given? ? yield(@router) : @router
151
168
  end
152
169
  alias :urls :router
@@ -227,14 +244,19 @@ module Padrino
227
244
  invoke_hook(:route_added, verb, path, block)
228
245
 
229
246
  # HTTPRouter route construction
230
- route = router.add(path)
247
+ route = case path
248
+ when Regexp
249
+ router.add('/?*').match_path(path)
250
+ else
251
+ router.add(path)
252
+ end
253
+
231
254
  route.name(name) if name
232
255
  route.send(verb.downcase.to_sym)
233
256
  route.host(options.delete(:host)) if options.key?(:host)
257
+ route.condition(:user_agent => options.delete(:agent)) if options.key?(:agent)
234
258
  route.default_values = options.delete(:default_values)
235
259
 
236
- route.to(block)
237
-
238
260
  # Add Sinatra conditions
239
261
  options.each { |option, args| send(option, *args) }
240
262
  conditions, @conditions = @conditions, []
@@ -251,9 +273,15 @@ module Padrino
251
273
  route.after_filters = []
252
274
  end
253
275
 
276
+ route.to(block)
277
+
254
278
  route
255
279
  end
256
280
 
281
+ def current_controller
282
+ @_controller && @_controller.last
283
+ end
284
+
257
285
  ##
258
286
  # Returns the final parsed route details (modified to reflect all Padrino options)
259
287
  # given the raw route. Raw route passed in could be a named alias or a string and
@@ -273,18 +301,6 @@ module Padrino
273
301
  end
274
302
 
275
303
  if path.kind_of?(String) # path i.e "/index" or "/show"
276
- # Backwards compatability
277
-
278
- if path == '(/)'
279
- path = '/'
280
- warn "WARNING! #{Padrino.first_caller}: #{verb} (/) is deprecated, simply use / instead" if verb != "HEAD"
281
- end
282
-
283
- if path =~ /\(\/\)$/
284
- path.gsub(/\(\/\)$/, '/?')
285
- warn "WARNING! #{Padrino.first_caller}: #{verb} (/) is deprecated, simply use /? instead" if verb != "HEAD"
286
- end
287
-
288
304
  # Now we need to parse our 'with' params
289
305
  if with_params = options.delete(:with)
290
306
  path = process_path_for_with_params(path, with_params)
@@ -345,7 +361,7 @@ module Padrino
345
361
  # Used for calculating path in route method
346
362
  #
347
363
  def process_path_for_parent_params(path, parent_params)
348
- parent_prefix = parent_params.uniq.collect { |param| "#{param}/:#{param}_id" }.join("/")
364
+ parent_prefix = parent_params.flatten.uniq.collect { |param| "#{param}/:#{param}_id" }.join("/")
349
365
  File.join(parent_prefix, path)
350
366
  end
351
367
 
@@ -450,20 +466,17 @@ module Padrino
450
466
  # Compatibility with http_router
451
467
  #
452
468
  def route!(base=self.class, pass_block=nil)
469
+ base.router.runner = self
453
470
  if base.router and match = base.router.recognize(@request)
454
471
  if !match.matched?
455
- route_eval {
456
- match.headers.each{|k,v| response[k] = v}
472
+ route_eval do
473
+ match.headers.each {|k,v| response[k] = v}
457
474
  status match.status
458
- }
475
+ end
459
476
  elsif match
460
477
  @block_params = match.params
461
478
  (@params ||= {}).merge!(match.params_as_hash)
462
479
  pass_block = catch(:pass) do
463
- # Run Sinatra Conditions
464
- match.path.route.custom_conditions.each { |cond| throw :pass if instance_eval(&cond) == false }
465
- # Run scoped before filters
466
- match.path.route.before_filters.each { |bef| throw :pass if instance_eval(&bef) == false }
467
480
  # If present set current controller layout
468
481
  parent_layout = base.instance_variable_get(:@layout)
469
482
  base.instance_variable_set(:@layout, match.path.route.use_layout) if match.path.route.use_layout
@@ -483,7 +496,7 @@ module Padrino
483
496
 
484
497
  # Run routes defined in superclass.
485
498
  if base.superclass.respond_to?(:router)
486
- route! base.superclass, pass_block
499
+ route!(base.superclass, pass_block)
487
500
  return
488
501
  end
489
502
 
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'thor'
3
2
 
4
3
  module Padrino
@@ -63,6 +62,26 @@ module Padrino
63
62
  IRB.start
64
63
  end
65
64
 
65
+ desc "generate", "Executes the Padrino generator with given options."
66
+ def generate(*args)
67
+ # Build Padrino g as an alias of padrino-gen
68
+ begin
69
+ # We try to load the vendored padrino-gen if exist
70
+ padrino_gen_path = File.expand_path('../../../../../padrino-gen/lib', __FILE__)
71
+ $:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include?(padrino_gen_path)
72
+ require 'padrino-core/command'
73
+ require 'padrino-gen/command'
74
+ ARGV.shift
75
+ Padrino.bin_gen(ARGV)
76
+ rescue
77
+ puts "<= You need padrino-gen! Run: gem install padrino-gen"
78
+ end
79
+ end
80
+ desc "g", "Executes the Padrino generator with given options."
81
+ alias :g :generate
82
+ desc "gen", "Executes the Padrino generator with given options."
83
+ alias :gen :generate
84
+
66
85
  desc "version", "Show current Padrino Version"
67
86
  map "-v" => :version, "--version" => :version
68
87
  def version
@@ -86,7 +105,7 @@ module Padrino
86
105
  end
87
106
 
88
107
  protected
89
- def self.banner(task)
108
+ def self.banner(task=nil, *args)
90
109
  "padrino #{task.name}"
91
110
  end
92
111
 
@@ -4,9 +4,10 @@ Rake.application.instance_variable_set(:@rakefile, __FILE__)
4
4
 
5
5
  module PadrinoTasks
6
6
  def self.init
7
- Padrino::Tasks.files.flatten.uniq.each { |ext| load(ext) }
7
+ Padrino::Tasks.files.flatten.uniq.each { |ext| load(ext) rescue puts "<= Failed load #{ext}" } unless @_init
8
8
  Rake.application.init
9
9
  Rake.application.top_level
10
+ @_init = true
10
11
  end
11
12
  end
12
13
 
@@ -1,5 +1,38 @@
1
1
  module Padrino
2
2
  class << self
3
+
4
+ ##
5
+ # Hooks to be called before a load/reload
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # before_load do
10
+ # pre_initialize_something
11
+ # end
12
+ #
13
+ #
14
+ def before_load(&block)
15
+ @_before_load ||= []
16
+ @_before_load << Proc.new(&block) if block_given?
17
+ @_before_load
18
+ end
19
+
20
+ ##
21
+ # Hooks to be called after a load/reload
22
+ #
23
+ # ==== Examples
24
+ #
25
+ # after_load do
26
+ # DataMapper.finalize
27
+ # end
28
+ #
29
+ #
30
+ def after_load(&block)
31
+ @_after_load ||= []
32
+ @_after_load << Proc.new(&block) if block_given?
33
+ @_after_load
34
+ end
35
+
3
36
  ##
4
37
  # Requires necessary dependencies as well as application files from root lib and models
5
38
  #
@@ -8,9 +41,11 @@ module Padrino
8
41
  @_called_from = first_caller
9
42
  set_encoding
10
43
  set_load_paths(*load_paths) # We set the padrino load paths
44
+ Padrino.logger # Initialize our logger
45
+ before_load.each { |bl| bl.call } # Run before hooks
11
46
  dependency_paths.each { |path| require_dependency(path) }
12
47
  Reloader::Stat.run! # We need to fill our Stat::CACHE
13
- Padrino.logger # Initialize our logger
48
+ after_load.each { |al| al.call } # Run after hooks
14
49
  Thread.current[:padrino_loaded] = true
15
50
  end
16
51
 
@@ -18,7 +53,9 @@ module Padrino
18
53
  # Method for reloading required applications and their files
19
54
  #
20
55
  def reload!
56
+ before_load.each { |bl| bl.call } # Run before hooks
21
57
  Reloader::Stat.reload! # detects the modified files
58
+ after_load.each { |al| al.call } # Run after hooks
22
59
  end
23
60
 
24
61
  ##
@@ -53,12 +90,13 @@ module Padrino
53
90
  # With +require_dependencies+ we don't have this problem.
54
91
  #
55
92
  # ==== Examples
93
+ #
56
94
  # # For require all our app libs we need to do:
57
95
  # require_dependencies("#{Padrino.root}/lib/**/*.rb")
58
96
  #
59
97
  def require_dependencies(*paths)
60
98
  # Extract all files to load
61
- files = paths.map { |path| Dir[path] }.flatten
99
+ files = paths.map { |path| Dir[path] }.flatten.uniq.sort
62
100
 
63
101
  while files.present?
64
102
  # We need a size to make sure things are loading
@@ -72,9 +110,14 @@ module Padrino
72
110
  begin
73
111
  Reloader::Stat.safe_load(file)
74
112
  files.delete(file)
75
- rescue Exception => e
113
+ rescue LoadError => e
76
114
  errors << e
77
- failed << files
115
+ failed << file
116
+ rescue NameError => e
117
+ errors << e
118
+ failed << file
119
+ rescue Exception => e
120
+ raise e
78
121
  end
79
122
  end
80
123
 
@@ -99,6 +142,7 @@ module Padrino
99
142
 
100
143
  ##
101
144
  # Appends custom dependency patterns to the be loaded for Padrino
145
+ #
102
146
  # ==== Examples
103
147
  # Padrino.custom_dependencies("#{Padrino.root}/foo/bar/*.rb")
104
148
  #
@@ -126,4 +170,4 @@ module Padrino
126
170
  $:.uniq!
127
171
  end
128
172
  end # self
129
- end # Padrino
173
+ end # Padrino
@@ -0,0 +1,30 @@
1
+ nl:
2
+ date:
3
+ formats:
4
+ # Use the strftime parameters for formats.
5
+ # When no format has been given, it uses default.
6
+ # You can provide other formats here if you like!
7
+ default: "%d-%m-%Y"
8
+ short: "%d %b"
9
+ long: "%d %B %Y"
10
+
11
+ day_names: [zondag, maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag]
12
+ abbr_day_names: [zo, ma, di, wo, do, vr, za]
13
+ month_names: [~, januari, februari, maart, april, mei, juni, juli, augustus, september, oktober, november]
14
+ abbr_month_names: [~, jan, feb, maa, apr, mei, jun, jul, aug, sep, okt, nov, dec]
15
+ order: [ :day, :month, :year ]
16
+
17
+ time:
18
+ formats:
19
+ default: "%a %d %b %Y %H:%M:%S %z"
20
+ short: "%d %b %H:%M"
21
+ long: "%d %B %Y %H:%M"
22
+ am: "am"
23
+ pm: "pm"
24
+
25
+ # Used in array.to_sentence.
26
+ support:
27
+ array:
28
+ words_connector: ", "
29
+ two_words_connector: " en "
30
+ last_word_connector: " en "
@@ -0,0 +1,30 @@
1
+ pl:
2
+ date:
3
+ formats:
4
+ # Use the strftime parameters for formats.
5
+ # When no format has been given, it uses default.
6
+ # You can provide other formats here if you like!
7
+ default: "%Y-%m-%d"
8
+ short: "%d %b"
9
+ long: "%d %B %Y"
10
+
11
+ day_names: [Niedziela, Poniedziałek, Wtorek, Środa, Czwartek, Piątek, Sobota]
12
+ abbr_day_names: [nie, pon, wto, śro, czw, pia, sob]
13
+ month_names: [~, Styczeń, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Październik, Listopad, Grudzień]
14
+ abbr_month_names: [~, sty, lut, mar, kwi, maj, cze, lip, sie, wrz, paź, lis, gru]
15
+ order: [ :year, :month, :day ]
16
+
17
+ time:
18
+ formats:
19
+ default: "%a, %d %b %Y, %H:%M:%S %z"
20
+ short: "%d %b, %H:%M"
21
+ long: "%d %B %Y, %H:%M"
22
+ am: "przed południem"
23
+ pm: "po południu"
24
+
25
+ # Used in array.to_sentence.
26
+ support:
27
+ array:
28
+ words_connector: ", "
29
+ two_words_connector: " i "
30
+ last_word_connector: " i "
@@ -189,23 +189,10 @@ module Padrino
189
189
  ##
190
190
  # Removes the specified class and constant.
191
191
  #
192
- # Additionally this removes the specified class from the subclass list of every superclass that
193
- # tracks it's subclasses in an array returned by _subclasses_list. Classes that wish to use this
194
- # functionality are required to alias the reader for their list of subclasses
195
- # to _subclasses_list. Plugins for ORMs and other libraries should keep this in mind.
196
- #
197
192
  def remove_constant(const)
198
193
  return if Padrino::Reloader.exclude_constants.any? { |base| (const.to_s =~ /^#{base}/ || const.superclass.to_s =~ /^#{base}/) } &&
199
194
  !Padrino::Reloader.include_constants.any? { |base| (const.to_s =~ /^#{base}/ || const.superclass.to_s =~ /^#{base}/) }
200
195
 
201
- superklass = const
202
- until (superklass = superklass.superclass).nil?
203
- if superklass.respond_to?(:_subclasses_list)
204
- superklass.send(:_subclasses_list).delete(klass)
205
- superklass.send(:_subclasses_list).delete(klass.to_s)
206
- end
207
- end
208
-
209
196
  parts = const.to_s.split("::")
210
197
  base = parts.size == 1 ? Object : Object.full_const_get(parts[0..-2].join("::"))
211
198
  object = parts[-1].to_s
@@ -221,11 +208,11 @@ module Padrino
221
208
  # Searches Ruby files in your +Padrino.root+ and monitors them for any changes.
222
209
  #
223
210
  def rotation
224
- paths = Dir[Padrino.root("*")].unshift(Padrino.root).reject { |path| !File.directory?(path) }
225
-
226
- files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
211
+ paths = Dir[Padrino.root("*")].unshift(Padrino.root).
212
+ reject { |path| Padrino::Reloader.exclude.include?(path) || !File.directory?(path) }
213
+ files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten.uniq
227
214
 
228
- files.map{ |file|
215
+ files.map { |file|
229
216
  next if Padrino::Reloader.exclude.any? { |base| file =~ /^#{base}/ }
230
217
 
231
218
  found, stat = figure_path(file, paths)
@@ -38,7 +38,7 @@ module Padrino
38
38
  end
39
39
 
40
40
  def sort!
41
- @mapping = @mapping.sort_by { |h, p, m, a| [(-1.0 / 0.0), -p.size] }
41
+ @mapping = @mapping.sort_by { |h, p, m, a| -p.size }
42
42
  end
43
43
 
44
44
  def map(options={})
@@ -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
79
- end
79
+ end
@@ -49,6 +49,11 @@ if defined?(ActiveSupport::CoreExtensions::Hash) && !Hash.method_defined?(:slice
49
49
  include ActiveSupport::CoreExtensions::Hash::DeepMerge
50
50
  include ActiveSupport::CoreExtensions::Hash::ReverseMerge
51
51
  include ActiveSupport::CoreExtensions::Hash::Slice
52
+
53
+ def ordered_collect(&block)
54
+ keys = self.stringify_keys.keys.sort
55
+ keys.collect { |key| block.call(key, self[key.to_sym]) }
56
+ end
52
57
  end
53
58
  end
54
59
 
@@ -62,7 +67,7 @@ module ObjectSpace
62
67
  # Returns all the classes in the object space.
63
68
  def classes
64
69
  klasses = []
65
- ObjectSpace.each_object(Class) {|o| klasses << o}
70
+ ObjectSpace.each_object(Class) { |o| klasses << o }
66
71
  klasses
67
72
  end
68
73
  end
@@ -86,14 +91,14 @@ end unless Object.method_defined?(:full_const_get)
86
91
  class FileSet
87
92
  # Iterates over every file in the glob pattern and yields to a block
88
93
  # Returns the list of files matching the glob pattern
89
- # FileSet.glob_require('padrino-core/application/*.rb', __FILE__) { |file| load file }
94
+ # FileSet.glob('padrino-core/application/*.rb', __FILE__) { |file| load file }
90
95
  def self.glob(glob_pattern, file_path=nil, &block)
91
96
  glob_pattern = File.join(File.dirname(file_path), glob_pattern) if file_path
92
97
  file_list = Dir.glob(glob_pattern).sort
93
98
  file_list.each { |file| block.call(file) }
94
99
  file_list
95
100
  end
96
-
101
+
97
102
  # Requires each file matched in the glob pattern into the application
98
103
  # FileSet.glob_require('padrino-core/application/*.rb', __FILE__)
99
104
  def self.glob_require(glob_pattern, file_path=nil)
@@ -104,4 +109,4 @@ end unless defined?(FileSet)
104
109
  ##
105
110
  # Loads our locales configuration files
106
111
  #
107
- I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n)
112
+ I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n)
@@ -5,11 +5,11 @@
5
5
  # without include full padrino core.
6
6
  #
7
7
  module Padrino
8
- VERSION = '0.9.14' unless defined?(Padrino::VERSION)
8
+ VERSION = '0.9.15' unless defined?(Padrino::VERSION)
9
9
  ##
10
10
  # Return the current Padrino version
11
11
  #
12
12
  def self.version
13
13
  VERSION
14
14
  end
15
- end # Padrino
15
+ end # Padrino
data/padrino-core.gemspec CHANGED
@@ -1,16 +1,14 @@
1
1
  require File.expand_path("../lib/padrino-core/version.rb", __FILE__)
2
- require 'rubygems'
3
- require 'bundler'
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = "padrino-core"
7
5
  s.rubyforge_project = "padrino-core"
8
6
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
9
- s.email = %q{padrinorb@gmail.com}
10
- s.summary = %q{The required Padrino core gem}
11
- s.homepage = "http://github.com/padrino/padrino-framework/tree/master/padrino-core"
12
- s.description = %q{The Padrino core gem required for use of this framework}
13
- s.default_executable = %q{padrino}
7
+ s.email = "padrinorb@gmail.com"
8
+ s.summary = "The required Padrino core gem"
9
+ s.homepage = "http://www.padrinorb.com"
10
+ s.description = "The Padrino core gem required for use of this framework"
11
+ s.default_executable = "padrino"
14
12
  s.executables = ["padrino"]
15
13
  s.required_rubygems_version = ">= 1.3.6"
16
14
  s.version = Padrino.version
@@ -18,6 +16,16 @@ Gem::Specification.new do |s|
18
16
  s.extra_rdoc_files = Dir["*.rdoc"]
19
17
  s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile padrino-core.gemspec) + Dir.glob("{bin,lib,test}/**/*")
20
18
  s.rdoc_options = ["--charset=UTF-8"]
21
- s.require_path = 'lib'
22
- s.add_bundler_dependencies :core, :development
23
- end
19
+ s.require_path = "lib"
20
+ s.add_dependency("sinatra", ">= 1.0.0")
21
+ s.add_dependency("http_router", ">= 0.3.13")
22
+ s.add_dependency("thor", ">= 0.13.0")
23
+ # If you want try our test on AS edge.
24
+ # $ AS=edge rake test
25
+ if ENV['AS'] == "edge"
26
+ s.add_dependency("activesupport", ">= 3.0.0.beta4")
27
+ s.add_dependency("tzinfo")
28
+ else
29
+ s.add_dependency("activesupport", ">= 2.3.8")
30
+ end
31
+ end
@@ -1,4 +1,9 @@
1
- A = "A"
1
+ # This file will be safe loaded three times.
2
+ # The first one fail because B and C constant are not defined
3
+ # The second one file because B requires C constant so will not be loaded
4
+ # The third one B and C are defined
2
5
 
3
6
  # But here we need some of b.rb
4
- A_result = [B, A]
7
+ A_result = [B, C]
8
+
9
+ A = "A"
@@ -1,4 +1,4 @@
1
- B = "B"
1
+ # But here we need some of c.rb and a.rb
2
+ B_result = C
2
3
 
3
- # Here we need some of c.rb
4
- B_result = [C, B]
4
+ B = "B"
@@ -0,0 +1,4 @@
1
+ D = 0 unless defined?(D)
2
+ D += 1
3
+
4
+ raise "SomeThing"
@@ -51,4 +51,4 @@ class TestApplication < Test::Unit::TestCase
51
51
  assert_equal "Foo in html", body
52
52
  end
53
53
  end
54
- end
54
+ end
@@ -1,14 +1,20 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestDependencies < Test::Unit::TestCase
4
- context 'when we require a dependency that have another dependecy' do
4
+ context 'when we require a dependency that have another dependency' do
5
5
 
6
- should 'raise an error without padrino' do
7
- assert_raise NameError do
8
- require "fixtures/dependencies/a.rb"
9
- require "fixtures/dependencies/b.rb"
10
- require "fixtures/dependencies/c.rb"
6
+ should 'raise an error without reloading it twice' do
7
+ silence_warnings do
8
+ assert_raise(RuntimeError) do
9
+ Padrino.require_dependencies(
10
+ Padrino.root("fixtures/dependencies/a.rb"),
11
+ Padrino.root("fixtures/dependencies/b.rb"),
12
+ Padrino.root("fixtures/dependencies/c.rb"),
13
+ Padrino.root("fixtures/dependencies/d.rb")
14
+ )
15
+ end
11
16
  end
17
+ assert_equal 1, D
12
18
  end
13
19
 
14
20
  should 'resolve dependency problems' do
@@ -19,9 +25,8 @@ class TestDependencies < Test::Unit::TestCase
19
25
  Padrino.root("fixtures/dependencies/c.rb")
20
26
  )
21
27
  end
22
- assert_equal ["B", "A"], A_result
23
- assert_equal ["C", "B"], B_result
28
+ assert_equal ["B", "C"], A_result
29
+ assert_equal "C", B_result
24
30
  end
25
31
  end
26
-
27
32
  end
data/test/test_mounter.rb CHANGED
@@ -147,4 +147,4 @@ class TestMounter < Test::Unit::TestCase
147
147
  assert_equal "Im Demo 2", body
148
148
  end
149
149
  end
150
- end
150
+ end
@@ -365,5 +365,4 @@ class TestRendering < Test::Unit::TestCase
365
365
  assert_equal 'THIS. IS. SPARTA!', body
366
366
  end
367
367
  end
368
-
369
368
  end
data/test/test_routing.rb CHANGED
@@ -27,6 +27,19 @@ class TestRouting < Test::Unit::TestCase
27
27
  }
28
28
  end
29
29
 
30
+ should 'accept regexp routes' do
31
+ mock_app do
32
+ get(%r{/fob|/baz}) { "regexp" }
33
+ get("/foo") { "str" }
34
+ end
35
+ get "/foo"
36
+ assert_equal "str", body
37
+ get "/fob"
38
+ assert_equal "regexp", body
39
+ get "/baz"
40
+ assert_equal "regexp", body
41
+ end
42
+
30
43
  should "parse routes with question marks" do
31
44
  mock_app do
32
45
  get("/foo/?"){ "okey" }
@@ -53,6 +66,17 @@ class TestRouting < Test::Unit::TestCase
53
66
  assert_equal "2", body
54
67
  end
55
68
 
69
+ should "match user agents" do
70
+ app = mock_app do
71
+ get("/main", :agent => /IE/){ "hello IE" }
72
+ get("/main"){ "hello" }
73
+ end
74
+ get "/main"
75
+ assert_equal "hello", body
76
+ get "/main", {}, {'HTTP_USER_AGENT' => 'This is IE'}
77
+ assert_equal "hello IE", body
78
+ end
79
+
56
80
  should "not generate overlapping head urls" do
57
81
  app = mock_app do
58
82
  get("/main"){ "hello" }
@@ -471,17 +495,19 @@ class TestRouting < Test::Unit::TestCase
471
495
  mock_app do
472
496
  controllers :project do
473
497
  get(:index, :parent => :user) { "index #{params[:user_id]}" }
498
+ get(:index, :parent => [:user, :section]) { "index #{params[:user_id]} #{params[:section_id]}" }
474
499
  get(:edit, :with => :id, :parent => :user) { "edit #{params[:id]} #{params[:user_id]}"}
475
500
  get(:show, :with => :id, :parent => [:user, :product]) { "show #{params[:id]} #{params[:user_id]} #{params[:product_id]}"}
476
501
  end
477
502
  end
478
503
  get "/user/1/project"
479
504
  assert_equal "index 1", body
505
+ get "/user/1/section/3/project"
506
+ assert_equal "index 1 3", body
480
507
  get "/user/1/project/edit/2"
481
508
  assert_equal "edit 2 1", body
482
509
  get "/user/1/product/2/project/show/3"
483
510
  assert_equal "show 3 1 2", body
484
-
485
511
  end
486
512
 
487
513
  should "apply parent to controller" do
@@ -610,8 +636,8 @@ class TestRouting < Test::Unit::TestCase
610
636
  assert_equal 'html', body
611
637
  end
612
638
 
613
- should 'allows custom route-conditions to be set via route options' do
614
- protector = Module.new {
639
+ should 'allows custom route-conditions to be set via route options and halt' do
640
+ protector = Module.new do
615
641
  def protect(*args)
616
642
  condition {
617
643
  unless authorize(params["user"], params["password"])
@@ -619,7 +645,7 @@ class TestRouting < Test::Unit::TestCase
619
645
  end
620
646
  }
621
647
  end
622
- }
648
+ end
623
649
 
624
650
  mock_app do
625
651
  register protector
@@ -644,6 +670,39 @@ class TestRouting < Test::Unit::TestCase
644
670
  assert_equal "hey", body
645
671
  end
646
672
 
673
+ should 'allows custom route-conditions to be set via route options using two routes' do
674
+ protector = Module.new do
675
+ def protect(*args)
676
+ condition { authorize(params["user"], params["password"]) }
677
+ end
678
+ end
679
+
680
+ mock_app do
681
+ register protector
682
+
683
+ helpers do
684
+ def authorize(username, password)
685
+ username == "foo" && password == "bar"
686
+ end
687
+ end
688
+
689
+ get "/", :protect => true do
690
+ "hey"
691
+ end
692
+
693
+ get "/" do
694
+ "go away"
695
+ end
696
+ end
697
+
698
+ get "/"
699
+ assert_equal "go away", body
700
+
701
+ get "/", :user => "foo", :password => "bar"
702
+ assert ok?
703
+ assert_equal "hey", body
704
+ end
705
+
647
706
  should 'scope filters in the given controller' do
648
707
  mock_app do
649
708
  before { @global = 'global' }
@@ -759,7 +818,6 @@ class TestRouting < Test::Unit::TestCase
759
818
  post "/.json"
760
819
  assert_equal "This is the post index.json", body
761
820
  post "/.js"
762
- assert_match "Sinatra doesn't know this ditty", body
763
821
  assert_equal 404, status
764
822
  end
765
823
 
@@ -859,4 +917,4 @@ class TestRouting < Test::Unit::TestCase
859
917
  post @app.url(:posts, :create, :format => :js, :bar => 'bar', :baz => 'baz', :id => 5)
860
918
  assert_equal "POST CREATE bar - baz - 5", body, "should properly post to create action"
861
919
  end
862
- end
920
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
4
+ hash: 37
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 14
10
- version: 0.9.14
9
+ - 15
10
+ version: 0.9.15
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -18,10 +18,12 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-06-30 00:00:00 -07:00
21
+ date: 2010-08-28 00:00:00 +02:00
22
22
  default_executable: padrino
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
+ name: sinatra
26
+ prerelease: false
25
27
  requirement: &id001 !ruby/object:Gem::Requirement
26
28
  none: false
27
29
  requirements:
@@ -34,26 +36,26 @@ dependencies:
34
36
  - 0
35
37
  version: 1.0.0
36
38
  type: :runtime
37
- name: sinatra
38
- prerelease: false
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
41
+ name: http_router
42
+ prerelease: false
41
43
  requirement: &id002 !ruby/object:Gem::Requirement
42
44
  none: false
43
45
  requirements:
44
46
  - - ">="
45
47
  - !ruby/object:Gem::Version
46
- hash: 19
48
+ hash: 9
47
49
  segments:
48
50
  - 0
49
51
  - 3
50
- - 0
51
- version: 0.3.0
52
+ - 13
53
+ version: 0.3.13
52
54
  type: :runtime
53
- name: http_router
54
- prerelease: false
55
55
  version_requirements: *id002
56
56
  - !ruby/object:Gem::Dependency
57
+ name: thor
58
+ prerelease: false
57
59
  requirement: &id003 !ruby/object:Gem::Requirement
58
60
  none: false
59
61
  requirements:
@@ -66,10 +68,10 @@ dependencies:
66
68
  - 0
67
69
  version: 0.13.0
68
70
  type: :runtime
69
- name: thor
70
- prerelease: false
71
71
  version_requirements: *id003
72
72
  - !ruby/object:Gem::Dependency
73
+ name: activesupport
74
+ prerelease: false
73
75
  requirement: &id004 !ruby/object:Gem::Requirement
74
76
  none: false
75
77
  requirements:
@@ -82,105 +84,7 @@ dependencies:
82
84
  - 8
83
85
  version: 2.3.8
84
86
  type: :runtime
85
- name: activesupport
86
- prerelease: false
87
87
  version_requirements: *id004
88
- - !ruby/object:Gem::Dependency
89
- requirement: &id005 !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- hash: 49
95
- segments:
96
- - 0
97
- - 8
98
- - 7
99
- version: 0.8.7
100
- type: :development
101
- name: rake
102
- prerelease: false
103
- version_requirements: *id005
104
- - !ruby/object:Gem::Dependency
105
- requirement: &id006 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 43
111
- segments:
112
- - 0
113
- - 9
114
- - 8
115
- version: 0.9.8
116
- type: :development
117
- name: mocha
118
- prerelease: false
119
- version_requirements: *id006
120
- - !ruby/object:Gem::Dependency
121
- requirement: &id007 !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 11
127
- segments:
128
- - 0
129
- - 5
130
- - 0
131
- version: 0.5.0
132
- type: :development
133
- name: rack-test
134
- prerelease: false
135
- version_requirements: *id007
136
- - !ruby/object:Gem::Dependency
137
- requirement: &id008 !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- hash: 9
143
- segments:
144
- - 0
145
- - 5
146
- - 1
147
- version: 0.5.1
148
- type: :development
149
- name: webrat
150
- prerelease: false
151
- version_requirements: *id008
152
- - !ruby/object:Gem::Dependency
153
- requirement: &id009 !ruby/object:Gem::Requirement
154
- none: false
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- hash: 43
159
- segments:
160
- - 2
161
- - 2
162
- - 22
163
- version: 2.2.22
164
- type: :development
165
- name: haml
166
- prerelease: false
167
- version_requirements: *id009
168
- - !ruby/object:Gem::Dependency
169
- requirement: &id010 !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- hash: 33
175
- segments:
176
- - 2
177
- - 10
178
- - 3
179
- version: 2.10.3
180
- type: :development
181
- name: shoulda
182
- prerelease: false
183
- version_requirements: *id010
184
88
  description: The Padrino core gem required for use of this framework
185
89
  email: padrinorb@gmail.com
186
90
  executables:
@@ -218,6 +122,8 @@ files:
218
122
  - lib/padrino-core/locale/es.yml
219
123
  - lib/padrino-core/locale/fr.yml
220
124
  - lib/padrino-core/locale/it.yml
125
+ - lib/padrino-core/locale/nl.yml
126
+ - lib/padrino-core/locale/pl.yml
221
127
  - lib/padrino-core/locale/pt_br.yml
222
128
  - lib/padrino-core/locale/ru.yml
223
129
  - lib/padrino-core/locale/tr.yml
@@ -235,6 +141,7 @@ files:
235
141
  - test/fixtures/dependencies/a.rb
236
142
  - test/fixtures/dependencies/b.rb
237
143
  - test/fixtures/dependencies/c.rb
144
+ - test/fixtures/dependencies/d.rb
238
145
  - test/helper.rb
239
146
  - test/test_application.rb
240
147
  - test/test_core.rb
@@ -248,7 +155,7 @@ files:
248
155
  - test/test_routing.rb
249
156
  - test/test_server.rb
250
157
  has_rdoc: true
251
- homepage: http://github.com/padrino/padrino-framework/tree/master/padrino-core
158
+ homepage: http://www.padrinorb.com
252
159
  licenses: []
253
160
 
254
161
  post_install_message: