deas 0.29.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/deas.gemspec +0 -1
- data/lib/deas/deas_runner.rb +16 -0
- data/lib/deas/runner.rb +10 -8
- data/lib/deas/server.rb +0 -7
- data/lib/deas/sinatra_app.rb +0 -1
- data/lib/deas/sinatra_runner.rb +2 -23
- data/lib/deas/template_source.rb +20 -11
- data/lib/deas/test_runner.rb +14 -4
- data/lib/deas/version.rb +1 -1
- data/lib/deas/view_handler.rb +5 -3
- data/test/support/fake_sinatra_call.rb +0 -11
- data/test/support/routes.rb +4 -59
- data/test/support/template.erb +1 -1
- data/test/support/template.json +1 -1
- data/test/support/view_handlers.rb +21 -2
- data/test/system/rack_tests.rb +13 -43
- data/test/unit/deas_runner_tests.rb +87 -0
- data/test/unit/runner_tests.rb +4 -1
- data/test/unit/server_configuration_tests.rb +1 -10
- data/test/unit/sinatra_runner_tests.rb +0 -78
- data/test/unit/template_source_tests.rb +20 -16
- data/test/unit/test_runner_tests.rb +54 -14
- data/test/unit/view_handler_tests.rb +21 -6
- metadata +4 -49
- data/lib/deas/template.rb +0 -86
- data/test/support/views/_info.erb +0 -1
- data/test/support/views/haml_layout1.haml +0 -2
- data/test/support/views/haml_with_layout.haml +0 -1
- data/test/support/views/layout1.erb +0 -2
- data/test/support/views/layout2.erb +0 -2
- data/test/support/views/layout3.erb +0 -2
- data/test/support/views/show.erb +0 -2
- data/test/support/views/show.html.erb +0 -0
- data/test/support/views/show.json.erb +0 -0
- data/test/support/views/show_json.erb +0 -0
- data/test/support/views/some.html.file.other +0 -0
- data/test/support/views/some_file.engine +0 -0
- data/test/support/views/some_no_engine_extension +0 -0
- data/test/support/views/with_layout.erb +0 -1
- data/test/unit/template_tests.rb +0 -150
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: 103
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 30
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.30.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: 2015-
|
19
|
+
date: 2015-02-04 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -100,20 +100,6 @@ dependencies:
|
|
100
100
|
name: assert-rack-test
|
101
101
|
version_requirements: *id005
|
102
102
|
prerelease: false
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ">="
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
hash: 3
|
110
|
-
segments:
|
111
|
-
- 0
|
112
|
-
version: "0"
|
113
|
-
type: :development
|
114
|
-
name: haml
|
115
|
-
version_requirements: *id006
|
116
|
-
prerelease: false
|
117
103
|
description: Handler-based web framework powered by Sinatra
|
118
104
|
email:
|
119
105
|
- kelly@kellyredding.com
|
@@ -148,7 +134,6 @@ files:
|
|
148
134
|
- lib/deas/show_exceptions.rb
|
149
135
|
- lib/deas/sinatra_app.rb
|
150
136
|
- lib/deas/sinatra_runner.rb
|
151
|
-
- lib/deas/template.rb
|
152
137
|
- lib/deas/template_engine.rb
|
153
138
|
- lib/deas/template_source.rb
|
154
139
|
- lib/deas/test_helpers.rb
|
@@ -168,20 +153,6 @@ files:
|
|
168
153
|
- test/support/test_layout2.test
|
169
154
|
- test/support/test_template.test
|
170
155
|
- test/support/view_handlers.rb
|
171
|
-
- test/support/views/_info.erb
|
172
|
-
- test/support/views/haml_layout1.haml
|
173
|
-
- test/support/views/haml_with_layout.haml
|
174
|
-
- test/support/views/layout1.erb
|
175
|
-
- test/support/views/layout2.erb
|
176
|
-
- test/support/views/layout3.erb
|
177
|
-
- test/support/views/show.erb
|
178
|
-
- test/support/views/show.html.erb
|
179
|
-
- test/support/views/show.json.erb
|
180
|
-
- test/support/views/show_json.erb
|
181
|
-
- test/support/views/some.html.file.other
|
182
|
-
- test/support/views/some_file.engine
|
183
|
-
- test/support/views/some_no_engine_extension
|
184
|
-
- test/support/views/with_layout.erb
|
185
156
|
- test/system/rack_tests.rb
|
186
157
|
- test/unit/cgi_tests.rb
|
187
158
|
- test/unit/deas_runner_tests.rb
|
@@ -200,7 +171,6 @@ files:
|
|
200
171
|
- test/unit/sinatra_runner_tests.rb
|
201
172
|
- test/unit/template_engine_tests.rb
|
202
173
|
- test/unit/template_source_tests.rb
|
203
|
-
- test/unit/template_tests.rb
|
204
174
|
- test/unit/test_runner_tests.rb
|
205
175
|
- test/unit/url_tests.rb
|
206
176
|
- test/unit/view_handler_tests.rb
|
@@ -250,20 +220,6 @@ test_files:
|
|
250
220
|
- test/support/test_layout2.test
|
251
221
|
- test/support/test_template.test
|
252
222
|
- test/support/view_handlers.rb
|
253
|
-
- test/support/views/_info.erb
|
254
|
-
- test/support/views/haml_layout1.haml
|
255
|
-
- test/support/views/haml_with_layout.haml
|
256
|
-
- test/support/views/layout1.erb
|
257
|
-
- test/support/views/layout2.erb
|
258
|
-
- test/support/views/layout3.erb
|
259
|
-
- test/support/views/show.erb
|
260
|
-
- test/support/views/show.html.erb
|
261
|
-
- test/support/views/show.json.erb
|
262
|
-
- test/support/views/show_json.erb
|
263
|
-
- test/support/views/some.html.file.other
|
264
|
-
- test/support/views/some_file.engine
|
265
|
-
- test/support/views/some_no_engine_extension
|
266
|
-
- test/support/views/with_layout.erb
|
267
223
|
- test/system/rack_tests.rb
|
268
224
|
- test/unit/cgi_tests.rb
|
269
225
|
- test/unit/deas_runner_tests.rb
|
@@ -282,7 +238,6 @@ test_files:
|
|
282
238
|
- test/unit/sinatra_runner_tests.rb
|
283
239
|
- test/unit/template_engine_tests.rb
|
284
240
|
- test/unit/template_source_tests.rb
|
285
|
-
- test/unit/template_tests.rb
|
286
241
|
- test/unit/test_runner_tests.rb
|
287
242
|
- test/unit/url_tests.rb
|
288
243
|
- test/unit/view_handler_tests.rb
|
data/lib/deas/template.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'rack'
|
2
|
-
|
3
|
-
module Deas
|
4
|
-
|
5
|
-
class Template
|
6
|
-
|
7
|
-
attr_reader :name, :options
|
8
|
-
|
9
|
-
def initialize(sinatra_call, name, options = nil)
|
10
|
-
@sinatra_call, @name, @options = sinatra_call, name.to_sym, (options || {})
|
11
|
-
@options[:scope] = @sinatra_call.settings.deas_template_scope.new(@sinatra_call)
|
12
|
-
|
13
|
-
(@options.delete(:layout) || @options.delete(:layouts) || []).tap do |l|
|
14
|
-
@layouts = l.compact.map(&:to_sym)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def engine(template_name)
|
19
|
-
return 'erb' if @sinatra_call.settings.views.nil?
|
20
|
-
|
21
|
-
views_path = Pathname.new(@options[:views] || @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
|
-
|
26
|
-
# builds render-blocks like:
|
27
|
-
#
|
28
|
-
# erb :main_layout do
|
29
|
-
# erb :second_layout do
|
30
|
-
# erb :user_index
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
|
34
|
-
def render(&block)
|
35
|
-
template_names = [ @layouts, @name ].flatten.reverse
|
36
|
-
top_render_proc = template_names.inject(block) do |render_proc, name|
|
37
|
-
proc{ @sinatra_call.send(engine(name), name, @options.dup, &render_proc) }
|
38
|
-
end
|
39
|
-
top_render_proc.call
|
40
|
-
end
|
41
|
-
|
42
|
-
class Scope
|
43
|
-
|
44
|
-
attr_reader :sinatra_call
|
45
|
-
|
46
|
-
def initialize(sinatra_call)
|
47
|
-
@sinatra_call = sinatra_call
|
48
|
-
end
|
49
|
-
|
50
|
-
def render(name, options = nil, &block)
|
51
|
-
Template.new(@sinatra_call, name, options || {}).render(&block)
|
52
|
-
end
|
53
|
-
|
54
|
-
def partial(name, locals = nil, &block)
|
55
|
-
Partial.new(@sinatra_call, name, locals || {}).render(&block)
|
56
|
-
end
|
57
|
-
|
58
|
-
def escape_html(html)
|
59
|
-
Rack::Utils.escape_html(html)
|
60
|
-
end
|
61
|
-
alias :h :escape_html
|
62
|
-
|
63
|
-
def escape_url(path)
|
64
|
-
Rack::Utils.escape_path(path)
|
65
|
-
end
|
66
|
-
alias :u :escape_url
|
67
|
-
|
68
|
-
def ==(other_scope)
|
69
|
-
self.sinatra_call == other_scope.sinatra_call
|
70
|
-
self.class.included_modules == other_scope.class.included_modules
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
class Partial < Template
|
76
|
-
|
77
|
-
def initialize(sinatra_call, name, locals = nil)
|
78
|
-
options = { :locals => (locals || {}) }
|
79
|
-
super sinatra_call, name, options
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Stuff: <%= info %>
|
@@ -1 +0,0 @@
|
|
1
|
-
%span= view.class.inspect
|
data/test/support/views/show.erb
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
With Layouts View: <%= view.class.inspect %>
|
data/test/unit/template_tests.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
require 'assert'
|
2
|
-
require 'deas/template'
|
3
|
-
|
4
|
-
require 'test/support/fake_sinatra_call'
|
5
|
-
|
6
|
-
class Deas::Template
|
7
|
-
|
8
|
-
class UnitTests < Assert::Context
|
9
|
-
desc "Deas::Template"
|
10
|
-
setup do
|
11
|
-
@fake_sinatra_call = FakeSinatraCall.new
|
12
|
-
@template = Deas::Template.new(@fake_sinatra_call, 'users/index')
|
13
|
-
end
|
14
|
-
subject{ @template }
|
15
|
-
|
16
|
-
should have_instance_methods :name, :options, :render, :engine
|
17
|
-
|
18
|
-
should "symbolize it's name" do
|
19
|
-
assert_equal :"users/index", subject.name
|
20
|
-
end
|
21
|
-
|
22
|
-
should "set it's scope option" do
|
23
|
-
assert_instance_of Deas::Template::Scope, subject.options[:scope]
|
24
|
-
end
|
25
|
-
|
26
|
-
should "know a named template's render engine" do
|
27
|
-
fake_sinatra_call = FakeSinatraCall.new(:views => TEST_SUPPORT_ROOT.join('views'))
|
28
|
-
|
29
|
-
views_exist = Deas::Template.new(fake_sinatra_call, 'whatever')
|
30
|
-
assert_equal 'erb', views_exist.engine('layout1')
|
31
|
-
assert_equal 'haml', views_exist.engine('haml_layout1')
|
32
|
-
assert_equal 'other', views_exist.engine('some.html.file')
|
33
|
-
assert_equal 'engine', views_exist.engine('some_file')
|
34
|
-
assert_equal 'erb', views_exist.engine('some_no_engine_extension')
|
35
|
-
assert_equal 'erb', views_exist.engine('does_not_exist')
|
36
|
-
|
37
|
-
views_no_exist = Deas::Template.new(fake_sinatra_call, 'whatever', {
|
38
|
-
:views => '/does/not/exist'
|
39
|
-
})
|
40
|
-
assert_equal 'erb', views_no_exist.engine('layout1')
|
41
|
-
assert_equal 'erb', views_no_exist.engine('haml_layout1')
|
42
|
-
assert_equal 'erb', views_no_exist.engine('some.html.file')
|
43
|
-
assert_equal 'erb', views_no_exist.engine('some_file')
|
44
|
-
assert_equal 'erb', views_no_exist.engine('some_no_engine_extension')
|
45
|
-
assert_equal 'erb', views_no_exist.engine('does_not_exist')
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
should "call the sinatra_call's `erb` method with #render" do
|
50
|
-
return_value = subject.render
|
51
|
-
|
52
|
-
assert_equal subject.name, return_value[0]
|
53
|
-
assert_equal subject.options, return_value[1]
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
class WithLayoutsTests < UnitTests
|
59
|
-
desc "with layouts"
|
60
|
-
setup do
|
61
|
-
@template = Deas::Template.new(@fake_sinatra_call, 'users/index', {
|
62
|
-
:layout => [ 'layouts/web', 'layouts/search' ]
|
63
|
-
})
|
64
|
-
end
|
65
|
-
|
66
|
-
should "call the engine's `erb` method for each layout" do
|
67
|
-
web_lay_render_args = subject.render
|
68
|
-
search_lay_render_args = web_lay_render_args.block_call_result
|
69
|
-
users_index_render_args = search_lay_render_args.block_call_result
|
70
|
-
|
71
|
-
assert_equal :"layouts/web", web_lay_render_args.template_name
|
72
|
-
assert_equal :"layouts/search", search_lay_render_args.template_name
|
73
|
-
assert_equal :"users/index", users_index_render_args.template_name
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
class ScopeTests < UnitTests
|
79
|
-
desc "Deas::Template::RenderScope"
|
80
|
-
setup do
|
81
|
-
@scope = Deas::Template::Scope.new(@fake_sinatra_call)
|
82
|
-
end
|
83
|
-
subject{ @scope }
|
84
|
-
|
85
|
-
should have_reader :sinatra_call
|
86
|
-
should have_imeths :render, :partial, :escape_html, :h, :escape_url, :u
|
87
|
-
|
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' })
|
93
|
-
|
94
|
-
assert_equal :my_template, render_args.template_name
|
95
|
-
assert_instance_of Deas::Template::Scope, render_args.opts[:scope]
|
96
|
-
|
97
|
-
exp_locals = { :something => true }
|
98
|
-
assert_equal exp_locals, render_args.opts[:locals]
|
99
|
-
|
100
|
-
assert_equal '#render called this proc', render_args.block_call_result
|
101
|
-
end
|
102
|
-
|
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' })
|
107
|
-
|
108
|
-
assert_equal :_part, render_args.template_name
|
109
|
-
assert_instance_of Deas::Template::Scope, render_args.opts[:scope]
|
110
|
-
|
111
|
-
exp_locals = { :something => true }
|
112
|
-
assert_equal exp_locals, render_args.opts[:locals]
|
113
|
-
|
114
|
-
assert_equal '#partial called this proc', render_args.block_call_result
|
115
|
-
end
|
116
|
-
|
117
|
-
should "escape html with #h or #escape_html" do
|
118
|
-
exp_val = "<strong></strong>"
|
119
|
-
assert_equal exp_val, subject.escape_html("<strong></strong>")
|
120
|
-
assert_equal exp_val, subject.h("<strong></strong>")
|
121
|
-
end
|
122
|
-
|
123
|
-
should "escape urls with #u or #escape_url" do
|
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")
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
class PartialTests < UnitTests
|
132
|
-
desc "Partial"
|
133
|
-
setup do
|
134
|
-
@partial = Deas::Template::Partial.new(@fake_sinatra_call, 'users/index/_listing', {
|
135
|
-
:user => 'Joe Test'
|
136
|
-
})
|
137
|
-
end
|
138
|
-
subject{ @partial }
|
139
|
-
|
140
|
-
should "be a kind of Deas::Template" do
|
141
|
-
assert_kind_of Deas::Template, subject
|
142
|
-
end
|
143
|
-
|
144
|
-
should "set it's locals option" do
|
145
|
-
assert_equal({ :user => 'Joe Test' }, subject.options[:locals])
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|