deas 0.25.0 → 0.26.0

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.
data/lib/deas/router.rb CHANGED
@@ -23,6 +23,10 @@ module Deas
23
23
  @base_url
24
24
  end
25
25
 
26
+ def prepend_base_url(url_path)
27
+ "#{base_url}#{url_path}"
28
+ end
29
+
26
30
  def url(name, path)
27
31
  if !path.kind_of?(::String)
28
32
  raise ArgumentError, "invalid path `#{path.inspect}` - "\
@@ -34,8 +38,7 @@ module Deas
34
38
  def url_for(name, *args)
35
39
  url = self.urls[name.to_sym]
36
40
  raise ArgumentError, "no route named `#{name.to_sym.inspect}`" unless url
37
-
38
- "#{base_url}#{url.path_for(*args)}"
41
+ prepend_base_url(url.path_for(*args))
39
42
  end
40
43
 
41
44
  def get(path, handler_name); self.route(:get, path, handler_name); end
@@ -52,7 +55,7 @@ module Deas
52
55
 
53
56
  from_url = self.urls[from_path]
54
57
  from_url_path = from_url.path if from_url
55
- add_route(http_method, "#{base_url}#{from_url_path || from_path}", proxy)
58
+ add_route(http_method, prepend_base_url(from_url_path || from_path), proxy)
56
59
  end
57
60
 
58
61
  def redirect(from_path, to_path = nil, &block)
data/lib/deas/runner.rb CHANGED
@@ -5,7 +5,8 @@ module Deas
5
5
  class Runner
6
6
 
7
7
  attr_reader :handler_class, :handler
8
- attr_reader :request, :response, :params, :logger, :session
8
+ attr_reader :request, :response, :params
9
+ attr_reader :logger, :router, :session
9
10
 
10
11
  def initialize(handler_class)
11
12
  @handler_class = handler_class
@@ -15,6 +15,7 @@ module Deas
15
15
  @response = @sinatra_call.response
16
16
  @params = NormalizedParams.new(@sinatra_call.params).value
17
17
  @logger = @sinatra_call.settings.logger
18
+ @router = @sinatra_call.settings.router
18
19
  @session = @sinatra_call.session
19
20
 
20
21
  super(handler_class)
@@ -60,7 +61,10 @@ module Deas
60
61
 
61
62
  def render(template_name, options = nil, &block)
62
63
  options ||= {}
63
- options[:locals] = { :view => @handler }.merge(options[:locals] || {})
64
+ options[:locals] = {
65
+ :view => @handler,
66
+ :logger => @logger
67
+ }.merge(options[:locals] || {})
64
68
  options[:layout] ||= @handler_class.layouts
65
69
 
66
70
  self.content_type(get_content_type(template_name)) if self.content_type.nil?
data/lib/deas/template.rb CHANGED
@@ -65,18 +65,6 @@ module Deas
65
65
  end
66
66
  alias :u :escape_url
67
67
 
68
- def logger
69
- @sinatra_call.settings.logger
70
- end
71
-
72
- def router
73
- @sinatra_call.settings.router
74
- end
75
-
76
- def url_for(url)
77
- "#{self.router.base_url}#{url}"
78
- end
79
-
80
68
  def ==(other_scope)
81
69
  self.sinatra_call == other_scope.sinatra_call
82
70
  self.class.included_modules == other_scope.class.included_modules
@@ -1,5 +1,6 @@
1
1
  require 'ostruct'
2
2
  require 'rack/multipart'
3
+ require 'deas/router'
3
4
  require 'deas/runner'
4
5
 
5
6
  module Deas
@@ -16,6 +17,7 @@ module Deas
16
17
  @response = args.delete(:response)
17
18
  @params = NormalizedParams.new(args.delete(:params) || {}).value
18
19
  @logger = args.delete(:logger) || Deas::NullLogger.new
20
+ @router = args.delete(:router) || Deas::Router.new
19
21
  @session = args.delete(:session)
20
22
 
21
23
  super(handler_class)
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.25.0"
2
+ VERSION = "0.26.0"
3
3
  end
@@ -59,6 +59,7 @@ module Deas
59
59
 
60
60
  def app_settings; @deas_runner.app_settings; end
61
61
  def logger; @deas_runner.logger; end
62
+ def router; @deas_runner.router; end
62
63
  def request; @deas_runner.request; end
63
64
  def response; @deas_runner.response; end
64
65
  def params; @deas_runner.params; end
@@ -18,7 +18,8 @@ class FakeSinatraCall
18
18
  @settings = OpenStruct.new({
19
19
  :deas_template_scope => Deas::Template::Scope,
20
20
  :deas_default_charset => 'utf-8',
21
- :router => Deas::Router.new
21
+ :router => Deas::Router.new,
22
+ :logger => @logger
22
23
  }.merge(settings))
23
24
  end
24
25
 
@@ -11,7 +11,7 @@ class Deas::Router
11
11
  subject{ @router }
12
12
 
13
13
  should have_accessors :urls, :routes
14
- should have_imeths :view_handler_ns, :base_url
14
+ should have_imeths :view_handler_ns, :base_url, :prepend_base_url
15
15
  should have_imeths :url, :url_for
16
16
  should have_imeths :get, :post, :put, :patch, :delete
17
17
  should have_imeths :route, :redirect
@@ -103,12 +103,23 @@ class Deas::Router
103
103
  assert_equal url, subject.base_url
104
104
  end
105
105
 
106
- should "use the base url when adding routes" do
106
+ should "prepend the base url to any url path" do
107
+ url_path = Factory.path
108
+ base_url = Factory.url
109
+
110
+ assert_equal url_path, subject.prepend_base_url(url_path)
111
+
112
+ subject.base_url base_url
113
+ assert_equal "#{base_url}#{url_path}", subject.prepend_base_url(url_path)
114
+ end
115
+
116
+ should "prepend the base url when adding routes" do
107
117
  url = Factory.url
108
118
  subject.base_url url
109
- route = subject.get('/some-path', Object)
119
+ path = Factory.path
120
+ route = subject.get(path, Object)
110
121
 
111
- exp_path = "#{url}/some-path"
122
+ exp_path = subject.prepend_base_url(path)
112
123
  assert_equal exp_path, route.path
113
124
  end
114
125
 
@@ -197,13 +208,14 @@ class Deas::Router
197
208
  assert_equal url.path, route.path
198
209
  end
199
210
 
200
- should "use the base url when building named urls" do
211
+ should "prepend the base url when building named urls" do
201
212
  url = Factory.url
202
213
  subject.base_url url
203
- subject.url('base_get_info', '/info/:for')
214
+ path = Factory.path
215
+ subject.url('base_get_info', path)
204
216
 
205
- exp_path = "#{url}/info/now"
206
- assert_equal exp_path, subject.url_for(:base_get_info, :for => 'now')
217
+ exp_path = subject.prepend_base_url(path)
218
+ assert_equal exp_path, subject.url_for(:base_get_info)
207
219
  end
208
220
 
209
221
  end
@@ -13,7 +13,8 @@ class Deas::Runner
13
13
  subject{ @runner }
14
14
 
15
15
  should have_readers :handler_class, :handler
16
- should have_readers :request, :response, :params, :logger, :session
16
+ should have_readers :request, :response, :params
17
+ should have_readers :logger, :router, :session
17
18
  should have_imeths :halt, :redirect, :content_type, :status, :headers
18
19
  should have_imeths :render, :partial, :send_file
19
20
 
@@ -27,6 +28,7 @@ class Deas::Runner
27
28
  assert_nil subject.response
28
29
  assert_nil subject.params
29
30
  assert_nil subject.logger
31
+ assert_nil subject.router
30
32
  assert_nil subject.session
31
33
  end
32
34
 
@@ -4,6 +4,7 @@ require 'deas/sinatra_runner'
4
4
  require 'deas/runner'
5
5
  require 'deas/template'
6
6
  require 'test/support/fake_sinatra_call'
7
+ require 'test/support/normalized_params_spy'
7
8
  require 'test/support/view_handlers'
8
9
 
9
10
  class Deas::SinatraRunner
@@ -40,7 +41,8 @@ class Deas::SinatraRunner
40
41
  assert_equal @fake_sinatra_call.request, subject.request
41
42
  assert_equal @fake_sinatra_call.response, subject.response
42
43
  assert_equal @fake_sinatra_call.params, subject.params
43
- assert_equal @fake_sinatra_call.settings.deas_logger, subject.logger
44
+ assert_equal @fake_sinatra_call.settings.logger, subject.logger
45
+ assert_equal @fake_sinatra_call.settings.router, subject.router
44
46
  assert_equal @fake_sinatra_call.session, subject.session
45
47
  end
46
48
 
@@ -81,11 +83,14 @@ class Deas::SinatraRunner
81
83
  assert_equal [exp_headers], subject.headers(exp_headers)
82
84
  end
83
85
 
84
- should "render the template with a :view local and the handler layouts" do
86
+ should "render the template with :view/:logger locals and the handler layouts" do
85
87
  exp_handler = FlagViewHandler.new(subject)
86
88
  exp_layouts = FlagViewHandler.layouts
87
89
  exp_result = Deas::Template.new(@fake_sinatra_call, 'index', {
88
- :locals => { :view => exp_handler },
90
+ :locals => {
91
+ :view => exp_handler,
92
+ :logger => @runner.logger
93
+ },
89
94
  :layout => exp_layouts
90
95
  }).render
91
96
 
@@ -83,7 +83,6 @@ class Deas::Template
83
83
 
84
84
  should have_reader :sinatra_call
85
85
  should have_imeths :render, :partial, :escape_html, :h, :escape_url, :u
86
- should have_imeths :logger, :router, :url_for
87
86
 
88
87
  should "call the sinatra_call's erb method with #render" do
89
88
  render_args = subject.render('my_template', {
@@ -126,23 +125,6 @@ class Deas::Template
126
125
  assert_equal exp_val, subject.u("/path/to/somewhere")
127
126
  end
128
127
 
129
- should "expose the sinatra call (and deas server) logger" do
130
- assert_equal @fake_sinatra_call.settings.logger, subject.logger
131
- end
132
-
133
- should "expose the sinatra call (and deas server) router" do
134
- assert_equal @fake_sinatra_call.settings.router, subject.router
135
- end
136
-
137
- should "build urls with #url_for" do
138
- base_url = Factory.url
139
- url = Factory.url
140
- @fake_sinatra_call.settings.router.base_url(base_url)
141
-
142
- exp = "#{base_url}#{url}"
143
- assert_equal exp, subject.url_for(url)
144
- end
145
-
146
128
  end
147
129
 
148
130
  class PartialTests < UnitTests
@@ -2,6 +2,7 @@ require 'assert'
2
2
  require 'deas/test_runner'
3
3
 
4
4
  require 'rack/test'
5
+ require 'deas/router'
5
6
  require 'deas/runner'
6
7
  require 'test/support/normalized_params_spy'
7
8
  require 'test/support/view_handlers'
@@ -43,6 +44,7 @@ class Deas::TestRunner
43
44
  assert_nil subject.response
44
45
  assert_kind_of ::Hash, subject.params
45
46
  assert_kind_of Deas::NullLogger, subject.logger
47
+ assert_kind_of Deas::Router, subject.router
46
48
  assert_nil subject.session
47
49
  end
48
50
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 123
4
+ hash: 119
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 25
8
+ - 26
9
9
  - 0
10
- version: 0.25.0
10
+ version: 0.26.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2014-08-01 00:00:00 Z
19
+ date: 2014-09-30 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement