roger 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,46 +10,63 @@ module Roger
10
10
  @resolver = Roger::Resolver.new(@base)
11
11
  end
12
12
 
13
- def test_find_template_path
14
- assert_equal @resolver.find_template("formats/index.html"), @base + "formats/index.html"
15
-
16
- # This should not be found on it's own as it will be processed
17
- assert_equal @resolver.find_template("formats/markdown.md"), nil
13
+ def assert_find(exp, search)
14
+ exp = @base + exp unless exp.nil?
15
+ assert_equal exp, @resolver.find_template(search)
18
16
  end
19
17
 
20
18
  def test_find_template_index_path
21
- assert_equal @resolver.find_template("formats"), @base + "formats/index.html"
19
+ assert_find "formats/index.html", "formats"
22
20
  end
23
21
 
24
22
  def test_find_template_html_without_extension
25
- assert_equal @resolver.find_template("formats/index"), @base + "formats/index.html"
26
- assert_equal @resolver.find_template("formats/erb"), @base + "formats/erb.html.erb"
23
+ assert_find "formats/index.html", "formats/index"
24
+ assert_find "formats/erb.html.erb", "formats/erb"
27
25
  end
28
26
 
29
27
  def test_find_template_with_template_extension
30
- assert_equal @resolver.find_template("formats/markdown"), @base + "formats/markdown.md"
28
+ assert_find "formats/markdown.md", "formats/markdown"
31
29
  end
32
30
 
33
31
  def test_find_template_with_double_extensions
34
- assert_equal @resolver.find_template("formats/erb"), @base + "formats/erb.html.erb"
35
- assert_equal @resolver.find_template("formats/erb.html"), @base + "formats/erb.html.erb"
32
+ assert_find "formats/erb.html.erb", "formats/erb"
33
+ assert_find "formats/erb.html.erb", "formats/erb.html"
34
+ assert_find "formats/erb.html.erb", "formats/erb.html.erb"
35
+
36
+ assert_find "formats/markdown-erb.md.erb", "formats/markdown-erb"
37
+ assert_find "formats/markdown-erb.md.erb", "formats/markdown-erb.md"
38
+ assert_find "formats/markdown-erb.md.erb", "formats/markdown-erb.md.erb"
39
+ end
36
40
 
37
- assert_equal @resolver.find_template("formats/json.json"), @base + "formats/json.json.erb"
41
+ def test_not_find_template_with_non_matching_double_extension
42
+ assert_find "formats/json.json.erb", "formats/json.json"
43
+ assert_find nil, "formats/json.html"
44
+ end
45
+
46
+ def test_find_template_with_aliassed_extension
47
+ assert_find "formats/markdown-erb.md.erb", "formats/markdown-erb.html"
48
+ assert_find "formats/markdown.md", "formats/markdown.html"
49
+ end
50
+
51
+ def test_find_template_exact_match
52
+ assert_find "formats/index.html", "formats/index.html"
53
+ assert_find "formats/erb.html.erb", "formats/erb.html.erb"
38
54
  end
39
55
 
40
56
  def test_find_template_with_preferred_extension
41
57
  assert_equal(
42
- @resolver.find_template("formats/json", preferred_extension: "json"),
43
- @base + "formats/json.json.erb"
58
+ @resolver.find_template("formats/preferred", prefer: "html"),
59
+ @base + "formats/preferred.html.erb"
44
60
  )
45
- end
46
61
 
47
- def test_find_template_exact_match
48
- # TODO
62
+ assert_equal(
63
+ @resolver.find_template("formats/preferred", prefer: "json"),
64
+ @base + "formats/preferred.json.erb"
65
+ )
49
66
  end
50
67
 
51
68
  def test_path_to_url
52
- assert_equal @resolver.path_to_url(@base + "formats/erb.html.erb"), "/formats/erb.html.erb"
69
+ assert_equal "/formats/erb.html.erb", @resolver.path_to_url(@base + "formats/erb.html.erb")
53
70
  end
54
71
 
55
72
  def test_path_to_url_relative_to_relative_path
@@ -77,6 +94,10 @@ module Roger
77
94
  @resolver = Roger::Resolver.new([@base + "html", @base + "partials"])
