curly-templates 2.3.0 → 2.3.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: eb1dc47e32f2363e33bf4115534e745fc2eabd36
4
- data.tar.gz: 11b280643f7a7aa455e574555a6a26420c2eeb45
3
+ metadata.gz: cdd7bc20cc76f95d2375221dcd42a0b195df7757
4
+ data.tar.gz: 3ad84f498e084560f579bbe91fde2684bbb7c53b
5
5
  SHA512:
6
- metadata.gz: 863377bbaccc8028eb5d6adb6ab76b3184f87544bc584c2a12e296bf4b38790eca0e66f526356cb971e92ebfc9cabc77310aa42d6414fb0e52d84a0ea709f0a8
7
- data.tar.gz: 5399c66c98a2065ebe1ee97c36d516c88a1d08d70c5924c07047aafd566084bcb1493ffc0a4a1836f11dbdf94be144dbcebeaa737c9b2fb4f073099eefb1cf3c
6
+ metadata.gz: 3998fc0caa17d607e4a13a3adc5bc17da44c6d8530d5c1910b273f16fca3ede99e352f2ddc44c318bda5040fa9a4f2b92eebb806f600b47679f937dcdd28c0f0
7
+ data.tar.gz: 126b53d760f5b3c10e99e16b219b7f76f9f842bbc289d4b9e4848d716fc5ba038796bc7f0bbffaa1af17a325fa8dfe8841855187675261b2136a2e44bc58f034
@@ -1,5 +1,15 @@
1
1
  ### Unreleased
2
2
 
3
+ ### Curly 2.3.1 (January 7, 2015)
4
+
5
+ * Fix an issue with nested context blocks.
6
+
7
+ *Daniel Schierbeck*
8
+
9
+ * Make `respond_to_missing?` work with presenter objects.
10
+
11
+ *Jeremy Rodi*
12
+
3
13
  ### Curly 2.3.0 (December 22, 2014)
4
14
 
5
15
  * Add support for Rails 4.2.
data/Gemfile CHANGED
@@ -8,6 +8,6 @@ platform :ruby do
8
8
  gem 'redcarpet'
9
9
  gem 'github-markup'
10
10
  gem 'coveralls', require: false
11
- gem 'rails', '~> 4.1.0', require: false
11
+ gem 'rails', '~> 4.2.0', require: false
12
12
  gem 'rspec-rails', require: false
13
13
  end
@@ -0,0 +1,9 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.1.5
4
+ dependencies:
5
+ post:
6
+ - bundle install
7
+ test:
8
+ override:
9
+ - bundle exec rspec
@@ -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.3.0'
8
- s.date = '2014-12-22'
7
+ s.version = '2.3.1'
8
+ s.date = '2015-01-07'
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."
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  Gemfile
34
34
  README.md
35
35
  Rakefile
36
+ circle.yml
36
37
  curly-templates.gemspec
37
38
  lib/curly-templates.rb
38
39
  lib/curly.rb
@@ -92,6 +93,7 @@ Gem::Specification.new do |s|
92
93
  spec/integration/collection_blocks_spec.rb
93
94
  spec/integration/context_blocks_spec.rb
94
95
  spec/integration/partials_spec.rb
96
+ spec/matchers/have_structure.rb
95
97
  spec/parser_spec.rb
96
98
  spec/presenter_spec.rb
97
99
  spec/scanner_spec.rb
@@ -25,7 +25,7 @@
25
25
  #
26
26
  # See Curly::Presenter for more information on presenters.
27
27
  module Curly
28
- VERSION = "2.3.0"
28
+ VERSION = "2.3.1"
29
29
 
30
30
  # Compiles a Curly template to Ruby code.
31
31
  #
@@ -65,6 +65,7 @@ module Curly
65
65
  def code
66
66
  <<-RUBY
67
67
  buffer = ActiveSupport::SafeBuffer.new
68
+ buffers = []
68
69
  presenters = []
69
70
  #{@parts.join("\n")}
70
71
  buffer
@@ -151,9 +152,10 @@ module Curly
151
152
 
152
153
  output <<-RUBY
153
154
  presenters << presenter
154
- old_buffer, buffer = buffer, ActiveSupport::SafeBuffer.new
155
- old_buffer << #{method_call} do |item|
155
+ buffers << buffer
156
+ buffer << #{method_call} do |item|
156
157
  options = options.merge("#{name}" => item)
158
+ buffer = ActiveSupport::SafeBuffer.new
157
159
  presenter = #{item_presenter_class}.new(self, options)
158
160
  RUBY
159
161
 
@@ -162,8 +164,9 @@ module Curly
162
164
  @presenter_classes.pop
163
165
 
164
166
  output <<-RUBY
167
+ buffer
165
168
  end
166
- buffer = old_buffer
169
+ buffer = buffers.pop
167
170
  presenter = presenters.pop
168
171
  RUBY
169
172
  end
@@ -307,5 +307,10 @@ module Curly
307
307
  def method_missing(method, *args, &block)
308
308
  @_context.public_send(method, *args, &block)
309
309
  end
310
+
311
+ # Tells ruby (and developers) what methods we can accept.
312
+ def respond_to_missing?(method, include_private = false)
313
+ @_context.respond_to?(method, false)
314
+ end
310
315
  end
311
316
  end
@@ -19,8 +19,18 @@ describe Curly::Compiler do
19
19
  Class.new(Curly::Presenter) do
20
20
  presents :form
21
21
 
22
- def text
23
- @form.upcase
22
+ def text_field(&block)
23
+ block.call(@form)
24
+ end
25
+ end
26
+ end
27
+
28
+ let(:inner_context_presenter_class) do
29
+ Class.new(Curly::Presenter) do
30
+ presents :text_field
31
+
32
+ def field
33
+ %(<input type="text" value="#{@text_field.upcase}">).html_safe
24
34
  end
25
35
  end
26
36
  end
@@ -30,10 +40,11 @@ describe Curly::Compiler do
30
40
 
31
41
  before do
32
42
  stub_const("FormPresenter", context_presenter_class)
43
+ stub_const("TextFieldPresenter", inner_context_presenter_class)
33
44
  end
34
45
 
35
46
  it "compiles context blocks" do
36
- evaluate('{{@form}}{{text}}{{/form}}').should == '<form>YO</form>'
47
+ evaluate('{{@form}}{{@text_field}}{{field}}{{/text_field}}{{/form}}').should == '<form><input type="text" value="YO"></form>'
37
48
  end
38
49
 
39
50
  it "fails if the component is not a context block" do
@@ -3,3 +3,5 @@
3
3
  <b>{{label}}</b> {{input}}
4
4
  {{/name_field}}
5
5
  {{/form}}
6
+
7
+ <p>Thank you!</p>
@@ -1,20 +1,23 @@
1
1
  require 'spec_helper'
2
+ require 'matchers/have_structure'
2
3
 
3
4
  describe "Context blocks", type: :request do
4
5
  example "A context block" do
5
6
  get '/new'
6
7
 
7
- response.body.should == <<-HTML.strip_heredoc
8
+ response.body.should have_structure <<-HTML.strip_heredoc
8
9
  <html>
9
10
  <head>
10
11
  <title>Dummy app</title>
11
12
  </head>
12
13
  <body>
13
- <form accept-charset="UTF-8" action="/new" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div>
14
+ <form accept-charset="UTF-8" action="/new" method="post"><input name="utf8" type="hidden" value="&#x2713;" />
14
15
  <div class="field">
15
16
  <b>Name</b> <input id="dashboard_name" name="dashboard[name]" type="text" value="test" />
16
17
  </div>
17
18
  </form>
19
+
20
+ <p>Thank you!</p>
18
21
  </body>
19
22
  </html>
20
23
  HTML
@@ -0,0 +1,29 @@
1
+ require 'rspec/expectations'
2
+ require 'nokogiri'
3
+
4
+ RSpec::Matchers.define(:have_structure) do |expected|
5
+ match do |actual|
6
+ normalized(actual).should == normalized(expected)
7
+ end
8
+
9
+ failure_message_for_should do |actual|
10
+ "Expected\n\n#{actual}\n\n" \
11
+ "to have the same structure as\n\n#{expected}"
12
+ end
13
+
14
+ failure_message_for_should_not do |actual|
15
+ "Expected\n\n#{actual}\n\n" \
16
+ "to NOT have the same canonicalized structure as\n\n#{expected}"
17
+ end
18
+
19
+ def normalized(text)
20
+ document = Nokogiri::XML("<snippet>#{text}</snippet>")
21
+ document.traverse do |node|
22
+ node.content = node.text.strip if node.text?
23
+ end
24
+
25
+ document.canonicalize do |node, parent|
26
+ !(node.text? && node.text.empty?)
27
+ end
28
+ end
29
+ end
@@ -56,6 +56,26 @@ describe Curly::Presenter do
56
56
  end
57
57
  end
58
58
 
59
+ describe "#method_missing" do
60
+ let(:context) { double("context") }
61
+ subject {
62
+ CircusPresenter.new(context,
63
+ midget: "Meek Harolson",
64
+ clown: "Bubbles")
65
+ }
66
+
67
+ it "delegates calls to the context" do
68
+ context.should receive(:undefined).once
69
+ subject.undefined
70
+ end
71
+
72
+ it "allows method calls on context-defined methods" do
73
+ context.should receive(:respond_to?).
74
+ with(:undefined, false).once.and_return(true)
75
+ subject.method(:undefined)
76
+ end
77
+ end
78
+
59
79
  describe ".presenter_for_path" do
60
80
  it "returns the presenter class for the given path" do
61
81
  presenter = double("presenter")
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.3.0
4
+ version: 2.3.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-12-22 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -103,6 +103,7 @@ files:
103
103
  - Gemfile
104
104
  - README.md
105
105
  - Rakefile
106
+ - circle.yml
106
107
  - curly-templates.gemspec
107
108
  - lib/curly-templates.rb
108
109
  - lib/curly.rb
@@ -162,6 +163,7 @@ files:
162
163
  - spec/integration/collection_blocks_spec.rb
163
164
  - spec/integration/context_blocks_spec.rb
164
165
  - spec/integration/partials_spec.rb
166
+ - spec/matchers/have_structure.rb
165
167
  - spec/parser_spec.rb
166
168
  - spec/presenter_spec.rb
167
169
  - spec/scanner_spec.rb