curly-templates 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/curly-templates.gemspec +2 -2
- data/lib/curly.rb +1 -1
- data/lib/curly/presenter.rb +22 -1
- data/spec/presenter_spec.rb +9 -0
- metadata +3 -3
data/curly-templates.gemspec
CHANGED
@@ -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.
|
8
|
-
s.date = '2013-04-
|
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
data/lib/curly/presenter.rb
CHANGED
@@ -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)
|
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.
|
data/spec/presenter_spec.rb
CHANGED
@@ -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.
|
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-
|
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:
|
146
|
+
hash: 3185475346795496979
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|