tiltout 1.3.0 → 1.4.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tiltout (1.2.0)
4
+ tiltout (1.4.0)
5
5
  tilt (~> 1.3)
6
6
 
7
7
  GEM
@@ -27,8 +27,10 @@ require "tiltout/version"
27
27
  require "tiltout/partials"
28
28
 
29
29
  class Tiltout
30
+ attr_reader :paths
31
+
30
32
  def initialize(template_root, opt = {})
31
- @template_root = template_root
33
+ @paths = Array(template_root)
32
34
  @cache = {} if !opt.key?(:cache) || opt[:cache]
33
35
  @layout = opt[:layout]
34
36
  @default_type = opt[:default_type] || "erb"
@@ -70,9 +72,13 @@ class Tiltout
70
72
 
71
73
  def find_file(name)
72
74
  return name[:file] if name.is_a?(Hash)
73
- full_name = File.join(@template_root, name.to_s)
74
- return full_name if cached?(full_name) || File.exists?(full_name)
75
- File.join(@template_root, "#{name}.#{@default_type}")
75
+ paths.each do |path|
76
+ full_name = File.join(path, name.to_s)
77
+ return full_name if cached?(full_name) || File.exists?(full_name)
78
+ full_name = File.join(path, "#{name}.#{@default_type}")
79
+ return full_name if cached?(full_name) || File.exists?(full_name)
80
+ end
81
+ nil
76
82
  end
77
83
 
78
84
  def cache(name, template)
@@ -24,5 +24,5 @@
24
24
  #++
25
25
 
26
26
  class Tiltout
27
- VERSION = "1.3.0"
27
+ VERSION = "1.4.0"
28
28
  end
@@ -32,19 +32,22 @@ module ViewHelper
32
32
  end
33
33
 
34
34
  describe Tiltout do
35
- before { @root = "/dolt/views" }
35
+ before do
36
+ @root = "/dolt/views"
37
+ File.stubs(:exists?).returns(false)
38
+ end
36
39
 
37
40
  def file_read
38
41
  File.respond_to?(:binread) ? :binread : :read
39
42
  end
40
43
 
41
44
  def fake_file(file, content)
42
- File.stubs(:file_exists?).with(file).returns(true)
45
+ File.stubs(:exists?).with(file).returns(true)
43
46
  File.stubs(file_read).with(file).returns(content)
44
47
  end
45
48
 
46
49
  it "reads template from file" do
47
- File.expects(file_read).with("/dolt/views/file.erb").returns("")
50
+ fake_file("/dolt/views/file.erb", "")
48
51
  renderer = Tiltout.new("/dolt/views")
49
52
  renderer.render(:file)
50
53
  end
@@ -222,4 +225,21 @@ Say it: <%= say_it %>, <%= do_it %>
222
225
  assert_equal "Chris is partial\n", renderer.render(:file)
223
226
  end
224
227
  end
228
+
229
+ describe "multiple view paths" do
230
+ it "uses the first available template" do
231
+ fake_file("/dolt/views/file.erb", "#1")
232
+ fake_file("/tlod/views/file.erb", "#2")
233
+ renderer = Tiltout.new(["/dolt/views", "/tlod/views"])
234
+
235
+ assert_equal "#1", renderer.render(:file)
236
+ end
237
+
238
+ it "uses only available template" do
239
+ fake_file("/tlod/views/file.erb", "#2")
240
+ renderer = Tiltout.new(["/dolt/views", "/tlod/views"])
241
+
242
+ assert_equal "#2", renderer.render(:file)
243
+ end
244
+ end
225
245
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiltout
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt