deas 0.32.0 → 0.33.0

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: 2e01bef9b6af4303f73139d7163cffe10e365422
4
- data.tar.gz: 72a8a94d809478d18b0977d6f08db810a4801547
3
+ metadata.gz: adc507d7ca21b98b7f24b336b303ebe5800a5902
4
+ data.tar.gz: 85fc3d5b41048f51ce959d0b9fd0d630b28d477a
5
5
  SHA512:
6
- metadata.gz: d911b586a2a5550d68b1213da0928c9660bded2411454543f838d5aa882652412d7bc3717c526fd9b53349c5250ce37c66c0feffb5105e8c65ea7382bb0ebf9a
7
- data.tar.gz: 29061f4db02882144065819d5f86c720cf9859eb100972f88c070ce23c90257b65bf8f52a0cc6c973f3c94b2a6c7746656aa20613916d2be4a2049526ce321da
6
+ metadata.gz: 800d1d86aef361ab9f194f74fb83ea4951c4e45ce639c8dccf46378c3eb7daea7442045c3bbdedd6f9e238146a2a130c8b4c2b1b0234cf5d40e886eccb37ea0d
7
+ data.tar.gz: 8a67207f27e0fb0e993207c7c5f4cc31c0d189086c66a5dbfc5c9aa0845d58cc5b7807caaf23f08386867c83160c649a4d75b664d1e99e26a44fb02f29600a7c
data/lib/deas/router.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require 'deas/exceptions'
2
- require 'deas/redirect_proxy'
3
- require 'deas/route'
4
- require 'deas/route_proxy'
5
2
  require 'deas/url'
6
3
 
7
4
  module Deas
@@ -74,6 +71,7 @@ module Deas
74
71
  handler_names[self.default_request_type_name] = default_handler_name
75
72
  end
76
73
 
74
+ require 'deas/route_proxy'
77
75
  proxies = handler_names.inject({}) do |proxies, (req_type_name, handler_name)|
78
76
  proxies[req_type_name] = Deas::RouteProxy.new(handler_name, self.view_handler_ns)
79
77
  proxies
@@ -91,6 +89,7 @@ module Deas
91
89
  raise ArgumentError, "no url named `#{to_path.inspect}`"
92
90
  end
93
91
 
92
+ require 'deas/redirect_proxy'
94
93
  proxy = Deas::RedirectProxy.new(to_url || to_path, &block)
95
94
  proxies = { self.default_request_type_name => proxy }
96
95
 
@@ -108,6 +107,7 @@ module Deas
108
107
 
109
108
  def add_route(http_method, path, proxies)
110
109
  proxies = HandlerProxies.new(proxies, self.default_request_type_name)
110
+ require 'deas/route'
111
111
  Deas::Route.new(http_method, path, proxies).tap{ |r| self.routes.push(r) }
112
112
  end
113
113
 
data/lib/deas/runner.rb CHANGED
@@ -1,8 +1,3 @@
1
- # need to define class immediately b/c of circular requires:
2
- # - runner -> router -> route -> deas_runner -> runner
3
- module Deas; end
4
- class Deas::Runner; end
5
-
6
1
  require 'rack/utils'
7
2
  require 'deas/logger'
8
3
  require 'deas/router'
@@ -46,7 +46,7 @@ module Deas
46
46
  end
47
47
 
48
48
  def render(template_name, view_handler, locals, &content)