78
95
  end
79
96
 
97
+ def assert_find(exp, search)
98
+ assert_equal @base + exp, @resolver.find_template(search)
99
+ end
100
+
80
101
  def test_add_load_path
81
102
  @resolver.load_paths << @base + "henk"
82
103
 
@@ -84,16 +105,16 @@ module Roger
84
105
  end
85
106
 
86
107
  def test_find_template_path
87
- assert_equal @resolver.find_template("formats/index"), @base + "html/formats/index.html"
88
- assert_equal @resolver.find_template("test/simple"), @base + "partials/test/simple.html.erb"
108
+ assert_find "html/formats/index.html", "formats/index"
109
+ assert_find "partials/test/simple.html.erb", "test/simple"
89
110
  end
90
111
 
91
112
  def test_find_template_path_ordered
92
- assert_equal @resolver.find_template("formats/erb"), @base + "html/formats/erb.html.erb"
113
+ assert_find "html/formats/erb.html.erb", "formats/erb"
93
114
 
94
115
  @resolver.load_paths.reverse!
95
116
 
96
- assert_equal @resolver.find_template("formats/erb"), @base + "partials/formats/erb.html.erb"
117
+ assert_find "partials/formats/erb.html.erb", "formats/erb"
97
118
  end
98
119
  end
99
120
  end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ # Generators register themself on the CLI module
3
+ require "test_helper"
4
+ require "./lib/roger/template.rb"
5
+
6
+ module Roger
7
+ # Roger template tests
8
+ class TemplateTest < ::Test::Unit::TestCase
9
+ def setup
10
+ @base = Pathname.new(File.dirname(__FILE__) + "/../../project")
11
+ @config = {
12
+ partials_path: @base + "partials",
13
+ layouts_path: @base + "layouts",
14
+ source_path: @base + "html/test.html.erb"
15
+ }
16
+ @template_path = @base + "html"
17
+ end
18
+
19
+ def test_render
20
+ template = Template.new("<%= 'test' %>", {}, source_path: "test.erb")
21
+ assert_equal "test", template.render
22
+ end
23
+
24
+ def test_render_with_block
25
+ template = Template.new("<%= yield %>", {}, source_path: "test.erb")
26
+ assert_equal "inner", template.render { "inner" }
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-24 00:00:00.000000000 Z
13
+ date: 2016-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  name: rack
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - ! '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.0.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ! '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.0.0
43
43
  - !ruby/object:Gem::Dependency
@@ -86,14 +86,14 @@ dependencies:
86
86
  name: redcarpet
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ! '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: 3.1.1
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ! '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: 3.1.1
99
99
  - !ruby/object:Gem::Dependency
@@ -244,12 +244,14 @@ files:
244
244
  - lib/roger/release/scm.rb
245
245
  - lib/roger/release/scm/fixed.rb
246
246
  - lib/roger/release/scm/git.rb
247
+ - lib/roger/renderer.rb
247
248
  - lib/roger/resolver.rb
248
249
  - lib/roger/rogerfile.rb
249
250
  - lib/roger/server.rb
250
251
  - lib/roger/template.rb
251
252
  - lib/roger/template/helpers/capture.rb
252
253
  - lib/roger/template/helpers/partial.rb
254
+ - lib/roger/template/helpers/rendering.rb
253
255
  - lib/roger/template/template_context.rb
254
256
  - lib/roger/test.rb
255
257
  - lib/roger/testing/mock_project.rb
@@ -265,14 +267,20 @@ files:
265
267
  - test/project/html/formats/erb.html.erb
266
268
  - test/project/html/formats/index.html
267
269
  - test/project/html/formats/json.json.erb
270
+ - test/project/html/formats/markdown-erb.md.erb
268
271
  - test/project/html/formats/markdown.md
272
+ - test/project/html/formats/preferred.html.erb
273
+ - test/project/html/formats/preferred.json.erb
269
274
  - test/project/html/front_matter/erb.html.erb
270
275
  - test/project/html/front_matter/markdown.md
271
276
  - test/project/html/layouts/content-for.html.erb
272
277
  - test/project/html/layouts/erb.html.erb
273
278
  - test/project/html/mockup/encoding.html
279
+ - test/project/html/partials/_local.html.erb
274
280
  - test/project/html/partials/erb.html.erb
275
281
  - test/project/html/partials/load_path.html.erb
282
+ - test/project/html/renderer/file.html.erb
283
+ - test/project/html/renderer/recursive.html.erb
276
284
  - test/project/html/static/non-relative.html.erb
277
285
  - test/project/html/static/relative.html.erb
278
286
  - test/project/layouts/test.html.erb
@@ -285,10 +293,13 @@ files:
285
293
  - test/project/lib/tests/succeed/succeed.rb
286
294
  - test/project/partials/formats/erb.html.erb
287
295
  - test/project/partials/partials-test.html.erb
296
+ - test/project/partials/test/_underscored.html.erb
297
+ - test/project/partials/test/deep_recursive.html.erb
288
298
  - test/project/partials/test/erb.html.erb
289
299
  - test/project/partials/test/front_matter.html.erb
290
300
  - test/project/partials/test/json.json.erb
291
301
  - test/project/partials/test/markdown.md
302
+ - test/project/partials/test/recursive.html.erb
292
303
  - test/project/partials/test/simple.html.erb
293
304
  - test/project/partials/test/yield.html.erb
294
305
  - test/project/partials2/partials2-test.html.erb
@@ -315,9 +326,13 @@ files:
315
326
  - test/unit/release/scm/fixed_test.rb
316
327
  - test/unit/release/scm/git_test.rb
317
328
  - test/unit/release_test.rb
329
+ - test/unit/renderer/renderer_base_test.rb
330
+ - test/unit/renderer/renderer_content_for_test.rb
331
+ - test/unit/renderer/renderer_helper_test.rb
332
+ - test/unit/renderer/renderer_partial_test.rb
318
333
  - test/unit/resolver_test.rb
319
334
  - test/unit/server_test.rb
320
- - test/unit/template_test.rb
335
+ - test/unit/template/template_base_test.rb
321
336
  - test/unit/test_helper.rb
322
337
  - test/unit/test_test.rb
323
338
  homepage: http://github.com/digitpaint/roger
@@ -331,17 +346,17 @@ require_paths:
331
346
  - lib
332
347
  required_ruby_version: !ruby/object:Gem::Requirement
333
348
  requirements:
334
- - - '>='
349
+ - - ! '>='
335
350
  - !ruby/object:Gem::Version
336
351
  version: '0'
337
352
  required_rubygems_version: !ruby/object:Gem::Requirement
338
353
  requirements:
339
- - - '>='
354
+ - - ! '>='
340
355
  - !ruby/object:Gem::Version
341
356
  version: '0'
342
357
  requirements: []
343
358
  rubyforge_project:
344
- rubygems_version: 2.2.2
359
+ rubygems_version: 2.4.8
345
360
  signing_key:
346
361
  specification_version: 4
347
362
  summary: Roger is a set of tools to create self-containing HTML mockups.
@@ -355,14 +370,20 @@ test_files:
355
370
  - test/project/html/formats/erb.html.erb
356
371
  - test/project/html/formats/index.html
357
372
  - test/project/html/formats/json.json.erb
373
+ - test/project/html/formats/markdown-erb.md.erb
358
374
  - test/project/html/formats/markdown.md
375
+ - test/project/html/formats/preferred.html.erb
376
+ - test/project/html/formats/preferred.json.erb
359
377
  - test/project/html/front_matter/erb.html.erb
360
378
  - test/project/html/front_matter/markdown.md
361
379
  - test/project/html/layouts/content-for.html.erb
362
380
  - test/project/html/layouts/erb.html.erb
363
381
  - test/project/html/mockup/encoding.html
382
+ - test/project/html/partials/_local.html.erb
364
383
  - test/project/html/partials/erb.html.erb
365
384
  - test/project/html/partials/load_path.html.erb
385
+ - test/project/html/renderer/file.html.erb
386
+ - test/project/html/renderer/recursive.html.erb
366
387
  - test/project/html/static/non-relative.html.erb
367
388
  - test/project/html/static/relative.html.erb
368
389
  - test/project/layouts/test.html.erb
