curly-templates 0.7.0 → 0.8.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.
- data/Gemfile +1 -0
- data/README.md +13 -0
- data/curly-templates.gemspec +2 -2
- data/lib/curly.rb +1 -1
- data/lib/curly/presenter.rb +20 -2
- data/lib/curly/railtie.rb +6 -1
- data/lib/curly/template_handler.rb +1 -4
- data/spec/presenter_spec.rb +40 -2
- data/spec/spec_helper.rb +10 -0
- data/spec/template_handler_spec.rb +0 -10
- metadata +3 -3
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -87,6 +87,13 @@ render collection: post.comments
|
|
87
87
|
```
|
88
88
|
|
89
89
|
|
90
|
+
Is it ready to use in production?
|
91
|
+
---------------------------------
|
92
|
+
|
93
|
+
Yes! While still a young project, it's being used in a rather large Rails app
|
94
|
+
at Zendesk, where it performs admirably.
|
95
|
+
|
96
|
+
|
90
97
|
Examples
|
91
98
|
--------
|
92
99
|
|
@@ -256,6 +263,12 @@ Thanks
|
|
256
263
|
Thanks to [Zendesk](http://zendesk.com/) for sponsoring the work on Curly.
|
257
264
|
|
258
265
|
|
266
|
+
Build Status
|
267
|
+
------------
|
268
|
+
|
269
|
+
[](https://travis-ci.org/zendesk/curly)
|
270
|
+
|
271
|
+
|
259
272
|
Copyright and License
|
260
273
|
---------------------
|
261
274
|
|
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.
|
8
|
-
s.date = '2013-05-
|
7
|
+
s.version = '0.8.0'
|
8
|
+
s.date = '2013-05-22'
|
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
@@ -45,7 +45,13 @@ module Curly
|
|
45
45
|
def initialize(context, options = {})
|
46
46
|
@_context = context
|
47
47
|
self.class.presented_names.each do |name|
|
48
|
-
|
48
|
+
value = options.fetch(name) do
|
49
|
+
default_values.fetch(name) do
|
50
|
+
raise ArgumentError.new("required parameter `#{name}` missing")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
instance_variable_set("@#{name}", value)
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
@@ -209,14 +215,26 @@ module Curly
|
|
209
215
|
end
|
210
216
|
|
211
217
|
def presents(*args)
|
218
|
+
options = args.extract_options!
|
219
|
+
|
212
220
|
self.presented_names += args
|
221
|
+
|
222
|
+
if options.key?(:default)
|
223
|
+
default_values = args.each_with_object(Hash.new) do |arg, hash|
|
224
|
+
hash[arg] = options.fetch(:default)
|
225
|
+
end
|
226
|
+
|
227
|
+
self.default_values = self.default_values.merge(default_values)
|
228
|
+
end
|
213
229
|
end
|
214
230
|
end
|
215
231
|
|
216
232
|
private
|
217
233
|
|
218
|
-
class_attribute :presented_names
|
234
|
+
class_attribute :presented_names, :default_values
|
235
|
+
|
219
236
|
self.presented_names = [].freeze
|
237
|
+
self.default_values = {}.freeze
|
220
238
|
|
221
239
|
# Delegates private method calls to the current view context.
|
222
240
|
#
|
data/lib/curly/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'curly/dependency_tracker'
|
2
|
+
|
1
3
|
module Curly
|
2
4
|
class Railtie < Rails::Railtie
|
3
5
|
config.app_generators.template_engine :curly
|
@@ -6,9 +8,12 @@ module Curly
|
|
6
8
|
ActionView::Template.register_template_handler :curly, Curly::TemplateHandler
|
7
9
|
|
8
10
|
if defined?(CacheDigests::DependencyTracker)
|
9
|
-
require 'curly/dependency_tracker'
|
10
11
|
CacheDigests::DependencyTracker.register_tracker :curly, Curly::DependencyTracker
|
11
12
|
end
|
13
|
+
|
14
|
+
if defined?(ActionView::DependencyTracker)
|
15
|
+
ActionView::DependencyTracker.register_tracker :curly, Curly::DependencyTracker
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
@@ -28,7 +28,6 @@ class Curly::TemplateHandler
|
|
28
28
|
presenter_class = Curly::Presenter.presenter_for_path(path)
|
29
29
|
|
30
30
|
source = Curly.compile(template.source, presenter_class)
|
31
|
-
template_digest = Digest::MD5.hexdigest(template.source)
|
32
31
|
|
33
32
|
<<-RUBY
|
34
33
|
if local_assigns.empty?
|
@@ -46,8 +45,6 @@ class Curly::TemplateHandler
|
|
46
45
|
if key = presenter.cache_key
|
47
46
|
@output_buffer = ActiveSupport::SafeBuffer.new
|
48
47
|
|
49
|
-
template_digest = #{template_digest.inspect}
|
50
|
-
|
51
48
|
if #{presenter_class}.respond_to?(:cache_key)
|
52
49
|
presenter_key = #{presenter_class}.cache_key
|
53
50
|
else
|
@@ -58,7 +55,7 @@ class Curly::TemplateHandler
|
|
58
55
|
expires_in: presenter.cache_duration
|
59
56
|
}
|
60
57
|
|
61
|
-
cache([
|
58
|
+
cache([key, presenter_key].compact, options) do
|
62
59
|
safe_concat(view_function.call)
|
63
60
|
end
|
64
61
|
|
data/spec/presenter_spec.rb
CHANGED
@@ -9,8 +9,14 @@ describe Curly::Presenter do
|
|
9
9
|
|
10
10
|
include MonkeyComponents
|
11
11
|
|
12
|
-
presents :midget, :clown
|
13
|
-
|
12
|
+
presents :midget, :clown, default: nil
|
13
|
+
presents :elephant, default: "Dumbo"
|
14
|
+
|
15
|
+
attr_reader :midget, :clown, :elephant
|
16
|
+
end
|
17
|
+
|
18
|
+
class FrenchCircusPresenter < CircusPresenter
|
19
|
+
presents :elephant, default: "Babar"
|
14
20
|
end
|
15
21
|
|
16
22
|
it "sets the presented parameters as instance variables" do
|
@@ -25,6 +31,18 @@ describe Curly::Presenter do
|
|
25
31
|
presenter.clown.should == "Bubbles"
|
26
32
|
end
|
27
33
|
|
34
|
+
it "allows specifying default values for parameters" do
|
35
|
+
context = double("context")
|
36
|
+
|
37
|
+
# Make sure subclasses can change default values.
|
38
|
+
french_presenter = FrenchCircusPresenter.new(context)
|
39
|
+
french_presenter.elephant.should == "Babar"
|
40
|
+
|
41
|
+
# The subclass shouldn't change the superclass' defaults, though.
|
42
|
+
presenter = CircusPresenter.new(context)
|
43
|
+
presenter.elephant.should == "Dumbo"
|
44
|
+
end
|
45
|
+
|
28
46
|
describe ".presenter_for_path" do
|
29
47
|
it "returns the presenter class for the given path" do
|
30
48
|
presenter = double("presenter")
|
@@ -47,6 +65,26 @@ describe Curly::Presenter do
|
|
47
65
|
end
|
48
66
|
end
|
49
67
|
|
68
|
+
describe ".available_methods" do
|
69
|
+
it "includes the methods on the presenter" do
|
70
|
+
CircusPresenter.available_methods.should include(:midget)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not include methods on the Curly::Presenter base class" do
|
74
|
+
CircusPresenter.available_methods.should_not include(:cache_key)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".method_available?" do
|
79
|
+
it "returns true if the method is available" do
|
80
|
+
CircusPresenter.method_available?(:midget).should be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns false if the method is not available" do
|
84
|
+
CircusPresenter.method_available?(:bear).should be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
50
88
|
describe ".version" do
|
51
89
|
it "sets the version of the presenter" do
|
52
90
|
presenter1 = Class.new(Curly::Presenter) do
|
data/spec/spec_helper.rb
CHANGED
@@ -123,16 +123,6 @@ describe Curly::TemplateHandler do
|
|
123
123
|
output.should == "BAZ"
|
124
124
|
end
|
125
125
|
|
126
|
-
it "adds a digest of the template source to the cache key" do
|
127
|
-
context.assigns[:cache_key] = "x"
|
128
|
-
|
129
|
-
template.stub(:source) { "{{bar}}" }
|
130
|
-
output.should == "BAR"
|
131
|
-
|
132
|
-
template.stub(:source) { "FOO{{bar}}" }
|
133
|
-
output.should == "FOOBAR"
|
134
|
-
end
|
135
|
-
|
136
126
|
it "adds the presenter class' cache key to the instance's cache key" do
|
137
127
|
# Make sure caching is enabled
|
138
128
|
context.assigns[:cache_key] = "x"
|
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.
|
4
|
+
version: 0.8.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: 2013-05-
|
12
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
segments:
|
147
147
|
- 0
|
148
|
-
hash:
|
148
|
+
hash: 2436310145351861333
|
149
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|