curly-templates 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -15
- data/curly-templates.gemspec +2 -2
- data/lib/curly.rb +1 -1
- data/lib/curly/compiler.rb +4 -4
- data/lib/curly/presenter.rb +4 -2
- data/lib/curly/template_handler.rb +1 -1
- data/spec/compiler/collections_spec.rb +1 -1
- data/spec/dummy/app/presenters/dashboards/item_presenter.rb +12 -0
- data/spec/dummy/app/presenters/dashboards/new_presenter.rb +14 -4
- data/spec/dummy/app/views/dashboards/collection.html.curly +3 -0
- data/spec/dummy/app/views/dashboards/new.html.curly +3 -1
- data/spec/integration/collection_blocks_spec.rb +9 -0
- data/spec/integration/context_blocks_spec.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c88276c903b21a344ef66730915ad49c862b6b74
|
4
|
+
data.tar.gz: e302028fc3a83e6f39c83ed30d129f432888cb35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 317419189ff20063face87bb7845da75c4f37e85f60188a745cba7d4079cfdaeb0df3b53f554684a5a611c75af2ff204a06251f6ec718cfe9c8d57cf0180c3dc
|
7
|
+
data.tar.gz: 1a437609e0dd076bf321d430cb43316424b5ca1adeb3ad9704567041d42dc26012fa2161dff8bad804d969fc4c514c878f7a3e9e5a7d98e232142d3358afa45a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### Curly 2.1.1 (November 12, 2014)
|
4
|
+
|
5
|
+
* Fix a bug where a parent presenter's parameters were not being passed to the
|
6
|
+
child presenter when using context blocks.
|
7
|
+
|
8
|
+
*Daniel Schierbeck*
|
9
|
+
|
3
10
|
### Curly 2.1.0 (November 6, 2014)
|
4
11
|
|
5
12
|
* Add support for [context blocks](https://github.com/zendesk/curly#context-blocks).
|
data/README.md
CHANGED
@@ -1,23 +1,9 @@
|
|
1
1
|
Curly
|
2
2
|
=======
|
3
3
|
|
4
|
-
Free your views!
|
5
|
-
|
6
4
|
Curly is a template language that completely separates structure and logic.
|
7
5
|
Instead of interspersing your HTML with snippets of Ruby, all logic is moved
|
8
|
-
to a presenter class
|
9
|
-
|
10
|
-
While the basic concepts are very similar to [Mustache](http://mustache.github.com/)
|
11
|
-
or [Handlebars](http://handlebarsjs.com/), Curly is different in some key ways:
|
12
|
-
|
13
|
-
- Instead of the template controlling the variable scope and looping through
|
14
|
-
data, all logic is left to the presenter object. This means that untrusted
|
15
|
-
templates can safely be executed, making Curly a possible alternative to
|
16
|
-
languages like [Liquid](http://liquidmarkup.org/).
|
17
|
-
- Instead of implementing its own template resolution mechanism, Curly hooks
|
18
|
-
directly into Rails, leveraging the existing resolvers.
|
19
|
-
- Because of its close integration with Rails, with Curly you can easily set
|
20
|
-
up caching for your views and partials.
|
6
|
+
to a presenter class.
|
21
7
|
|
22
8
|
|
23
9
|
### Table of Contents
|
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 = '2.1.
|
8
|
-
s.date = '2014-11-
|
7
|
+
s.version = '2.1.1'
|
8
|
+
s.date = '2014-11-12'
|
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/compiler.rb
CHANGED
@@ -103,8 +103,8 @@ module Curly
|
|
103
103
|
presenters << presenter
|
104
104
|
items = Array(#{method_call})
|
105
105
|
items.each_with_index do |item, index|
|
106
|
-
|
107
|
-
presenter = #{item_presenter_class}.new(self,
|
106
|
+
options = options.merge("#{name}" => item, "#{counter}" => index + 1)
|
107
|
+
presenter = #{item_presenter_class}.new(self, options)
|
108
108
|
RUBY
|
109
109
|
|
110
110
|
@presenter_classes.push(item_presenter_class)
|
@@ -153,8 +153,8 @@ module Curly
|
|
153
153
|
presenters << presenter
|
154
154
|
old_buffer, buffer = buffer, ActiveSupport::SafeBuffer.new
|
155
155
|
old_buffer << #{method_call} do |item|
|
156
|
-
|
157
|
-
presenter = #{item_presenter_class}.new(self,
|
156
|
+
options = options.merge("#{name}" => item)
|
157
|
+
presenter = #{item_presenter_class}.new(self, options)
|
158
158
|
RUBY
|
159
159
|
|
160
160
|
@presenter_classes.push(item_presenter_class)
|
data/lib/curly/presenter.rb
CHANGED
@@ -44,6 +44,8 @@ module Curly
|
|
44
44
|
#
|
45
45
|
def initialize(context, options = {})
|
46
46
|
@_context = context
|
47
|
+
options.stringify_keys!
|
48
|
+
|
47
49
|
self.class.presented_names.each do |name|
|
48
50
|
value = options.fetch(name) do
|
49
51
|
default_values.fetch(name) do
|
@@ -263,11 +265,11 @@ module Curly
|
|
263
265
|
def presents(*args)
|
264
266
|
options = args.extract_options!
|
265
267
|
|
266
|
-
self.presented_names += args
|
268
|
+
self.presented_names += args.map(&:to_s)
|
267
269
|
|
268
270
|
if options.key?(:default)
|
269
271
|
default_values = args.each_with_object(Hash.new) do |arg, hash|
|
270
|
-
hash[arg] = options.fetch(:default)
|
272
|
+
hash[arg.to_s] = options.fetch(:default)
|
271
273
|
end
|
272
274
|
|
273
275
|
self.default_values = self.default_values.merge(default_values)
|
@@ -59,7 +59,7 @@ class Curly::TemplateHandler
|
|
59
59
|
options = local_assigns
|
60
60
|
end
|
61
61
|
|
62
|
-
presenter = ::#{presenter_class}.new(self, options
|
62
|
+
presenter = ::#{presenter_class}.new(self, options)
|
63
63
|
presenter.setup!
|
64
64
|
|
65
65
|
@output_buffer = output_buffer || ActiveSupport::SafeBuffer.new
|
@@ -72,7 +72,7 @@ describe Curly::Compiler do
|
|
72
72
|
|
73
73
|
let(:list) { double("list", title: "Inventory") }
|
74
74
|
let(:context) { double("context") }
|
75
|
-
let(:presenter) { presenter_class.new(context, list
|
75
|
+
let(:presenter) { presenter_class.new(context, "list" => list) }
|
76
76
|
|
77
77
|
before do
|
78
78
|
stub_const("ItemPresenter", inner_presenter_class)
|
@@ -8,12 +8,22 @@ class Dashboards::NewPresenter < Curly::Presenter
|
|
8
8
|
class FormPresenter < Curly::Presenter
|
9
9
|
presents :form, :name
|
10
10
|
|
11
|
-
def
|
12
|
-
"
|
11
|
+
def name_field(&block)
|
12
|
+
content_tag :div, class: "field" do
|
13
|
+
block.call
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
class NameFieldPresenter < Curly::Presenter
|
18
|
+
presents :form, :name
|
19
|
+
|
20
|
+
def label
|
21
|
+
"Name"
|
22
|
+
end
|
23
|
+
|
24
|
+
def input
|
25
|
+
@form.text_field :name, value: @name
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
@@ -13,10 +13,19 @@ describe "Collection blocks", type: :request do
|
|
13
13
|
<ul>
|
14
14
|
|
15
15
|
<li>uno</li>
|
16
|
+
<ul>
|
17
|
+
<li>1</li><li>2</li><li>3</li>
|
18
|
+
</ul>
|
16
19
|
|
17
20
|
<li>dos</li>
|
21
|
+
<ul>
|
22
|
+
<li>1</li><li>2</li><li>3</li>
|
23
|
+
</ul>
|
18
24
|
|
19
25
|
<li>tres!</li>
|
26
|
+
<ul>
|
27
|
+
<li>1</li><li>2</li><li>3</li>
|
28
|
+
</ul>
|
20
29
|
|
21
30
|
</ul>
|
22
31
|
|
@@ -11,9 +11,10 @@ describe "Context blocks", type: :request do
|
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<form accept-charset="UTF-8" action="/new" method="post"><div style="display:none"><input name="utf8" type="hidden" value="✓" /></div>
|
14
|
-
<
|
14
|
+
<div class="field">
|
15
|
+
<b>Name</b> <input id="dashboard_name" name="dashboard[name]" type="text" value="test" />
|
16
|
+
</div>
|
15
17
|
</form>
|
16
|
-
|
17
18
|
</body>
|
18
19
|
</html>
|
19
20
|
HTML
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curly-templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|