@@ -375,10 +396,13 @@ test_files:
375
396
  - test/project/lib/tests/succeed/succeed.rb
376
397
  - test/project/partials/formats/erb.html.erb
377
398
  - test/project/partials/partials-test.html.erb
399
+ - test/project/partials/test/_underscored.html.erb
400
+ - test/project/partials/test/deep_recursive.html.erb
378
401
  - test/project/partials/test/erb.html.erb
379
402
  - test/project/partials/test/front_matter.html.erb
380
403
  - test/project/partials/test/json.json.erb
381
404
  - test/project/partials/test/markdown.md
405
+ - test/project/partials/test/recursive.html.erb
382
406
  - test/project/partials/test/simple.html.erb
383
407
  - test/project/partials/test/yield.html.erb
384
408
  - test/project/partials2/partials2-test.html.erb
@@ -405,8 +429,12 @@ test_files:
405
429
  - test/unit/release/scm/fixed_test.rb
406
430
  - test/unit/release/scm/git_test.rb
407
431
  - test/unit/release_test.rb
432
+ - test/unit/renderer/renderer_base_test.rb
433
+ - test/unit/renderer/renderer_content_for_test.rb
434
+ - test/unit/renderer/renderer_helper_test.rb
435
+ - test/unit/renderer/renderer_partial_test.rb
408
436
  - test/unit/resolver_test.rb
409
437
  - test/unit/server_test.rb
410
- - test/unit/template_test.rb
438
+ - test/unit/template/template_base_test.rb
411
439
  - test/unit/test_helper.rb
412
440
  - test/unit/test_test.rb
@@ -1,208 +0,0 @@
1
- # encoding: UTF-8
2
- # Generators register themself on the CLI module
3
- require "test_helper"
4
- require "./lib/roger/template.rb"
5
-
6
- module Roger
7
- # A simple template helper to use for testing
8
- module TemplateHelper
9
- def a
10
- "a"
11
- end
12
-
13
- def from_env(key)
14
- env[key]
15
- end
16
- end
17
-
18
- # Roger template tests
19
- class TemplateTest < ::Test::Unit::TestCase
20
- def setup
21
- @base = Pathname.new(File.dirname(__FILE__) + "/../project")
22
- @config = {
23
- partials_path: @base + "partials",
24
- layouts_path: @base + "layouts",
25
- source_path: @base + "html/test.html.erb"
26
- }
27
- @template_path = @base + "html"
28
- end
29
-
30
- def test_encoding
31
- end
32
-
33
- # Extension
34
- def test_source_extension
35
- mime_types = {
36
- "html" => "html",
37
- "html.erb" => "html.erb",
38
- "css.erb" => "css.erb",
39
- "json.erb" => "json.erb",
40
- "sjon.json.erb" => "json.erb",
41
- "js.erb" => "js.erb"
42
- }
43
-
44
- mime_types.each do |ext, ext_out|
45
- assert_equal(
46
- ext_out,
47
- Template.new("", @config.update(source_path: @base + "html/file.#{ext}")).source_extension
48
- )
49
- end
50
- end
51
-
52
- def test_target_extension
53
- mime_types = {
54
- "html" => "html",
55
- "html.erb" => "html",
56
- "css.erb" => "css",
57
- "json.erb" => "json",
58
- "js.erb" => "js"
59
- }
60
-
61
- mime_types.each do |ext, ext_out|
62
- assert_equal(
63
- ext_out,
64
- Template.new("", @config.update(source_path: @base + "html/file.#{ext}")).target_extension
65
- )
66
- end
67
- end
68
-
69
- # Mime type
70
- def test_target_mime_type
71
- mime_types = {
72
- "html" => "text/html",
73
- "html.erb" => "text/html",
74
- "css.erb" => "text/css",
75
- "json.erb" => "application/json"
76
- }
77
-
78
- mime_types.each do |ext, mime|
79
- assert_equal(
80
- mime,
81
- Template.new("", @config.update(source_path: @base + "html/file.#{ext}")).target_mime_type
82
- )
83
- end
84
- end
85
-
86
- # Front-matter
87
-
88
- def test_front_matter_partial_access
89
- template = Template.new("---\ntest: yay!\n---\n<%= partial 'test/front_matter' %>", @config)
90
- assert_equal template.render, "yay!"
91
- end
92
-
93
- # Partials
94
-
95
- def test_encoding_in_partials
96
- end
97
-
98
- def test_partial
99
- template = Template.new("<%= partial 'test/simple' %>", @config)
100
- assert_equal template.render, "ERB"
101
-
102
- template = Template.new(
103
- "<%= partial 'test/simple.html' %>",
104
- @config.update(source_path: @base + "html/test.erb")
105
- )
106
- assert_equal template.render, "ERB"
107
- end
108
-
109
- def test_partial_with_double_template_extensions
110
- template = Template.new(
111
- "<%= partial 'test/json.json' %>",
112
- @config.update(source_path: @base + "html/test.erb")
113
- )
114
- assert_equal template.render, "{ key: value }"
115
- end
116
-
117
- def test_partial_with_preferred_extension
118
- template = Template.new("<%= partial 'test/json' %>", @config)
119
- assert_raise(ArgumentError) do
120
- template.render
121
- end
122
- template = Template.new(
123
- "<%= partial 'test/json' %>",
124
- @config.update(source_path: @base + "html/test.json.erb")
125
- )
126
- assert_equal template.render, "{ key: value }"
127
- end
128
-
129
- def test_partial_with_block
130
- template = Template.new("<% partial 'test/yield' do %>CONTENT<% end %>", @config)
131
- assert_equal template.render, "B-CONTENT-A"
132
-
133
- template = Template.new("<% partial 'test/yield' do %><%= 'CONTENT' %><% end %>", @config)
134
- assert_equal template.render, "B-CONTENT-A"
135
- end
136
-
137
- def test_partial_with_block_without_yield
138
- template = Template.new("<% partial 'test/simple' do %>CONTENT<% end %>", @config)
139
- assert_equal template.render, "ERB"
140
- end
141
-
142
- # Content for parts
143
-
144
- def test_content_for_not_returning_in_template
145
- content_for_block = 'B<% content_for :one do %><%= "one" %><% end %>A'
146
-
147
- template = Template.new(
148
- content_for_block,
149
- @config.update(source_path: @base + "html/test.erb")
150
- )
151
- assert_equal template.render, "BA"
152
- end
153
-
154
- def test_content_for_yield_in_layout
155
- content_for_block = "---\nlayout: \"yield\"\n---\n"
156
- content_for_block << "B<% content_for :one do %><%= \"one\" %><% end %>A"
157
-
158
- template = Template.new(content_for_block, @config)
159
- assert_equal template.render, "BAone"
160
- end
161
-
162
- def test_content_for_yield_in_layout_without_content_for
163
- content_for_block = "---\nlayout: \"yield\"\n---\nBA"
164
-
165
- template = Template.new(content_for_block, @config)
166
- assert_equal template.render, "BA"
167
- end
168
-
169
- def test_content_for_yield_with_partial_with_block
170
- template_string = "---\nlayout: \"yield\"\n---\nB"
171
- template_string << "<% content_for :one do %>"
172
- template_string << "<% partial 'test/yield' do %>CONTENT<% end %>"
173
- template_string << "<% end %>A"
174
-
175
- template = Template.new(template_string, @config)
176
- assert_equal template.render, "BAB-CONTENT-A"
177
- end
178
-
179
- # Environment
180
-
181
- def test_template_env
182
- template = Template.new("<%= env[:test] %>", @config)
183
- assert_equal template.render(test: "test"), "test"
184
- end
185
-
186
- # Helpers
187
-
188
- def test_register_helper
189
- Roger::Template.helper TemplateHelper
190
-
191
- assert Roger::Template.helpers.include?(TemplateHelper)
192
- end
193
-
194
- def test_helper_works
195
- Roger::Template.helper TemplateHelper
196
-
197
- template = Roger::Template.new("<%= a %>", @config)
198
- assert_equal template.render, "a"
199
- end
200
-
201
- def test_helper_has_access_to_env
202
- Roger::Template.helper TemplateHelper
203
-
204
- template = Roger::Template.new("<%= from_env(:test) %>", @config)
205
- assert_equal template.render(test: "test"), "test"
206
- end
207
- end
208
- end