deas 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/deas.gemspec CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency("assert")
25
25
  gem.add_development_dependency("assert-mocha")
26
26
  gem.add_development_dependency("assert-rack-test")
27
+ gem.add_development_dependency('haml')
27
28
 
28
29
  end
data/lib/deas/template.rb CHANGED
@@ -15,6 +15,14 @@ module Deas
15
15
  end
16
16
  end
17
17
 
18
+ def engine(template_name)
19
+ return 'erb' if @sinatra_call.settings.views.nil?
20
+
21
+ views_path = Pathname.new(@sinatra_call.settings.views)
22
+ template = Dir.glob("#{views_path.join(template_name.to_s)}.*").first.to_s
23
+ File.extname(template)[1..-1] || 'erb'
24
+ end
25
+
18
26
  # builds render-blocks like:
19
27
  #
20
28
  # erb :main_layout do
@@ -26,7 +34,7 @@ module Deas
26
34
  def render(&block)
27
35
  template_names = [ @layouts, @name ].flatten.reverse
28
36
  top_render_proc = template_names.inject(block) do |render_proc, name|
29
- proc{ @sinatra_call.erb(name, @options, &render_proc) }
37
+ proc{ @sinatra_call.send(engine(name), name, @options, &render_proc) }
30
38
  end
31
39
  top_render_proc.call
32
40
  end
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -8,12 +8,14 @@ class FakeApp
8
8
 
9
9
  attr_accessor :request, :response, :params, :settings, :session
10
10
 
11
- def initialize
11
+ def initialize(settings={})
12
12
  @request = FakeRequest.new('GET','/something', {}, OpenStruct.new)
13
13
  @params = @request.params
14
14
  @session = @request.session
15
15
  @response = FakeResponse.new
16
- @settings = OpenStruct.new(:deas_template_scope => Deas::Template::Scope)
16
+ @settings = OpenStruct.new(settings.merge({
17
+ :deas_template_scope => Deas::Template::Scope
18
+ }))
17
19
  end
18
20
 
19
21
  def halt(*args)
@@ -22,12 +22,16 @@ class DeasTestServer
22
22
  get '/show', 'ShowHandler'
23
23
  get '/halt', 'HaltHandler'
24
24
  get '/error', 'ErrorHandler'
25
- get '/with_layout', 'WithLayoutHandler'
26
- get '/alt_with_layout', 'AlternateWithLayoutHandler'
27
25
  get '/redirect', 'RedirectHandler'
28
26
  post '/session', 'SetSessionHandler'
29
27
  get '/session', 'UseSessionHandler'
30
28
 
29
+ get '/with_layout', 'WithLayoutHandler'
30
+ get '/alt_with_layout', 'AlternateWithLayoutHandler'
31
+ get '/haml_with_layout', 'HamlWithLayoutHandler'
32
+ get '/with_haml_layout', 'WithHamlLayoutHandler'
33
+ get '/haml_with_haml_layout', 'HamlWithHamlLayoutHandler'
34
+
31
35
  get '/handler/tests.json', 'HandlerTestsHandler'
32
36
 
33
37
  redirect :get, '/route_redirect', '/somewhere'
@@ -110,6 +114,36 @@ class AlternateWithLayoutHandler
110
114
 
111
115
  end
112
116
 
117
+ class HamlWithLayoutHandler
118
+ include Deas::ViewHandler
119
+ layouts 'layout1'
120
+
121
+ def run!
122
+ render 'haml_with_layout'
123
+ end
124
+
125
+ end
126
+
127
+ class WithHamlLayoutHandler
128
+ include Deas::ViewHandler
129
+ layouts 'haml_layout1'
130
+
131
+ def run!
132
+ render 'with_layout'
133
+ end
134
+
135
+ end
136
+
137
+ class HamlWithHamlLayoutHandler
138
+ include Deas::ViewHandler
139
+ layouts 'haml_layout1'
140
+
141
+ def run!
142
+ render 'haml_with_layout'
143
+ end
144
+
145
+ end
146
+
113
147
  class RedirectHandler
114
148
  include Deas::ViewHandler
115
149
 
@@ -0,0 +1,2 @@
1
+ Layout 1
2
+ =yield
@@ -0,0 +1 @@
1
+ With Layout
File without changes
File without changes
File without changes
@@ -47,15 +47,30 @@ module Deas
47
47
  assert_equal "Oops, something went wrong", last_response.body
48
48
  end
49
49
 
50
- should "return a 200 response and use all the layouts" do
51
- get '/with_layout'
52
-
50
+ should "render erb templates using layouts" do
53
51
  expected_body = "Layout 1\nLayout 2\nLayout 3\nWith Layout\n"
52
+
53
+ get '/with_layout'
54
54
  assert_equal 200, last_response.status
55
55
  assert_equal expected_body, last_response.body
56
56
 
57
57
  get '/alt_with_layout'
58
+ assert_equal 200, last_response.status
59
+ assert_equal expected_body, last_response.body
60
+ end
61
+
62
+ should "render mixed (erb and other) templates using layouts" do
63
+ expected_body = "Layout 1\nWith Layout\n"
64
+
65
+ get '/haml_with_layout'
66
+ assert_equal 200, last_response.status
67
+ assert_equal expected_body, last_response.body
68
+
69
+ get '/with_haml_layout'
70
+ assert_equal 200, last_response.status
71
+ assert_equal expected_body, last_response.body
58
72
 
73
+ get '/haml_with_haml_layout'
59
74
  assert_equal 200, last_response.status
60
75
  assert_equal expected_body, last_response.body
61
76
  end
@@ -12,7 +12,7 @@ class Deas::Template
12
12
  end
13
13
  subject{ @template }
14
14
 
15
- should have_instance_methods :name, :options, :render
15
+ should have_instance_methods :name, :options, :render, :engine
16
16
 
17
17
  should "symbolize it's name" do
18
18
  assert_equal :"users/index", subject.name
@@ -22,6 +22,29 @@ class Deas::Template
22
22
  assert_instance_of Deas::Template::Scope, subject.options[:scope]
23
23
  end
24
24
 
25
+ should "know a named template's render engine" do
26
+ views_exist = FakeApp.new(:views => TEST_SUPPORT_ROOT.join('views'))
27
+ template = Deas::Template.new(views_exist, 'whatever')
28
+
29
+ assert_equal 'erb', template.engine('layout1')
30
+ assert_equal 'haml', template.engine('haml_layout1')
31
+ assert_equal 'other', template.engine('some.html.file')
32
+ assert_equal 'engine', template.engine('some_file')
33
+ assert_equal 'erb', template.engine('some_no_engine_extension')
34
+ assert_equal 'erb', template.engine('does_not_exist')
35
+
36
+ views_no_exist = FakeApp.new(:views => '/does/not/exist')
37
+ template_no_exist = Deas::Template.new(views_no_exist, 'whatever')
38
+
39
+ assert_equal 'erb', template_no_exist.engine('layout1')
40
+ assert_equal 'erb', template_no_exist.engine('haml_layout1')
41
+ assert_equal 'erb', template_no_exist.engine('some.html.file')
42
+ assert_equal 'erb', template_no_exist.engine('some_file')
43
+ assert_equal 'erb', template_no_exist.engine('some_no_engine_extension')
44
+ assert_equal 'erb', template_no_exist.engine('does_not_exist')
45
+
46
+ end
47
+
25
48
  should "call the sinatra_call's `erb` method with #render" do
26
49
  return_value = subject.render
27
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: 47
4
+ hash: 43
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 12
8
+ - 13
9
9
  - 0
10
- version: 0.12.0
10
+ version: 0.13.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: 2013-05-21 00:00:00 Z
19
+ date: 2013-05-22 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: ns-options
@@ -113,6 +113,20 @@ dependencies:
113
113
  version: "0"
114
114
  type: :development
115
115
  version_requirements: *id006
116
+ - !ruby/object:Gem::Dependency
117
+ name: haml
118
+ prerelease: false
119
+ requirement: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ type: :development
129
+ version_requirements: *id007
116
130
  description: Handler-based web framework powered by Sinatra
117
131
  email:
118
132
  - kelly@kellyredding.com
@@ -153,10 +167,15 @@ files:
153
167
  - test/support/routes.rb
154
168
  - test/support/view_handlers.rb
155
169
  - test/support/views/_info.erb
170
+ - test/support/views/haml_layout1.haml
171
+ - test/support/views/haml_with_layout.haml
156
172
  - test/support/views/layout1.erb
157
173
  - test/support/views/layout2.erb
158
174
  - test/support/views/layout3.erb
159
175
  - test/support/views/show.erb
176
+ - test/support/views/some.html.file.other
177
+ - test/support/views/some_file.engine
178
+ - test/support/views/some_no_engine_extension
160
179
  - test/support/views/with_layout.erb
161
180
  - test/system/rack_tests.rb
162
181
  - test/unit/error_handler_tests.rb
@@ -212,10 +231,15 @@ test_files:
212
231
  - test/support/routes.rb
213
232
  - test/support/view_handlers.rb
214
233
  - test/support/views/_info.erb
234
+ - test/support/views/haml_layout1.haml
235
+ - test/support/views/haml_with_layout.haml
215
236
  - test/support/views/layout1.erb
216
237
  - test/support/views/layout2.erb
217
238
  - test/support/views/layout3.erb
218
239
  - test/support/views/show.erb
240
+ - test/support/views/some.html.file.other
241
+ - test/support/views/some_file.engine
242
+ - test/support/views/some_no_engine_extension
219
243
  - test/support/views/with_layout.erb
220
244
  - test/system/rack_tests.rb
221
245
  - test/unit/error_handler_tests.rb