curly-templates 0.9.0 → 0.9.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.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ### Unreleased
2
2
 
3
+ ### Curly 0.9.1 (June 20, 2013)
4
+
5
+ * Better error handling. If a presenter class cannot be found, we not raise a
6
+ more descriptive exception.
7
+
8
+ *Daniel Schierbeck*
9
+
10
+ * Include the superclass' dependencies in a presenter's dependency list.
11
+
12
+ *Daniel Schierbeck*
13
+
3
14
  ### Curly 0.9.0 (June 4, 2013)
4
15
 
5
16
  * Allow running setup code before rendering a Curly view. Simply add a `#setup!`
@@ -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.9.0'
8
- s.date = '2013-06-04'
7
+ s.version = '0.9.1'
8
+ s.date = '2013-06-20'
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."
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  curly-templates.gemspec
36
36
  lib/curly-templates.rb
37
37
  lib/curly.rb
38
+ lib/curly/compilation_error.rb
38
39
  lib/curly/compiler.rb
39
40
  lib/curly/dependency_tracker.rb
40
41
  lib/curly/invalid_reference.rb
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.9.0"
29
+ VERSION = "0.9.1"
30
30
 
31
31
  # Compiles a Curly template to Ruby code.
32
32
  #
@@ -0,0 +1,19 @@
1
+ module Curly
2
+ class CompilationError < StandardError
3
+ attr_reader :path
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def message
10
+ "error compiling `#{path}`: could not find #{presenter_class_name}"
11
+ end
12
+
13
+ private
14
+
15
+ def presenter_class_name
16
+ Curly::Presenter.presenter_name_for_path(path)
17
+ end
18
+ end
19
+ end
@@ -12,6 +12,10 @@ module Curly
12
12
  #
13
13
  # Returns a String containing the Ruby code.
14
14
  def compile(template, presenter_class)
15
+ if presenter_class.nil?
16
+ raise ArgumentError, "presenter class cannot be nil"
17
+ end
18
+
15
19
  source = template.inspect
16
20
  source.gsub!(REFERENCE_REGEX) { compile_reference($1, presenter_class) }
17
21
 
@@ -191,7 +191,11 @@ module Curly
191
191
  #
192
192
  # Returns a Set of String view paths.
193
193
  def dependencies
194
+ # The base presenter doesn't have any dependencies.
195
+ return Set.new if self == Curly::Presenter
196
+
194
197
  @dependencies ||= Set.new
198
+ @dependencies.union(superclass.dependencies)
195
199
  end
196
200
 
197
201
  # Indicate that the presenter depends a list of other views.
@@ -199,8 +203,9 @@ module Curly
199
203
  # deps - A list of String view paths that the presenter depends on.
200
204
  #
201
205
  # Returns nothing.
202
- def depends_on(*deps)
203
- dependencies.merge(deps)
206
+ def depends_on(*dependencies)
207
+ @dependencies ||= Set.new
208
+ @dependencies.merge(dependencies)
204
209
  end
205
210
 
206
211
  # Get or set the version of the presenter.
@@ -1,6 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'action_view'
3
3
  require 'curly'
4
+ require 'curly/compilation_error'
4
5
 
5
6
  class Curly::TemplateHandler
6
7
  class << self
@@ -27,6 +28,8 @@ class Curly::TemplateHandler
27
28
  path = template.virtual_path
28
29
  presenter_class = Curly::Presenter.presenter_for_path(path)
29
30
 
31
+ raise Curly::CompilationError.new(path) if presenter_class.nil?
32
+
30
33
  source = Curly.compile(template.source, presenter_class)
31
34
 
32
35
  <<-RUBY
@@ -58,6 +58,12 @@ describe Curly::Compiler do
58
58
  evaluate("{{parameterized}}").should == ""
59
59
  end
60
60
 
61
+ it "raises ArgumentError if the presenter class is nil" do
62
+ expect do
63
+ Curly::Compiler.compile("foo", nil)
64
+ end.to raise_exception(ArgumentError)
65
+ end
66
+
61
67
  it "makes sure only public methods are called on the presenter object" do
62
68
  expect { evaluate("{{bar}}") }.to raise_exception(Curly::InvalidReference)
63
69
  end
@@ -142,4 +142,18 @@ describe Curly::Presenter do
142
142
  cache_key.should == "Foo::BarPresenter/42/foo/bum"
143
143
  end
144
144
  end
145
+
146
+ describe ".dependencies" do
147
+ it "returns the dependencies defined for the presenter" do
148
+ presenter = Class.new(Curly::Presenter) { depends_on 'foo' }
149
+ presenter.dependencies.to_a.should == ['foo']
150
+ end
151
+
152
+ it "includes the dependencies defined for parent classes" do
153
+ Curly::Presenter.dependencies
154
+ parent = Class.new(Curly::Presenter) { depends_on 'foo' }
155
+ presenter = Class.new(parent) { depends_on 'bar' }
156
+ presenter.dependencies.to_a.should =~ ['foo', 'bar']
157
+ end
158
+ end
145
159
  end
@@ -98,6 +98,12 @@ describe Curly::TemplateHandler do
98
98
  output.should == "BAR"
99
99
  end
100
100
 
101
+ it "should fail if there's no matching presenter class" do
102
+ template.stub(:virtual_path) { "missing" }
103
+ template.stub(:source) { " FOO " }
104
+ expect { output }.to raise_exception(Curly::CompilationError)
105
+ end
106
+
101
107
  it "allows calling public methods on the presenter" do
102
108
  template.stub(:source) { "{{foo}}" }
103
109
  output.should == "FOO"
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.9.0
4
+ version: 0.9.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-06-04 00:00:00.000000000 Z
12
+ date: 2013-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -116,6 +116,7 @@ files:
116
116
  - curly-templates.gemspec
117
117
  - lib/curly-templates.rb
118
118
  - lib/curly.rb
119
+ - lib/curly/compilation_error.rb
119
120
  - lib/curly/compiler.rb
120
121
  - lib/curly/dependency_tracker.rb
121
122
  - lib/curly/invalid_reference.rb
@@ -147,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
148
  version: '0'
148
149
  segments:
149
150
  - 0
150
- hash: 3268332445838018672
151
+ hash: 3388653685709819519
151
152
  required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  none: false
153
154
  requirements: