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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a7d8e10aa960fd5bea29bd1be907a8da9ac42b7
4
- data.tar.gz: 168ddd1df204565e509efc6a51c2bc1836de56f2
3
+ metadata.gz: c88276c903b21a344ef66730915ad49c862b6b74
4
+ data.tar.gz: e302028fc3a83e6f39c83ed30d129f432888cb35
5
5
  SHA512:
6
- metadata.gz: d29a5cb46eda27d7582aecf94eb184178d02be0acbb4549fe5448c753a9d129be1563db0878f44caa9ca999411caec5cae7454b96feb2ce684f41896560ece1b
7
- data.tar.gz: a96a20ef10b8e5307086b670beac0bdd351d53ae23317ac079bb2edd9f3b6af383b2cb7138881c3f4611257fe567bda75781a200cb1d3c090f52f87b663b361e
6
+ metadata.gz: 317419189ff20063face87bb7845da75c4f37e85f60188a745cba7d4079cfdaeb0df3b53f554684a5a611c75af2ff204a06251f6ec718cfe9c8d57cf0180c3dc
7
+ data.tar.gz: 1a437609e0dd076bf321d430cb43316424b5ca1adeb3ad9704567041d42dc26012fa2161dff8bad804d969fc4c514c878f7a3e9e5a7d98e232142d3358afa45a
@@ -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, with only simple placeholders in the HTML.
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
@@ -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.0'
8
- s.date = '2014-11-06'
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."
@@ -26,7 +26,7 @@
26
26
  # See Curly::Presenter for more information on presenters.
27
27
  #
28
28
  module Curly
29
- VERSION = "2.1.0"
29
+ VERSION = "2.1.1"
30
30
 
31
31
  # Compiles a Curly template to Ruby code.
32
32
  #
@@ -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
- item_options = options.merge(:#{name} => item, :#{counter} => index + 1)
107
- presenter = #{item_presenter_class}.new(self, item_options.with_indifferent_access)
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
- item_options = options.merge(:#{name} => item)
157
- presenter = #{item_presenter_class}.new(self, item_options.with_indifferent_access)
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)
@@ -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.with_indifferent_access)
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: 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,4 +8,16 @@ class Dashboards::ItemPresenter < Curly::Presenter
8
8
  def name
9
9
  @name
10
10
  end
11
+
12
+ def subitems
13
+ %w[1 2 3]
14
+ end
15
+
16
+ class SubitemPresenter < Curly::Presenter
17
+ presents :item, :subitem
18
+
19
+ def name
20
+ @subitem
21
+ end
22
+ end
11
23
  end
@@ -8,12 +8,22 @@ class Dashboards::NewPresenter < Curly::Presenter
8
8
  class FormPresenter < Curly::Presenter
9
9
  presents :form, :name
10
10
 
11
- def name_label
12
- "Name"
11
+ def name_field(&block)
12
+ content_tag :div, class: "field" do
13
+ block.call
14
+ end
13
15
  end
14
16
 
15
- def name_input
16
- @form.text_field :name, value: @name
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
@@ -1,5 +1,8 @@
1
1
  <ul>
2
2
  {{*items}}
3
3
  <li>{{item}}</li>
4
+ <ul>
5
+ {{*subitems}}<li>{{name}}</li>{{/subitems}}
6
+ </ul>
4
7
  {{/items}}
5
8
  </ul>
@@ -1,3 +1,5 @@
1
1
  {{@form}}
2
- <b>{{name_label}}</b> {{name_input}}
2
+ {{@name_field}}
3
+ <b>{{label}}</b> {{input}}
4
+ {{/name_field}}
3
5
  {{/form}}
@@ -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="&#x2713;" /></div>
14
- <b>Name</b> <input id="dashboard_name" name="dashboard[name]" type="text" value="test" />
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.0
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-06 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack