stache 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.2.0
2
+
3
+ * Patch to properly reraise NameError/LoadError that occurs upon loading a Stache::View
@@ -8,13 +8,13 @@ module Stache
8
8
  if Stache::Util.needs_compilable?
9
9
  include Stache::Util.av_template_class(:Handlers)::Compilable
10
10
  end
11
-
11
+
12
12
  # Thanks to Mustache::Rails3 for getting us most of the way home here
13
13
  def compile(template)
14
14
  #
15
15
  # get a custom Mustache, or the default Stache::View
16
16
  mustache_class = mustache_class_from_template(template)
17
-
17
+
18
18
  # Return a string that will be eval'd in the context of the ActionView, ugly, but it works.
19
19
  <<-MUSTACHE
20
20
  mustache = ::#{mustache_class}.new
@@ -25,15 +25,15 @@ module Stache
25
25
  mustache.context.update(local_assigns)
26
26
  variables = controller.instance_variable_names
27
27
  variables -= %w[@template]
28
-
28
+
29
29
  if controller.respond_to?(:protected_instance_variables)
30
30
  variables -= controller.protected_instance_variables
31
31
  end
32
-
32
+
33
33
  variables.each do |name|
34
34
  mustache.instance_variable_set(name, controller.instance_variable_get(name))
35
35
  end
36
-
36
+
37
37
  # Declaring an +attr_reader+ for each instance variable in the
38
38
  # Stache::View subclass makes them available to your templates.
39
39
  mustache.class.class_eval do
@@ -43,7 +43,7 @@ module Stache
43
43
  mustache.render.html_safe
44
44
  MUSTACHE
45
45
  end
46
-
46
+
47
47
  # In Rails 3.1+, #call takes the place of #compile
48
48
  def self.call(template)
49
49
  new.compile(template)
@@ -54,10 +54,15 @@ module Stache
54
54
  const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
55
55
  begin
56
56
  const_name.constantize
57
- rescue NameError, LoadError
58
- Stache::View
57
+ rescue NameError, LoadError => e
58
+ # Only rescue NameError/LoadError concerning our mustache_class
59
+ if e.message.match(/#{const_name}$/)
60
+ Stache::View
61
+ else
62
+ raise e
63
+ end
59
64
  end
60
65
  end
61
66
 
62
67
  end
63
- end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Stache
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -25,5 +25,17 @@ describe Stache::Handler do
25
25
  it "retuns Stache::View if it can't find none" do
26
26
  @handler.mustache_class_from_template(@template).should == Stache::View
27
27
  end
28
+ it "reraises error if loaded mustache_class raises a NameError" do
29
+ @template.stub!(:virtual_path).and_return("profiles/index")
30
+ module Profiles; end
31
+ # Emulate autoload behavior so the error gets raised upon const_get
32
+ Profiles.autoload :Index, File.join(File.dirname(__FILE__), "profile_autoload.rb")
33
+
34
+ lambda {
35
+ @handler.mustache_class_from_template(@template)
36
+ }.should raise_error(NameError, "uninitialized constant Profiles::Index::Foo")
37
+
38
+ Object.send(:remove_const, :Profiles)
39
+ end
28
40
  end
29
- end
41
+ end
@@ -0,0 +1,6 @@
1
+ # This file is intended to raise a NameError upon require
2
+ module Profiles
3
+ class Index < Stache::View
4
+ include Foo
5
+ end
6
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: stache
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Wilson
@@ -14,7 +14,6 @@ date: 2011-08-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mustache
17
- prerelease: false
18
17
  requirement: &id001 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
@@ -22,10 +21,10 @@ dependencies:
22
21
  - !ruby/object:Gem::Version
23
22
  version: "0"
24
23
  type: :runtime
24
+ prerelease: false
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
- prerelease: false
29
28
  requirement: &id002 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
@@ -33,10 +32,10 @@ dependencies:
33
32
  - !ruby/object:Gem::Version
34
33
  version: 3.1.0
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- prerelease: false
40
39
  requirement: &id003 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
@@ -44,10 +43,10 @@ dependencies:
44
43
  - !ruby/object:Gem::Version
45
44
  version: "0"
46
45
  type: :development
46
+ prerelease: false
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec-rails
50
- prerelease: false
51
50
  requirement: &id004 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
@@ -55,10 +54,10 @@ dependencies:
55
54
  - !ruby/object:Gem::Version
56
55
  version: "0"
57
56
  type: :development
57
+ prerelease: false
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: bundler
61
- prerelease: false
62
61
  requirement: &id005 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
@@ -66,10 +65,10 @@ dependencies:
66
65
  - !ruby/object:Gem::Version
67
66
  version: "0"
68
67
  type: :development
68
+ prerelease: false
69
69
  version_requirements: *id005
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bueller
72
- prerelease: false
73
72
  requirement: &id006 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
@@ -77,10 +76,10 @@ dependencies:
77
76
  - !ruby/object:Gem::Version
78
77
  version: "0"
79
78
  type: :development
79
+ prerelease: false
80
80
  version_requirements: *id006
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rake
83
- prerelease: false
84
83
  requirement: &id007 !ruby/object:Gem::Requirement
85
84
  none: false
86
85
  requirements:
@@ -88,10 +87,10 @@ dependencies:
88
87
  - !ruby/object:Gem::Version
89
88
  version: "0"
90
89
  type: :development
90
+ prerelease: false
91
91
  version_requirements: *id007
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rcov
94
- prerelease: false
95
94
  requirement: &id008 !ruby/object:Gem::Requirement
96
95
  none: false
97
96
  requirements:
@@ -99,6 +98,7 @@ dependencies:
99
98
  - !ruby/object:Gem::Version
100
99
  version: "0"
101
100
  type: :development
101
+ prerelease: false
102
102
  version_requirements: *id008
103
103
  description: A rails 3.x compatible template handler, configurable.
104
104
  email: mhw@hypomodern.com
@@ -114,6 +114,7 @@ files:
114
114
  - .gitignore
115
115
  - .rspec
116
116
  - .rvmrc
117
+ - CHANGELOG.md
117
118
  - Gemfile
118
119
  - LICENSE
119
120
  - README.md
@@ -167,6 +168,7 @@ files:
167
168
  - spec/stache/asset_helper_spec.rb
168
169
  - spec/stache/config_spec.rb
169
170
  - spec/stache/handler_spec.rb
171
+ - spec/stache/profile_autoload.rb
170
172
  - spec/stache/util_spec.rb
171
173
  - spec/stache/view_spec.rb
172
174
  - spec/stache_spec.rb
@@ -184,6 +186,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
186
  requirements:
185
187
  - - ">="
186
188
  - !ruby/object:Gem::Version
189
+ hash: 542671315864466060
190
+ segments:
191
+ - 0
187
192
  version: "0"
188
193
  required_rubygems_version: !ruby/object:Gem::Requirement
189
194
  none: false
@@ -240,6 +245,7 @@ test_files:
240
245
  - spec/stache/asset_helper_spec.rb
241
246
  - spec/stache/config_spec.rb
242
247
  - spec/stache/handler_spec.rb
248
+ - spec/stache/profile_autoload.rb
243
249
  - spec/stache/util_spec.rb
244
250
  - spec/stache/view_spec.rb
245
251
  - spec/stache_spec.rb