curly-templates 0.6.0 → 0.6.1

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.
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'curly-templates'
7
- s.version = '0.6.0'
8
- s.date = '2013-04-22'
7
+ s.version = '0.6.1'
8
+ s.date = '2013-04-29'
9
9
 
10
10
  s.summary = "Free your views!"
11
11
  s.description = "A view layer for your Rails apps that separates structure and logic."
data/lib/curly.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # See Curly::Presenter for more information on presenters.
27
27
  #
28
28
  module Curly
29
- VERSION = "0.6.0"
29
+ VERSION = "0.6.1"
30
30
 
31
31
  REFERENCE_REGEX = %r(\{\{([\w\.]+)\}\})
32
32
 
@@ -100,8 +100,29 @@ module Curly
100
100
  "#{path}_presenter".camelize
101
101
  end
102
102
 
103
+ # Returns the presenter class for the given path.
104
+ #
105
+ # path - The String path of a template.
106
+ #
107
+ # Returns the Class or nil if the constant cannot be found.
103
108
  def presenter_for_path(path)
104
- presenter_name_for_path(path).constantize rescue nil
109
+ name = presenter_name_for_path(path)
110
+
111
+ begin
112
+ name.constantize
113
+ rescue NameError => e
114
+ missing_name = e.name.to_s
115
+
116
+ # Since we only want to return nil when the constant matching the
117
+ # path could not be found, we need to do same hacky matching. If
118
+ # the constant's name is Foo::BarPresenter and Foo does not exist,
119
+ # we consider that a match. If Foo exists but Foo::BarPresenter does
120
+ # not, NameError#name will return :BarPresenter, so we need to match
121
+ # that as well.
122
+ unless name.start_with?(missing_name) || name.end_with?(missing_name)
123
+ raise # The NameError was due to something else, re-raise.
124
+ end
125
+ end
105
126
  end
106
127
 
107
128
  # Whether a method is available to templates rendered with the presenter.
@@ -36,6 +36,15 @@ describe Curly::Presenter do
36
36
  it "returns nil if there is no presenter for the given path" do
37
37
  Curly::Presenter.presenter_for_path("foo/bar").should be_nil
38
38
  end
39
+
40
+ it "does not swallow exceptions" do
41
+ error = NameError.new("omg!", :baz)
42
+ String.any_instance.stub(:constantize).and_raise(error)
43
+
44
+ expect do
45
+ Curly::Presenter.presenter_for_path("foo/bar")
46
+ end.to raise_error(NameError)
47
+ end
39
48
  end
40
49
 
41
50
  describe ".version" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curly-templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
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: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: -673817575168436386
146
+ hash: 3185475346795496979
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  none: false
149
149
  requirements: