deas 0.22.1 → 0.23.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/deas.gemspec +1 -1
- data/lib/deas/logging.rb +4 -1
- data/lib/deas/template.rb +2 -2
- data/lib/deas/version.rb +1 -1
- data/test/support/fake_sinatra_call.rb +6 -3
- data/test/unit/template_tests.rb +36 -39
- metadata +10 -9
data/deas.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency("rack", ["~> 1.5"])
|
22
22
|
gem.add_dependency("sinatra", ["~> 1.4"])
|
23
23
|
|
24
|
-
gem.add_development_dependency("assert")
|
24
|
+
gem.add_development_dependency("assert", ["~>2.3"])
|
25
25
|
gem.add_development_dependency("assert-mocha")
|
26
26
|
gem.add_development_dependency("assert-rack-test")
|
27
27
|
gem.add_development_dependency('haml')
|
data/lib/deas/logging.rb
CHANGED
@@ -30,14 +30,17 @@ module Deas
|
|
30
30
|
|
31
31
|
# The real Rack call interface.
|
32
32
|
# This is the common behavior for both the verbose and summary logging
|
33
|
-
# middlewares. It times the response and returns it as is.
|
33
|
+
# middlewares. It sets rack's logger, times the response and returns it as is.
|
34
34
|
def call!(env)
|
35
|
+
env['rack.logger'] = @logger
|
36
|
+
|
35
37
|
status, headers, body = nil, nil, nil
|
36
38
|
benchmark = Benchmark.measure do
|
37
39
|
status, headers, body = @app.call(env)
|
38
40
|
end
|
39
41
|
log_error(env['sinatra.error'])
|
40
42
|
env['deas.time_taken'] = RoundedTime.new(benchmark.real)
|
43
|
+
|
41
44
|
[ status, headers, body ]
|
42
45
|
end
|
43
46
|
|
data/lib/deas/template.rb
CHANGED
@@ -49,8 +49,8 @@ module Deas
|
|
49
49
|
Template.new(@sinatra_call, name, options || {}).render(&block)
|
50
50
|
end
|
51
51
|
|
52
|
-
def partial(name, locals = nil)
|
53
|
-
Partial.new(@sinatra_call, name, locals || {}).render
|
52
|
+
def partial(name, locals = nil, &block)
|
53
|
+
Partial.new(@sinatra_call, name, locals || {}).render(&block)
|
54
54
|
end
|
55
55
|
|
56
56
|
def escape_html(html)
|
data/lib/deas/version.rb
CHANGED
@@ -33,11 +33,14 @@ class FakeSinatraCall
|
|
33
33
|
def headers(*args); args; end
|
34
34
|
|
35
35
|
# return the template name for each nested calls
|
36
|
-
|
36
|
+
|
37
|
+
RenderArgs = Struct.new(:template_name, :opts, :block_call_result)
|
38
|
+
|
39
|
+
def erb(template_name, opts, &block)
|
37
40
|
if block
|
38
|
-
|
41
|
+
RenderArgs.new(template_name, opts, block.call)
|
39
42
|
else
|
40
|
-
|
43
|
+
RenderArgs.new(template_name, opts, nil)
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
data/test/unit/template_tests.rb
CHANGED
@@ -4,7 +4,7 @@ require 'deas/template'
|
|
4
4
|
|
5
5
|
class Deas::Template
|
6
6
|
|
7
|
-
class
|
7
|
+
class UnitTests < Assert::Context
|
8
8
|
desc "Deas::Template"
|
9
9
|
setup do
|
10
10
|
@fake_sinatra_call = FakeSinatraCall.new
|
@@ -54,7 +54,7 @@ class Deas::Template
|
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
|
-
class WithLayoutsTests <
|
57
|
+
class WithLayoutsTests < UnitTests
|
58
58
|
desc "with layouts"
|
59
59
|
setup do
|
60
60
|
@template = Deas::Template.new(@fake_sinatra_call, 'users/index', {
|
@@ -62,20 +62,19 @@ class Deas::Template
|
|
62
62
|
})
|
63
63
|
end
|
64
64
|
|
65
|
-
should "call the engine's `erb` method for each layout
|
66
|
-
|
67
|
-
|
65
|
+
should "call the engine's `erb` method for each layout" do
|
66
|
+
web_lay_render_args = subject.render
|
67
|
+
search_lay_render_args = web_lay_render_args.block_call_result
|
68
|
+
users_index_render_args = search_lay_render_args.block_call_result
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
assert_equal :"
|
72
|
-
assert_equal :"layouts/search", return_value[2]
|
73
|
-
assert_equal :"users/index", return_value[4]
|
70
|
+
assert_equal :"layouts/web", web_lay_render_args.template_name
|
71
|
+
assert_equal :"layouts/search", search_lay_render_args.template_name
|
72
|
+
assert_equal :"users/index", users_index_render_args.template_name
|
74
73
|
end
|
75
74
|
|
76
75
|
end
|
77
76
|
|
78
|
-
class ScopeTests <
|
77
|
+
class ScopeTests < UnitTests
|
79
78
|
desc "Deas::Template::RenderScope"
|
80
79
|
setup do
|
81
80
|
@scope = Deas::Template::Scope.new(@fake_sinatra_call)
|
@@ -86,47 +85,45 @@ class Deas::Template
|
|
86
85
|
should have_imeths :render, :partial, :escape_html, :h, :escape_url, :u
|
87
86
|
should have_imeths :logger
|
88
87
|
|
89
|
-
should "call the sinatra_call's erb method with #
|
90
|
-
|
88
|
+
should "call the sinatra_call's erb method with #render" do
|
89
|
+
render_args = subject.render('my_template', {
|
90
|
+
:views => '/path/to/templates',
|
91
|
+
:locals => { :something => true }
|
92
|
+
}, &Proc.new{ '#render called this proc' })
|
91
93
|
|
92
|
-
assert_equal :
|
94
|
+
assert_equal :my_template, render_args.template_name
|
95
|
+
assert_instance_of Deas::Template::Scope, render_args.opts[:scope]
|
93
96
|
|
94
|
-
|
95
|
-
|
97
|
+
exp_locals = { :something => true }
|
98
|
+
assert_equal exp_locals, render_args.opts[:locals]
|
96
99
|
|
97
|
-
|
98
|
-
assert_equal(expected_locals, expected_options[:locals])
|
100
|
+
assert_equal '#render called this proc', render_args.block_call_result
|
99
101
|
end
|
100
102
|
|
101
|
-
should "call the sinatra_call's erb method with #
|
102
|
-
|
103
|
-
:
|
104
|
-
|
105
|
-
})
|
103
|
+
should "call the sinatra_call's erb method with #partial" do
|
104
|
+
render_args = subject.partial('part', {
|
105
|
+
:something => true
|
106
|
+
}, &Proc.new{ '#partial called this proc' })
|
106
107
|
|
107
|
-
assert_equal :
|
108
|
+
assert_equal :_part, render_args.template_name
|
109
|
+
assert_instance_of Deas::Template::Scope, render_args.opts[:scope]
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
+
exp_locals = { :something => true }
|
112
|
+
assert_equal exp_locals, render_args.opts[:locals]
|
111
113
|
|
112
|
-
|
113
|
-
assert_equal(expected_locals, expected_options[:locals])
|
114
|
+
assert_equal '#partial called this proc', render_args.block_call_result
|
114
115
|
end
|
115
116
|
|
116
117
|
should "escape html with #h or #escape_html" do
|
117
|
-
|
118
|
-
assert_equal "
|
119
|
-
|
120
|
-
return_value = subject.h("<strong></strong>")
|
121
|
-
assert_equal "<strong></strong>", return_value
|
118
|
+
exp_val = "<strong></strong>"
|
119
|
+
assert_equal exp_val, subject.escape_html("<strong></strong>")
|
120
|
+
assert_equal exp_val, subject.h("<strong></strong>")
|
122
121
|
end
|
123
122
|
|
124
123
|
should "escape urls with #u or #escape_url" do
|
125
|
-
|
126
|
-
assert_equal "
|
127
|
-
|
128
|
-
return_value = subject.u("/path/to/somewhere")
|
129
|
-
assert_equal "%2Fpath%2Fto%2Fsomewhere", return_value
|
124
|
+
exp_val = "%2Fpath%2Fto%2Fsomewhere"
|
125
|
+
assert_equal exp_val, subject.escape_url("/path/to/somewhere")
|
126
|
+
assert_equal exp_val, subject.u("/path/to/somewhere")
|
130
127
|
end
|
131
128
|
|
132
129
|
should "expose the sinatra call (and deas server) logger" do
|
@@ -135,7 +132,7 @@ class Deas::Template
|
|
135
132
|
|
136
133
|
end
|
137
134
|
|
138
|
-
class PartialTests <
|
135
|
+
class PartialTests < UnitTests
|
139
136
|
desc "Partial"
|
140
137
|
setup do
|
141
138
|
@partial = Deas::Template::Partial.new(@fake_sinatra_call, 'users/index/listing', {
|
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:
|
4
|
+
hash: 67
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 23
|
9
|
+
- 0
|
10
|
+
version: 0.23.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-10-
|
19
|
+
date: 2013-10-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ns-options
|
@@ -77,12 +77,13 @@ dependencies:
|
|
77
77
|
requirement: &id004 !ruby/object:Gem::Requirement
|
78
78
|
none: false
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
hash:
|
82
|
+
hash: 5
|
83
83
|
segments:
|
84
|
-
-
|
85
|
-
|
84
|
+
- 2
|
85
|
+
- 3
|
86
|
+
version: "2.3"
|
86
87
|
type: :development
|
87
88
|
version_requirements: *id004
|
88
89
|
- !ruby/object:Gem::Dependency
|