49
- [ view_handler.class.layouts,
49
+ [ view_handler.layouts,
50
50
  template_name
51
51
  ].flatten.reverse.inject(content) do |render_proc, name|
52
52
  proc{ get_engine(name).render(name, view_handler, locals, &render_proc) }
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.32.0"
2
+ VERSION = "0.33.0"
3
3
  end
@@ -37,6 +37,10 @@ module Deas
37
37
  raise NotImplementedError
38
38
  end
39
39
 
40
+ def layouts
41
+ self.class.layouts.map{ |proc| self.instance_eval(&proc) }
42
+ end
43
+
40
44
  def inspect
41
45
  reference = '0x0%x' % (self.object_id << 1)
42
46
  "#<#{self.class}:#{reference} @request=#{request.inspect}>"
@@ -62,6 +66,7 @@ module Deas
62
66
  def source_partial(*args, &block); @deas_runner.source_partial(*args, &block); end
63
67
  def send_file(*args, &block); @deas_runner.send_file(*args, &block); end
64
68
 
69
+ # TODO: make these public when built using the test helpers
65
70
  def logger; @deas_runner.logger; end
66
71
  def router; @deas_runner.router; end
67
72
  def request; @deas_runner.request; end
@@ -79,10 +84,14 @@ module Deas
79
84
 
80
85
  module ClassMethods
81
86
 
82
- def layout(*args)
83
- (@layouts ||= []).tap{ |l| l.push(*args) }
87
+ def layout(path = nil, &block)
88
+ value = !path.nil? ? Proc.new{ path } : block
89
+ self.layouts.push(value) if value
90
+ end
91
+
92
+ def layouts
93
+ @layouts ||= []
84
94
  end
85
- alias :layouts :layout
86
95
 
87
96
  def before_callbacks; @before_callbacks ||= []; end
88
97
  def after_callbacks; @after_callbacks ||= []; end
@@ -219,11 +219,11 @@ class Deas::TemplateSource
219
219
  end
220
220
 
221
221
  TestViewHandler = Class.new do
222
- def self.layouts; []; end
222
+ def layouts; []; end
223
223
  end
224
224
 
225
225
  LayoutViewHandler = Class.new do
226
- def self.layouts; ['test_layout1', 'test_layout2']; end
226
+ def layouts; ['test_layout1', 'test_layout2']; end
227
227
  end
228
228
 
229
229
  end
@@ -26,10 +26,10 @@ module Deas::ViewHandler
26
26
 
27
27
  should "specify layouts" do
28
28
  subject.layout 'layouts/app'
29
- assert_equal ['layouts/app'], subject.layouts
29
+ assert_equal ['layouts/app'], subject.layouts.map(&:call)
30
30
 
31
- subject.layouts 'layouts/web', 'layouts/search'
32
- assert_equal ['layouts/app', 'layouts/web', 'layouts/search'], subject.layouts
31
+ subject.layout { 'layouts/web' }
32
+ assert_equal ['layouts/app', 'layouts/web'], subject.layouts.map(&:call)
33
33
  end
34
34
 
35
35
  end
@@ -37,12 +37,13 @@ module Deas::ViewHandler
37
37
  class InitTests < UnitTests
38
38
  desc "when init"
39
39
  setup do
40
- @runner = test_runner(@handler_class)
40
+ @runner = test_runner(@handler_class)
41
41
  @handler = @runner.handler
42
42
  end
43
43
  subject{ @handler }
44
44
 
45
45
  should have_imeths :init, :init!, :run, :run!
46
+ should have_imeths :layouts
46
47
 
47
48
  should "have called `init!` and it's callbacks" do
48
49
  assert_equal true, subject.before_init_called
@@ -59,6 +60,21 @@ module Deas::ViewHandler
59
60
 
60
61
  end
61
62
 
63
+ class LayoutsTests < InitTests
64
+ desc "with layouts"
65
+ setup do
66
+ @params = { 'n' => Factory.integer }
67
+ @runner = test_runner(LayoutsViewHandler, :params => @params)
68
+ @handler = @runner.handler
69
+ end
70
+
71
+ should "build its layouts by instance eval'ing its class layout procs" do
72
+ exp = subject.class.layouts.map{ |proc| @handler.instance_eval(&proc) }
73
+ assert_equal exp, subject.layouts
74
+ end
75
+
76
+ end
77
+
62
78
  class RunTests < InitTests
63
79
  desc "and run"
64
80
 
@@ -279,4 +295,13 @@ module Deas::ViewHandler
279
295
 
280
296
  end
281
297
 
298
+ class LayoutsViewHandler
299
+ include Deas::ViewHandler
300
+
301
+ layout '1.html'
302
+ layout { '2.html' }
303
+ layout { "#{params['n']}.html" }
304
+
305
+ end
306
+
282
307
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-27 00:00:00.000000000 Z
12
+ date: 2015-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ns-options