padrino-core 0.12.0.rc2 → 0.12.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36ae10f9e389e527fa9dcec4bba7bf0d043d5e53
4
- data.tar.gz: e35bacd38ed575f456711d63a3f2c4482980bf16
3
+ metadata.gz: c6ea54a7ca6507bdf5a70d33d0474da425b14980
4
+ data.tar.gz: e614251aa0601ede038832b7b3c0b198320f90d4
5
5
  SHA512:
6
- metadata.gz: 076b43b1a789f3c6a84f04f578cd4b592ea45bb3fbde45d29bee659a1064240acd6df9c99c654485138b42d3fcc5f7e5bd3c148f69bfdb6f65fbc4214a48dea8
7
- data.tar.gz: 673d23844abf49d4e2aa1f2c7bae616cfe25b177e78bfdf338ec045b620fc7c69a4f225cc5656e81387c5fb246c13088fc3b80f25722d941b67643de9023ea23
6
+ metadata.gz: 29acbac657d342ba26fe4c728cda9d4822daba4055301530aca6e91761f5f96c8a2a1d92c4cc8e48971a31126c24439dcb4befc9859d7ac95b9e861f0fadb8b4
7
+ data.tar.gz: 0675c7fe47f31dc155cc8d1b8f4707bdbf05c2790e98d47313dae2dff0f701d3671d590266ea3df8e13c029c8eec2c8c3faacd63d37f0ff39d6b5587052dabf5
@@ -14,7 +14,11 @@ require 'padrino-core/server'
14
14
  require 'padrino-core/tasks'
15
15
  require 'padrino-core/module'
16
16
 
17
- PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
17
+ if ENV["PADRINO_ENV"]
18
+ warn 'Environment variable PADRINO_ENV is deprecated. Please, use RACK_ENV.'
19
+ ENV["RACK_ENV"] ||= ENV["PADRINO_ENV"]
20
+ end
21
+ RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined?(RACK_ENV)
18
22
  PADRINO_ROOT = ENV["PADRINO_ROOT"] ||= File.dirname(Padrino.first_caller) unless defined?(PADRINO_ROOT)
19
23
 
20
24
  module Padrino
@@ -43,13 +47,13 @@ module Padrino
43
47
  end
44
48
 
45
49
  ##
46
- # Helper method that return {PADRINO_ENV}.
50
+ # Helper method that return {RACK_ENV}.
47
51
  #
48
52
  # @return [Symbol]
49
53
  # The Padrino Environment.
50
54
  #
51
55
  def env
52
- @_env ||= PADRINO_ENV.to_s.downcase.to_sym
56
+ @_env ||= RACK_ENV.to_s.downcase.to_sym
53
57
  end
54
58
 
55
59
  ##
@@ -1,7 +1,7 @@
1
1
  require 'padrino-core/application/flash'
2
2
  require 'padrino-core/application/rendering'
3
3
  require 'padrino-core/application/routing'
4
- require 'padrino-core/application/showexceptions'
4
+ require 'padrino-core/application/show_exceptions'
5
5
  require 'padrino-core/application/authenticity_token'
6
6
 
7
7
  module Padrino
@@ -201,6 +201,10 @@ module Padrino
201
201
  @_prerequisites ||= []
202
202
  end
203
203
 
204
+ def default(option, *args, &block)
205
+ set(option, *args, &block) unless respond_to?(option)
206
+ end
207
+
204
208
  protected
205
209
 
206
210
  ##
@@ -204,7 +204,7 @@ module Padrino
204
204
  options[:layout] = false unless is_included_extension ? layout_engine : layout_engine == engine
205
205
  options[:layout_engine] = layout_engine || engine if options[:layout]
206
206
  elsif options[:layout].present?
207
- options[:layout], options[:layout_engine] = *resolve_template(settings.fetch_layout_path(options[:layout]))
207
+ options[:layout], options[:layout_engine] = *resolve_template(settings.fetch_layout_path(options[:layout]), options)
208
208
  end
209
209
  # Default to original layout value if none found.
210
210
  options[:layout] ||= layout_was
@@ -274,7 +274,7 @@ module Padrino
274
274
  end
275
275
 
276
276
  # Resolve view path and options.
277
- options.reverse_merge!(DEFAULT_RENDERING_OPTIONS)
277
+ options = DEFAULT_RENDERING_OPTIONS.merge(options)
278
278
  view_path = options.delete(:views) || settings.views || "./views"
279
279
  target_extension = File.extname(template_path)[1..-1] || "none" # explicit template extension
280
280
  template_path = template_path.chomp(".#{target_extension}")
@@ -514,7 +514,13 @@ module Padrino
514
514
 
515
515
  def compiled_router
516
516
  if @deferred_routes
517
- deferred_routes.each { |routes| routes.each { |(route, dest)| route.to(dest) } }
517
+ deferred_routes.each do |routes|
518
+ routes.each do |(route, dest)|
519
+ route.to(dest)
520
+ route.before_filters.flatten!
521
+ route.after_filters.flatten!
522
+ end
523
+ end
518
524
  @deferred_routes = nil
519
525
  router.sort!
520
526
  end
@@ -724,8 +730,8 @@ module Padrino
724
730
  invoke_hook(:padrino_route_added, route, verb, path, args, options, block)
725
731
 
726
732
  # Add Application defaults.
727
- route.before_filters.concat(@filters[:before])
728
- route.after_filters.concat(@filters[:after])
733
+ route.before_filters << @filters[:before]
734
+ route.after_filters << @filters[:after]
729
735
  if @_controller
730
736
  route.use_layout = @layout
731
737
  route.controller = Array(@_controller)[0].to_s
@@ -5,7 +5,7 @@ module Padrino
5
5
  %r{lib/padrino-.*$},
6
6
  %r{/padrino-.*/(lib|bin)},
7
7
  %r{/bin/padrino$},
8
- %r{/sinatra(/(base|main|showexceptions))?\.rb$},
8
+ %r{/sinatra(/(base|main|show_?exceptions))?\.rb$},
9
9
  %r{lib/tilt.*\.rb$},
10
10
  %r{lib/rack.*\.rb$},
11
11
  %r{lib/mongrel.*\.rb$},
@@ -124,7 +124,7 @@ module Padrino
124
124
  help(task.to_s)
125
125
  raise SystemExit
126
126
  end
127
- ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= options.environment.to_s
127
+ ENV["RACK_ENV"] ||= options.environment.to_s
128
128
  chdir(options.chdir)
129
129
  unless File.exist?('config/boot.rb')
130
130
  puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
@@ -4,9 +4,9 @@ zh_cn:
4
4
  # Use the strftime parameters for formats.
5
5
  # When no format has been given, it uses default.
6
6
  # You can provide other formats here if you like!
7
- default: "%Y 年 %m 月 %d 日"
8
- short: "%b 月 %d 日"
9
- long: "公元 %Y 年 %B 月 %d 日"
7
+ default: "%Y年%m月%d日"
8
+ short: "%b月%d日"
9
+ long: "%Y年%B月%d日"
10
10
  only_day: "%e"
11
11
 
12
12
  day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六]
@@ -20,9 +20,9 @@ zh_cn:
20
20
 
21
21
  time:
22
22
  formats:
23
- default: "%Y 年 %b 月 %d 日 %H:%M:%S %z"
24
- short: "%d 月 %b 日 %H:%M"
25
- long: "%Y 年 %B%d 日 %H 时 %M 分"
23
+ default: "%Y年%b月%d日 %H:%M:%S %z"
24
+ short: "%b月%d日 %H:%M"
25
+ long: "%Y年%B%d日 %H时%M分"
26
26
  am: "上午"
27
27
  pm: "下午"
28
28
 
@@ -89,7 +89,7 @@ module Padrino
89
89
  return unless options[:force] || file_changed?(file)
90
90
 
91
91
  Storage.prepare(file) # might call #safe_load recursively
92
- logger.debug(file_new?(file) ? :loading : :reload, began_at, file)
92
+ logger.devel(file_new?(file) ? :loading : :reload, began_at, file)
93
93
  begin
94
94
  with_silence{ require(file) }
95
95
  Storage.commit(file)
@@ -153,7 +153,7 @@ module Padrino
153
153
  began_at = Time.now
154
154
  I18n.reload!
155
155
  update_modification_time(file)
156
- logger.debug :reload, began_at, file
156
+ logger.devel :reload, began_at, file
157
157
  end
158
158
  true
159
159
  end
@@ -6,7 +6,7 @@
6
6
  #
7
7
  module Padrino
8
8
  # The version constant for the current version of Padrino.
9
- VERSION = '0.12.0.rc2' unless defined?(Padrino::VERSION)
9
+ VERSION = '0.12.0.rc3' unless defined?(Padrino::VERSION)
10
10
 
11
11
  #
12
12
  # The current Padrino version.
@@ -4,4 +4,4 @@ module AppGem
4
4
  extend Padrino::Module
5
5
 
6
6
  gem! 'app_gem'
7
- end
7
+ end
@@ -1,5 +1,5 @@
1
1
  PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
- # Remove this comment if you want do some like this: ruby PADRINO_ENV=test app.rb
2
+ # Remove this comment if you want do some like this: ruby RACK_ENV=test app.rb
3
3
  #
4
4
  # require 'rubygems'
5
5
  # require 'padrino-core'
@@ -0,0 +1 @@
1
+ <%= yield %> absolute layout
@@ -1,4 +1,4 @@
1
- ENV['PADRINO_ENV'] = 'test'
1
+ ENV['RACK_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
3
3
 
4
4
  require File.expand_path('../../../load_paths', __FILE__)
@@ -69,5 +69,18 @@ describe "Core" do
69
69
  res = Rack::MockRequest.new(Padrino.application).get("/")
70
70
  assert_equal "yes", res["Middleware-Called"]
71
71
  end
72
+
73
+ should "properly set default options" do
74
+ mock_app do
75
+ default :foo, :bar
76
+ default :zoo, :baz
77
+ set :foo, :bam
78
+ set :moo, :bam
79
+ default :moo, :ban
80
+ end
81
+ assert_equal @app.settings.foo, :bam
82
+ assert_equal @app.settings.zoo, :baz
83
+ assert_equal @app.settings.moo, :bam
84
+ end
72
85
  end
73
86
  end
@@ -446,7 +446,14 @@ describe "Rendering" do
446
446
  I18n.locale = :en
447
447
  get "/foo.pk"
448
448
  assert_equal 404, status
449
+ end
449
450
 
451
+ should 'resolve templates and layouts located in absolute paths' do
452
+ mock_app do
453
+ get("/foo") { render 'apps/views/blog/post', :layout => 'layout', :views => File.dirname(__FILE__)+'/fixtures' }
454
+ end
455
+ get '/foo'
456
+ assert_match /okay absolute layout/, body
450
457
  end
451
458
 
452
459
  should 'resolve template content_type and locale with layout' do
@@ -1488,6 +1488,51 @@ describe "Routing" do
1488
1488
  assert_equal '{"test"=>"what"}', body
1489
1489
  end
1490
1490
 
1491
+ should "work only for the given controller and route when using before-filter with route's name" do
1492
+ mock_app do
1493
+ controller :foo do
1494
+ before(:index) { @a = "only to :index" }
1495
+ get(:index) { @a }
1496
+ get(:main) { @a }
1497
+ end
1498
+ end
1499
+ get '/foo/'
1500
+ assert_equal 'only to :index', body
1501
+ get '/foo/main'
1502
+ assert_equal '', body
1503
+ end
1504
+
1505
+ should "work only for the given controller and route when using after-filter with route's name" do
1506
+ mock_app do
1507
+ controller :after_controller do
1508
+ global = "global variable"
1509
+ get(:index) { global }
1510
+ get(:main) { global }
1511
+ after(:index) { global = nil }
1512
+ end
1513
+ end
1514
+ get '/after_controller'
1515
+ assert_equal 'global variable', body
1516
+ get '/after_controller'
1517
+ assert_equal '', body
1518
+ end
1519
+
1520
+ should "execute the before/after filters when they are inserted after the target route" do
1521
+ mock_app do
1522
+ controller :after_test do
1523
+ global = "global variable"
1524
+ get(:index) { global }
1525
+ get(:foo) { global }
1526
+ before(:index) { global.delete!(" ") }
1527
+ after(:index) { global = "after" }
1528
+ end
1529
+ end
1530
+ get '/after_test'
1531
+ assert_equal 'globalvariable', body
1532
+ get '/after_test/foo'
1533
+ assert_equal 'after', body
1534
+ end
1535
+
1491
1536
  should 'work with controller and arbitrary params' do
1492
1537
  mock_app do
1493
1538
  get(:testing) { params[:foo] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0.rc2
4
+ version: 0.12.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-01-05 00:00:00.000000000 Z
14
+ date: 2014-01-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: tilt
@@ -121,7 +121,7 @@ files:
121
121
  - lib/padrino-core/application/rendering/extensions/haml.rb
122
122
  - lib/padrino-core/application/rendering/extensions/slim.rb
123
123
  - lib/padrino-core/application/routing.rb
124
- - lib/padrino-core/application/showexceptions.rb
124
+ - lib/padrino-core/application/show_exceptions.rb
125
125
  - lib/padrino-core/caller.rb
126
126
  - lib/padrino-core/cli/adapter.rb
127
127
  - lib/padrino-core/cli/base.rb
@@ -190,6 +190,7 @@ files:
190
190
  - test/fixtures/dependencies/circular/f.rb
191
191
  - test/fixtures/dependencies/circular/g.rb
192
192
  - test/fixtures/dependencies/d.rb
193
+ - test/fixtures/layouts/layout.erb
193
194
  - test/helper.rb
194
195
  - test/mini_shoulda.rb
195
196
  - test/test_application.rb
@@ -261,6 +262,7 @@ test_files:
261
262
  - test/fixtures/dependencies/circular/f.rb
262
263
  - test/fixtures/dependencies/circular/g.rb
263
264
  - test/fixtures/dependencies/d.rb
265
+ - test/fixtures/layouts/layout.erb
264
266
  - test/helper.rb
265
267
  - test/mini_shoulda.rb
266
268
  - test/test_application.rb