deas-erubis 0.5.1 → 0.5.2
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.
- checksums.yaml +4 -4
- data/deas-erubis.gemspec +1 -1
- data/lib/deas-erubis.rb +1 -0
- data/lib/deas-erubis/source.rb +12 -5
- data/lib/deas-erubis/version.rb +1 -1
- data/test/support/templates/{_partial.erb → _partial1.erb} +0 -0
- data/test/support/templates/view.aaa +6 -0
- data/test/support/templates/with_capture_partial.erb +1 -1
- data/test/support/templates/with_partial.erb +1 -1
- data/test/system/template_engine_tests.rb +5 -2
- data/test/unit/source_tests.rb +34 -1
- data/test/unit/template_engine_tests.rb +8 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: 05e87846e97f40eef052aca4ee79b73b030b94f6
|
4
|
+
data.tar.gz: e10a30275cb69eb9c806632f6c4f14a1eff92cd8
|
5
5
|
SHA512:
|
6
|
-
|
7
|
-
|
6
|
+
metadata.gz: 3126c4599310a15840838be33c4396349b5712fbaecbf6151ff2a81b300d5d1f677c3f873b50f5bb4c84c5f489ca0680d54b01c147acdd065052b3c9a4e578bb
|
7
|
+
data.tar.gz: 659d77c67276550f8942c06cfe7f6d6180f669fcaba94e635e4067f5f832813daf62eef516490d6a9a91b6b33fe5aafe0b8acd9c733127f5629344b437fe373a
|
data/deas-erubis.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
|
21
21
|
gem.add_development_dependency("assert", ["~> 2.15.1"])
|
22
22
|
|
23
|
-
gem.add_dependency("deas", ["~> 0.
|
23
|
+
gem.add_dependency("deas", ["~> 0.40.0"])
|
24
24
|
gem.add_dependency("erubis")
|
25
25
|
gem.add_dependency("much-plugin", ["~> 0.1.0"])
|
26
26
|
|
data/lib/deas-erubis.rb
CHANGED
data/lib/deas-erubis/source.rb
CHANGED
@@ -10,10 +10,11 @@ module Deas::Erubis
|
|
10
10
|
BUFVAR_NAME = '@_erb_buf'.freeze
|
11
11
|
DEFAULT_ERUBY = ::Erubis::Eruby
|
12
12
|
|
13
|
-
attr_reader :root, :eruby_class, :cache, :context_class
|
13
|
+
attr_reader :root, :ext, :eruby_class, :cache, :context_class
|
14
14
|
|
15
15
|
def initialize(root, opts)
|
16
16
|
@root = Pathname.new(root.to_s)
|
17
|
+
@ext = opts[:ext] ? ".#{opts[:ext]}" : nil
|
17
18
|
@eruby_class = opts[:eruby] || DEFAULT_ERUBY
|
18
19
|
@cache = opts[:cache] ? Hash.new : NullCache.new
|
19
20
|
@context_class = build_context_class(opts)
|
@@ -46,14 +47,20 @@ module Deas::Erubis
|
|
46
47
|
|
47
48
|
def load(template_name)
|
48
49
|
@cache[template_name] ||= begin
|
49
|
-
filename = source_file_path(template_name).
|
50
|
-
|
50
|
+
if (filename = source_file_path(template_name)).nil?
|
51
|
+
template_desc = "a template file named #{template_name.inspect}"
|
52
|
+
if !@ext.nil?
|
53
|
+
template_desc += " that ends in #{@ext.inspect}"
|
54
|
+
end
|
55
|
+
raise ArgumentError, "#{template_desc} does not exist"
|
56
|
+
end
|
57
|
+
content = File.send(File.respond_to?(:binread) ? :binread : :read, filename.to_s)
|
51
58
|
template(filename, content)
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
|
-
def source_file_path(
|
56
|
-
Dir.glob(self.root.join("#{
|
62
|
+
def source_file_path(name)
|
63
|
+
Dir.glob(self.root.join(name.end_with?(@ext) ? name : "#{name}*#{@ext}")).first
|
57
64
|
end
|
58
65
|
|
59
66
|
def build_context_class(opts)
|
data/lib/deas-erubis/version.rb
CHANGED
File without changes
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<% capture_partial '_yield_partial', 'local1' => local1 do %>
|
3
3
|
<span>some content</span>
|
4
4
|
<% end %>
|
5
|
-
<% capture_partial '
|
5
|
+
<% capture_partial '_partial1', 'local1' => local1 %>
|
6
6
|
<% capture_partial '_partial_no_locals' %>
|
7
7
|
<% source_capture_partial @default_source, '_partial_no_locals' %>
|
8
8
|
</div>
|
@@ -15,7 +15,10 @@ class Deas::Erubis::TemplateEngine
|
|
15
15
|
@locals = { 'local1' => Factory.string }
|
16
16
|
@content = Proc.new{ "<span>some content</span>" }
|
17
17
|
|
18
|
-
@engine = Deas::Erubis::TemplateEngine.new(
|
18
|
+
@engine = Deas::Erubis::TemplateEngine.new({
|
19
|
+
'source_path' => TEMPLATE_ROOT,
|
20
|
+
'ext' => 'erb'
|
21
|
+
})
|
19
22
|
end
|
20
23
|
subject{ @engine }
|
21
24
|
|
@@ -31,7 +34,7 @@ class Deas::Erubis::TemplateEngine
|
|
31
34
|
|
32
35
|
should "render partial templates" do
|
33
36
|
exp = Factory.partial_erb_rendered(subject, @locals)
|
34
|
-
assert_equal exp, subject.partial('
|
37
|
+
assert_equal exp, subject.partial('_partial1', @locals)
|
35
38
|
end
|
36
39
|
|
37
40
|
should "render partial templates yielding to given content blocks" do
|
data/test/unit/source_tests.rb
CHANGED
@@ -30,13 +30,20 @@ class Deas::Erubis::Source
|
|
30
30
|
end
|
31
31
|
subject{ @source }
|
32
32
|
|
33
|
-
should have_readers :root, :eruby_class, :cache, :context_class
|
33
|
+
should have_readers :root, :ext, :eruby_class, :cache, :context_class
|
34
34
|
should have_imeths :render, :compile, :template
|
35
35
|
|
36
36
|
should "know its root" do
|
37
37
|
assert_equal @root, subject.root.to_s
|
38
38
|
end
|
39
39
|
|
40
|
+
should "know its extension for looking up source files" do
|
41
|
+
assert_nil subject.ext
|
42
|
+
|
43
|
+
source = @source_class.new(@root, :ext => 'erb')
|
44
|
+
assert_equal '.erb', source.ext
|
45
|
+
end
|
46
|
+
|
40
47
|
should "default its eruby class" do
|
41
48
|
assert_equal Deas::Erubis::Source::DEFAULT_ERUBY, subject.eruby_class
|
42
49
|
end
|
@@ -145,6 +152,32 @@ class Deas::Erubis::Source
|
|
145
152
|
assert_equal default_source, context_class.default_source
|
146
153
|
end
|
147
154
|
|
155
|
+
should "only render templates with the matching ext if one is specified" do
|
156
|
+
source = @source_class.new(@root, :ext => 'erb')
|
157
|
+
file_path = Factory.template_file('basic.html.erb')
|
158
|
+
exp = Factory.basic_erb_rendered(@file_locals)
|
159
|
+
['basic', 'basic.html', 'basic.html.erb'].each do |name|
|
160
|
+
assert_equal exp, source.render(name, @file_locals)
|
161
|
+
end
|
162
|
+
|
163
|
+
source = @source_class.new(@root, :ext => 'erubis')
|
164
|
+
file_path = Factory.template_file('basic_alt.erubis')
|
165
|
+
exp = Factory.basic_erb_rendered(@file_locals)
|
166
|
+
['basic', 'basic_alt', 'basic_alt.erubis'].each do |name|
|
167
|
+
assert_equal exp, source.render(name, @file_locals)
|
168
|
+
end
|
169
|
+
|
170
|
+
source = @source_class.new(@root, :ext => 'erb')
|
171
|
+
['basic_alt', 'basic_alt.erubis'].each do |name|
|
172
|
+
assert_raises(ArgumentError){ source.render(name, @file_locals) }
|
173
|
+
end
|
174
|
+
|
175
|
+
source = @source_class.new(@root, :ext => 'html')
|
176
|
+
['basic', 'basic.html', 'basic.html.erb'].each do |name|
|
177
|
+
assert_raises(ArgumentError){ source.render(name, @file_locals) }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
148
181
|
end
|
149
182
|
|
150
183
|
class RenderCacheTests < RenderTests
|
@@ -10,7 +10,8 @@ class Deas::Erubis::TemplateEngine
|
|
10
10
|
desc "Deas::Erubis::TemplateEngine"
|
11
11
|
setup do
|
12
12
|
@engine = Deas::Erubis::TemplateEngine.new({
|
13
|
-
'source_path' => TEST_SUPPORT_PATH
|
13
|
+
'source_path' => TEST_SUPPORT_PATH,
|
14
|
+
'ext' => 'erb'
|
14
15
|
})
|
15
16
|
end
|
16
17
|
subject{ @engine }
|
@@ -39,6 +40,12 @@ class Deas::Erubis::TemplateEngine
|
|
39
40
|
assert_kind_of Hash, engine.erb_source.cache
|
40
41
|
end
|
41
42
|
|
43
|
+
should "pass any given ext option to its source" do
|
44
|
+
ext = Factory.string
|
45
|
+
engine = Deas::Erubis::TemplateEngine.new('ext' => ext)
|
46
|
+
assert_equal ".#{ext}", engine.erb_source.ext
|
47
|
+
end
|
48
|
+
|
42
49
|
should "pass any given deas template source to its source" do
|
43
50
|
default_source = 'a-default-source'
|
44
51
|
source_opts = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas-erubis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2016-04-
|
13
|
+
date: 2016-04-11 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.40.0
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id002
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -76,12 +76,13 @@ files:
|
|
76
76
|
- log/.gitkeep
|
77
77
|
- test/helper.rb
|
78
78
|
- test/support/factory.rb
|
79
|
-
- test/support/templates/
|
79
|
+
- test/support/templates/_partial1.erb
|
80
80
|
- test/support/templates/_partial_no_locals.erb
|
81
81
|
- test/support/templates/_yield_partial.erb
|
82
82
|
- test/support/templates/basic.html.erb
|
83
83
|
- test/support/templates/basic_alt.erubis
|
84
84
|
- test/support/templates/compile.erb
|
85
|
+
- test/support/templates/view.aaa
|
85
86
|
- test/support/templates/view.erb
|
86
87
|
- test/support/templates/with_capture_partial.erb
|
87
88
|
- test/support/templates/with_partial.erb
|
@@ -118,12 +119,13 @@ summary: Deas template engine for rendering erb templates using Erubis
|
|
118
119
|
test_files:
|
119
120
|
- test/helper.rb
|
120
121
|
- test/support/factory.rb
|
121
|
-
- test/support/templates/
|
122
|
+
- test/support/templates/_partial1.erb
|
122
123
|
- test/support/templates/_partial_no_locals.erb
|
123
124
|
- test/support/templates/_yield_partial.erb
|
124
125
|
- test/support/templates/basic.html.erb
|
125
126
|
- test/support/templates/basic_alt.erubis
|
126
127
|
- test/support/templates/compile.erb
|
128
|
+
- test/support/templates/view.aaa
|
127
129
|
- test/support/templates/view.erb
|
128
130
|
- test/support/templates/with_capture_partial.erb
|
129
131
|
- test/support/templates/with_partial.erb
|