deas-erubis 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ data.tar.gz: 14a40f9a2156fb042ae7aefccadeb3e33f62c1b2
4
+ metadata.gz: 32bdec58016585f5f676dea9100fa80a30a236c5
5
+ SHA512:
6
+ data.tar.gz: c03d7b4af3b4cfa33b44699bc976929274e35f537b4ac9d6fbdc0653c1022345db4d6ec019f9c53604f4e21ca79a52a9322068a870647aa4fe96605f09ff09b3
7
+ metadata.gz: 6943df339e7905f07f7bbe17356c4f7b5f6a3af65ad42d4754f894a5279f1a201ad09d6e936302d0106dcdcd28355ecbe63b4c8933a5060962dd370e9c2c0dc5
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake', "~> 10.4.0"
6
- gem 'pry', "~> 0.9.0"
5
+ gem 'pry', "~> 0.9.0"
data/deas-erubis.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Deas::Erubis::VERSION
9
9
  gem.authors = ["Kelly Redding", "Collin Redding"]
10
10
  gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
- gem.description = %q{Deas template engine for rendering erb templates using Erubis}
12
11
  gem.summary = %q{Deas template engine for rendering erb templates using Erubis}
12
+ gem.description = %q{Deas template engine for rendering erb templates using Erubis}
13
13
  gem.homepage = "http://github.com/redding/deas-erubis"
14
14
  gem.license = 'MIT'
15
15
 
@@ -18,10 +18,10 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency("assert", ["~> 2.15"])
21
+ gem.add_development_dependency("assert", ["~> 2.15.1"])
22
22
 
23
- gem.add_dependency("deas", ["~> 0.39"])
23
+ gem.add_dependency("deas", ["~> 0.39.2"])
24
24
  gem.add_dependency("erubis")
25
- gem.add_dependency("much-plugin", ["~> 0.1"])
25
+ gem.add_dependency("much-plugin", ["~> 0.1.0"])
26
26
 
27
27
  end
data/lib/deas-erubis.rb CHANGED
@@ -39,6 +39,8 @@ module Deas::Erubis
39
39
  self.erb_source.render(template_name, locals, &content)
40
40
  end
41
41
 
42
+ # this is used when chaining engines where another engine initially loads the
43
+ # template file
42
44
  def compile(template_name, compiled_content)
43
45
  self.erb_source.compile(template_name, compiled_content)
44
46
  end
@@ -7,7 +7,6 @@ module Deas::Erubis
7
7
 
8
8
  class Source
9
9
 
10
- EXT = '.erb'.freeze
11
10
  BUFVAR_NAME = '@_erb_buf'.freeze
12
11
  DEFAULT_ERUBY = ::Erubis::Eruby
13
12
 
@@ -22,12 +21,12 @@ module Deas::Erubis
22
21
  @default_source = opts[:default_source]
23
22
  end
24
23
 
25
- def render(file_name, locals, &content)
26
- load(file_name).evaluate(@context_class.new(@default_source, locals), &content)
24
+ def render(template_name, locals, &content)
25
+ load(template_name).evaluate(@context_class.new(@default_source, locals), &content)
27
26
  end
28
27
 
29
- def compile(filename, content)
30
- template(filename, content).evaluate(@context_class.new(@default_source, {}))
28
+ def compile(template_name, content)
29
+ template(template_name, content).evaluate(@context_class.new(@default_source, {}))
31
30
  end
32
31
 
33
32
  def template(filename, content)
@@ -45,16 +44,16 @@ module Deas::Erubis
45
44
 
46
45
  private
47
46
 
48
- def load(file_name)
49
- @cache[file_name] ||= begin
50
- filename = source_file_path(file_name).to_s
47
+ def load(template_name)
48
+ @cache[template_name] ||= begin
49
+ filename = source_file_path(template_name).to_s
51
50
  content = File.send(File.respond_to?(:binread) ? :binread : :read, filename)
52
51
  template(filename, content)
53
52
  end
54
53
  end
55
54
 
56
- def source_file_path(file_name)
57
- self.root.join("#{file_name}#{EXT}").to_s
55
+ def source_file_path(template_name)
56
+ Dir.glob(self.root.join("#{template_name}*")).first
58
57
  end
59
58
 
60
59
  def build_context_class(opts)
@@ -92,9 +91,9 @@ module Deas::Erubis
92
91
  end
93
92
 
94
93
  class NullCache
95
- def [](file_name); end
96
- def []=(file_name, value); end
97
- def keys; []; end
94
+ def [](template_name); end
95
+ def []=(template_name, value); end
96
+ def keys; []; end
98
97
  end
99
98
 
100
99
  end
@@ -1,4 +1,4 @@
1
1
  module Deas; end
2
2
  module Deas::Erubis
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
@@ -0,0 +1,2 @@
1
+ <h1>name: <%= name %></h1>
2
+ <h2>local1: <%= local1 %></h2>
@@ -10,9 +10,9 @@ class Deas::Erubis::TemplateEngine
10
10
  setup do
11
11
  @view = OpenStruct.new({
12
12
  :identifier => Factory.integer,
13
- :name => Factory.string
13
+ :name => Factory.string
14
14
  })
15
- @locals = { 'local1' => Factory.string }
15
+ @locals = { 'local1' => Factory.string }
16
16
  @content = Proc.new{ "<span>some content</span>" }
17
17
 
18
18
  @engine = Deas::Erubis::TemplateEngine.new('source_path' => TEMPLATE_ROOT)
@@ -40,12 +40,12 @@ class Deas::Erubis::TemplateEngine
40
40
  end
41
41
 
42
42
  should "compile raw template markup" do
43
- file_name = 'compile'
44
- file_path = TEMPLATE_ROOT.join("#{file_name}#{Deas::Erubis::Source::EXT}").to_s
45
- file_content = File.read(file_path)
43
+ template_name = 'compile'
44
+ file_path = TEMPLATE_ROOT.join("#{template_name}.erb").to_s
45
+ file_content = File.read(file_path)
46
46
 
47
47
  exp = Factory.compile_erb_rendered(subject)
48
- assert_equal exp, subject.compile(file_name, file_content)
48
+ assert_equal exp, subject.compile(template_name, file_content)
49
49
  end
50
50
 
51
51
  end
@@ -12,10 +12,6 @@ class Deas::Erubis::Source
12
12
  end
13
13
  subject{ @source_class }
14
14
 
15
- should "know its extension" do
16
- assert_equal '.erb', subject::EXT
17
- end
18
-
19
15
  should "know the bufvar name to use" do
20
16
  assert_equal '@_erb_buf', subject::BUFVAR_NAME
21
17
  end
@@ -51,15 +47,6 @@ class Deas::Erubis::Source
51
47
  assert_equal eruby, source.eruby_class
52
48
  end
53
49
 
54
- should "build template objects for template files" do
55
- filename = 'basic'
56
- template = subject.template(filename, Factory.string)
57
-
58
- assert_equal filename, template.filename
59
- assert_equal subject.eruby_class, template.eruby_class
60
- assert_equal Deas::Erubis::Source::BUFVAR_NAME, template.eruby_bufvar
61
- end
62
-
63
50
  should "not cache templates by default" do
64
51
  assert_kind_of NullCache, subject.cache
65
52
  end
@@ -120,21 +107,30 @@ class Deas::Erubis::Source
120
107
  assert_equal default_source, context.instance_variable_get('@default_source')
121
108
  end
122
109
 
110
+ should "build template objects for template files" do
111
+ filename = 'basic'
112
+ template = subject.template(filename, Factory.string)
113
+
114
+ assert_equal filename, template.filename
115
+ assert_equal subject.eruby_class, template.eruby_class
116
+ assert_equal Deas::Erubis::Source::BUFVAR_NAME, template.eruby_bufvar
117
+ end
118
+
123
119
  end
124
120
 
125
121
  class RenderTests < InitTests
126
122
  desc "`render` method"
127
123
  setup do
128
- @file_name = "basic"
124
+ @template_name = ['basic', 'basic_alt'].choice
129
125
  @file_locals = {
130
126
  'name' => Factory.string,
131
127
  'local1' => Factory.integer
132
128
  }
133
129
  end
134
130
 
135
- should "render a template for the given file name and return its data" do
131
+ should "render a template for the given template name and return its data" do
136
132
  exp = Factory.basic_erb_rendered(@file_locals)
137
- assert_equal exp, subject.render(@file_name, @file_locals)
133
+ assert_equal exp, subject.render(@template_name, @file_locals)
138
134
  end
139
135
 
140
136
  should "pass its default source to its context class" do
@@ -144,7 +140,7 @@ class Deas::Erubis::Source
144
140
  Assert.stub(source.context_class, :new) do |s, l|
145
141
  context_class = ContextClassSpy.new(s, l)
146
142
  end
147
- source.render(@file_name, @file_locals)
143
+ source.render(@template_name, @file_locals)
148
144
 
149
145
  assert_equal default_source, context_class.default_source
150
146
  end
@@ -157,12 +153,12 @@ class Deas::Erubis::Source
157
153
  @source = @source_class.new(@root, :cache => true)
158
154
  end
159
155
 
160
- should "cache templates by their file name" do
156
+ should "cache templates by their template name" do
161
157
  exp = Factory.basic_erb_rendered(@file_locals)
162
- assert_equal exp, @source.render(@file_name, @file_locals)
158
+ assert_equal exp, @source.render(@template_name, @file_locals)
163
159
 
164
- assert_equal [@file_name], @source.cache.keys
165
- assert_kind_of Template, @source.cache[@file_name]
160
+ assert_equal [@template_name], @source.cache.keys
161
+ assert_kind_of Template, @source.cache[@template_name]
166
162
  end
167
163
 
168
164
  end
@@ -175,7 +171,7 @@ class Deas::Erubis::Source
175
171
 
176
172
  should "not cache templates" do
177
173
  exp = Factory.basic_erb_rendered(@file_locals)
178
- assert_equal exp, @source.render(@file_name, @file_locals)
174
+ assert_equal exp, @source.render(@template_name, @file_locals)
179
175
 
180
176
  assert_equal [], @source.cache.keys
181
177
  end
@@ -185,13 +181,13 @@ class Deas::Erubis::Source
185
181
  class RenderContentTests < RenderTests
186
182
  desc "when yielding to a given content block"
187
183
  setup do
188
- @file_name = "yield"
184
+ @template_name = "yield"
189
185
  @content = Proc.new{ "<span>some content</span>" }
190
186
  end
191
187
 
192
- should "render the template for the given file name and return its data" do
188
+ should "render the template for the given template name and return its data" do
193
189
  exp = Factory.yield_erb_rendered(@file_locals, &@content)
194
- assert_equal exp, subject.render(@file_name, @file_locals, &@content)
190
+ assert_equal exp, subject.render(@template_name, @file_locals, &@content)
195
191
  end
196
192
 
197
193
  end
@@ -199,7 +195,7 @@ class Deas::Erubis::Source
199
195
  class CompileTests < InitTests
200
196
  desc "`compile` method"
201
197
 
202
- should "compile raw content file name and return its data" do
198
+ should "evaluate raw template output and return it" do
203
199
  raw = "<p><%= 1 + 1 %></p>"
204
200
  exp = "<p>2</p>"
205
201
  assert_equal exp, subject.compile('compile', raw)
@@ -216,11 +212,11 @@ class Deas::Erubis::Source
216
212
 
217
213
  should have_imeths :[], :[]=, :keys
218
214
 
219
- should "take a file name and return nothing on index" do
215
+ should "take a template name and return nothing on index" do
220
216
  assert_nil subject[Factory.path]
221
217
  end
222
218
 
223
- should "take a file name and value and do nothing on index write" do
219
+ should "take a template name and value and do nothing on index write" do
224
220
  assert_nothing_raised do
225
221
  subject[Factory.path] = Factory.string
226
222
  end
@@ -16,7 +16,7 @@ class Deas::Erubis::TemplateEngine
16
16
  subject{ @engine }
17
17
 
18
18
  should have_imeths :erb_source, :erb_handler_local, :erb_logger_local
19
- should have_imeths :render, :partial
19
+ should have_imeths :render, :partial, :compile
20
20
 
21
21
  should "be a Deas template engine" do
22
22
  assert_kind_of Deas::TemplateEngine, subject
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas-erubis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
4
+ version: 0.5.1
11
5
  platform: ruby
12
6
  authors:
13
7
  - Kelly Redding
@@ -16,67 +10,49 @@ autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
12
 
19
- date: 2015-11-24 00:00:00 Z
13
+ date: 2016-04-05 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
16
+ name: assert
17
+ prerelease: false
22
18
  requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
19
  requirements:
25
20
  - - ~>
26
21
  - !ruby/object:Gem::Version
27
- hash: 29
28
- segments:
29
- - 2
30
- - 15
31
- version: "2.15"
22
+ version: 2.15.1
32
23
  type: :development
33
- name: assert
34
24
  version_requirements: *id001
35
- prerelease: false
36
25
  - !ruby/object:Gem::Dependency
26
+ name: deas
27
+ prerelease: false
37
28
  requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
29
  requirements:
40
30
  - - ~>
41
31
  - !ruby/object:Gem::Version
42
- hash: 69
43
- segments:
44
- - 0
45
- - 39
46
- version: "0.39"
32
+ version: 0.39.2
47
33
  type: :runtime
48
- name: deas
49
34
  version_requirements: *id002
50
- prerelease: false
51
35
  - !ruby/object:Gem::Dependency
36
+ name: erubis
37
+ prerelease: false
52
38
  requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
39
  requirements:
55
- - - ">="
40
+ - &id005
41
+ - ">="
56
42
  - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
43
  version: "0"
61
44
  type: :runtime
62
- name: erubis
63
45
  version_requirements: *id003
64
- prerelease: false
65
46
  - !ruby/object:Gem::Dependency
47
+ name: much-plugin
48
+ prerelease: false
66
49
  requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
50
  requirements:
69
51
  - - ~>
70
52
  - !ruby/object:Gem::Version
71
- hash: 9
72
- segments:
73
- - 0
74
- - 1
75
- version: "0.1"
53
+ version: 0.1.0
76
54
  type: :runtime
77
- name: much-plugin
78
55
  version_requirements: *id004
79
- prerelease: false
80
56
  description: Deas template engine for rendering erb templates using Erubis
81
57
  email:
82
58
  - kelly@kellyredding.com
@@ -92,7 +68,6 @@ files:
92
68
  - Gemfile
93
69
  - LICENSE
94
70
  - README.md
95
- - Rakefile
96
71
  - deas-erubis.gemspec
97
72
  - lib/deas-erubis.rb
98
73
  - lib/deas-erubis/source.rb
@@ -104,7 +79,8 @@ files:
104
79
  - test/support/templates/_partial.erb
105
80
  - test/support/templates/_partial_no_locals.erb
106
81
  - test/support/templates/_yield_partial.erb
107
- - test/support/templates/basic.erb
82
+ - test/support/templates/basic.html.erb
83
+ - test/support/templates/basic_alt.erubis
108
84
  - test/support/templates/compile.erb
109
85
  - test/support/templates/view.erb
110
86
  - test/support/templates/with_capture_partial.erb
@@ -119,35 +95,25 @@ files:
119
95
  homepage: http://github.com/redding/deas-erubis
120
96
  licenses:
121
97
  - MIT
98
+ metadata: {}
99
+
122
100
  post_install_message:
123
101
  rdoc_options: []
124
102
 
125
103
  require_paths:
126
104
  - lib
127
105
  required_ruby_version: !ruby/object:Gem::Requirement
128
- none: false
129
106
  requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
- version: "0"
107
+ - *id005
136
108
  required_rubygems_version: !ruby/object:Gem::Requirement
137
- none: false
138
109
  requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- hash: 3
142
- segments:
143
- - 0
144
- version: "0"
110
+ - *id005
145
111
  requirements: []
146
112
 
147
113
  rubyforge_project:
148
- rubygems_version: 1.8.29
114
+ rubygems_version: 2.5.1
149
115
  signing_key:
150
- specification_version: 3
116
+ specification_version: 4
151
117
  summary: Deas template engine for rendering erb templates using Erubis
152
118
  test_files:
153
119
  - test/helper.rb
@@ -155,7 +121,8 @@ test_files:
155
121
  - test/support/templates/_partial.erb
156
122
  - test/support/templates/_partial_no_locals.erb
157
123
  - test/support/templates/_yield_partial.erb
158
- - test/support/templates/basic.erb
124
+ - test/support/templates/basic.html.erb
125
+ - test/support/templates/basic_alt.erubis
159
126
  - test/support/templates/compile.erb
160
127
  - test/support/templates/view.erb
161
128
  - test/support/templates/with_capture_partial.erb
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"