curly-templates 2.3.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -1
- data/circle.yml +9 -0
- data/curly-templates.gemspec +4 -2
- data/lib/curly.rb +1 -1
- data/lib/curly/compiler.rb +6 -3
- data/lib/curly/presenter.rb +5 -0
- data/spec/compiler/context_blocks_spec.rb +14 -3
- data/spec/dummy/app/views/dashboards/new.html.curly +2 -0
- data/spec/integration/context_blocks_spec.rb +5 -2
- data/spec/matchers/have_structure.rb +29 -0
- data/spec/presenter_spec.rb +20 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdd7bc20cc76f95d2375221dcd42a0b195df7757
|
4
|
+
data.tar.gz: 3ad84f498e084560f579bbe91fde2684bbb7c53b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3998fc0caa17d607e4a13a3adc5bc17da44c6d8530d5c1910b273f16fca3ede99e352f2ddc44c318bda5040fa9a4f2b92eebb806f600b47679f937dcdd28c0f0
|
7
|
+
data.tar.gz: 126b53d760f5b3c10e99e16b219b7f76f9f842bbc289d4b9e4848d716fc5ba038796bc7f0bbffaa1af17a325fa8dfe8841855187675261b2136a2e44bc58f034
|
data/CHANGELOG.md
CHANGED
@@ -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
data/circle.yml
ADDED
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.3.
|
8
|
-
s.date = '
|
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
|
data/lib/curly.rb
CHANGED
data/lib/curly/compiler.rb
CHANGED
@@ -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
|
-
|
155
|
-
|
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 =
|
169
|
+
buffer = buffers.pop
|
167
170
|
presenter = presenters.pop
|
168
171
|
RUBY
|
169
172
|
end
|
data/lib/curly/presenter.rb
CHANGED
@@ -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
|
23
|
-
@form
|
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}}{{
|
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
|
@@ -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
|
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"><
|
14
|
+
<form accept-charset="UTF-8" action="/new" method="post"><input name="utf8" type="hidden" value="✓" />
|
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
|
data/spec/presenter_spec.rb
CHANGED
@@ -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.
|
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:
|
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
|