curly-templates 2.0.0.beta1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/curly-templates.gemspec +6 -3
- data/lib/curly.rb +1 -1
- data/lib/curly/compiler.rb +4 -0
- data/lib/curly/{compilation_error.rb → presenter_not_found.rb} +1 -1
- data/lib/curly/template_handler.rb +2 -2
- data/spec/integration/collection_blocks_spec.rb +88 -0
- data/spec/integration/components_spec.rb +45 -0
- data/spec/integration/conditional_blocks_spec.rb +42 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/template_handler_spec.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2818caa59f5bef7c626637f7836e1af656b7e80f
|
4
|
+
data.tar.gz: 4ca1146d648950e76512b621161f83b4af455829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c963f1466c87b64c3a34af2a60c1a9be706623513688226ce2c3cb62aedae3abcaf8947d39620966960570aed0b3867d3fd4e5c72140405c061d4b62892bc8
|
7
|
+
data.tar.gz: 8fbbaf7cf446034b96343ee77f766bafc473d62e01a4010fa412fe4806538505929ee30843685f46b969a2fade65d2b43ad303aa9ace72d0cf0d64627229aa3a
|
data/CHANGELOG.md
CHANGED
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.0.0
|
8
|
-
s.date = '2014-
|
7
|
+
s.version = '2.0.0'
|
8
|
+
s.date = '2014-07-01'
|
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."
|
@@ -37,7 +37,6 @@ Gem::Specification.new do |s|
|
|
37
37
|
lib/curly-templates.rb
|
38
38
|
lib/curly.rb
|
39
39
|
lib/curly/attribute_parser.rb
|
40
|
-
lib/curly/compilation_error.rb
|
41
40
|
lib/curly/compiler.rb
|
42
41
|
lib/curly/component_compiler.rb
|
43
42
|
lib/curly/component_parser.rb
|
@@ -47,6 +46,7 @@ Gem::Specification.new do |s|
|
|
47
46
|
lib/curly/incorrect_ending_error.rb
|
48
47
|
lib/curly/invalid_component.rb
|
49
48
|
lib/curly/presenter.rb
|
49
|
+
lib/curly/presenter_not_found.rb
|
50
50
|
lib/curly/railtie.rb
|
51
51
|
lib/curly/scanner.rb
|
52
52
|
lib/curly/syntax_error.rb
|
@@ -61,6 +61,9 @@ Gem::Specification.new do |s|
|
|
61
61
|
spec/component_compiler_spec.rb
|
62
62
|
spec/generators/controller_generator_spec.rb
|
63
63
|
spec/incorrect_ending_error_spec.rb
|
64
|
+
spec/integration/collection_blocks_spec.rb
|
65
|
+
spec/integration/components_spec.rb
|
66
|
+
spec/integration/conditional_blocks_spec.rb
|
64
67
|
spec/presenter_spec.rb
|
65
68
|
spec/scanner_spec.rb
|
66
69
|
spec/spec_helper.rb
|
data/lib/curly.rb
CHANGED
data/lib/curly/compiler.rb
CHANGED
@@ -165,6 +165,10 @@ module Curly
|
|
165
165
|
name, identifier, attributes = ComponentParser.parse(component)
|
166
166
|
last_block = @blocks.pop
|
167
167
|
|
168
|
+
if last_block.nil?
|
169
|
+
raise Curly::Error, "block ending not expected"
|
170
|
+
end
|
171
|
+
|
168
172
|
unless last_block == [name, identifier]
|
169
173
|
raise Curly::IncorrectEndingError.new([name, identifier], last_block)
|
170
174
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'action_view'
|
3
3
|
require 'curly'
|
4
|
-
require 'curly/
|
4
|
+
require 'curly/presenter_not_found'
|
5
5
|
|
6
6
|
class Curly::TemplateHandler
|
7
7
|
class << self
|
@@ -48,7 +48,7 @@ class Curly::TemplateHandler
|
|
48
48
|
path = template.virtual_path
|
49
49
|
presenter_class = Curly::Presenter.presenter_for_path(path)
|
50
50
|
|
51
|
-
raise Curly::
|
51
|
+
raise Curly::PresenterNotFound.new(path) if presenter_class.nil?
|
52
52
|
|
53
53
|
source = Curly.compile(template.source, presenter_class)
|
54
54
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Collection block components" do
|
4
|
+
include RenderingSupport
|
5
|
+
|
6
|
+
before do
|
7
|
+
item_presenter do
|
8
|
+
presents :item
|
9
|
+
|
10
|
+
def name
|
11
|
+
@item
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
example "with neither identifier nor attributes" do
|
17
|
+
presenter do
|
18
|
+
def items
|
19
|
+
["one", "two", "three"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
render("{{*items}}<{{name}}>{{/items}}").should == "<one><two><three>"
|
24
|
+
end
|
25
|
+
|
26
|
+
example "with an identifier" do
|
27
|
+
presenter do
|
28
|
+
def items(filter = nil)
|
29
|
+
if filter == "even"
|
30
|
+
["two"]
|
31
|
+
elsif filter == "odd"
|
32
|
+
["one", "three"]
|
33
|
+
else
|
34
|
+
["one", "two", "three"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
render("{{*items.even}}<{{name}}>{{/items.even}}").should == "<two>"
|
40
|
+
render("{{*items.odd}}<{{name}}>{{/items.odd}}").should == "<one><three>"
|
41
|
+
render("{{*items}}<{{name}}>{{/items}}").should == "<one><two><three>"
|
42
|
+
end
|
43
|
+
|
44
|
+
example "with attributes" do
|
45
|
+
presenter do
|
46
|
+
def items(length: "1")
|
47
|
+
["x"] * length.to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
render("{{*items length=3}}<{{name}}>{{/items}}").should == "<x><x><x>"
|
52
|
+
render("{{*items}}<{{name}}>{{/items}}").should == "<x>"
|
53
|
+
end
|
54
|
+
|
55
|
+
example "with nested collection blocks" do
|
56
|
+
presenter do
|
57
|
+
def items
|
58
|
+
[{ parts: [1, 2] }, { parts: [3, 4] }]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
item_presenter do
|
63
|
+
presents :item
|
64
|
+
|
65
|
+
def parts
|
66
|
+
@item[:parts]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
part_presenter do
|
71
|
+
presents :part
|
72
|
+
|
73
|
+
def number
|
74
|
+
@part
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
render("{{*items}}<{{*parts}}[{{number}}]{{/parts}}>{{/items}}").should == "<[1][2]><[3][4]>"
|
79
|
+
end
|
80
|
+
|
81
|
+
def item_presenter(&block)
|
82
|
+
stub_const("ItemPresenter", Class.new(Curly::Presenter, &block))
|
83
|
+
end
|
84
|
+
|
85
|
+
def part_presenter(&block)
|
86
|
+
stub_const("ItemPresenter::PartPresenter", Class.new(Curly::Presenter, &block))
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Components" do
|
4
|
+
include RenderingSupport
|
5
|
+
|
6
|
+
example "with neither identifier nor attributes" do
|
7
|
+
presenter do
|
8
|
+
def title
|
9
|
+
"A Clockwork Orange"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
render("{{title}}").should == "A Clockwork Orange"
|
14
|
+
end
|
15
|
+
|
16
|
+
example "with an identifier" do
|
17
|
+
presenter do
|
18
|
+
def reverse(str)
|
19
|
+
str.reverse
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
render("{{reverse.123}}").should == "321"
|
24
|
+
end
|
25
|
+
|
26
|
+
example "with attributes" do
|
27
|
+
presenter do
|
28
|
+
def double(number:)
|
29
|
+
number.to_i * 2
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
render("{{double number=3}}").should == "6"
|
34
|
+
end
|
35
|
+
|
36
|
+
example "with both identifier and attributes" do
|
37
|
+
presenter do
|
38
|
+
def a(href:, title:)
|
39
|
+
content_tag :a, nil, href: href, title: title
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
render(%({{a href="/welcome.html" title="Welcome!"}})).should == %(<a href="/welcome.html" title="Welcome!"></a>)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Conditional block components" do
|
4
|
+
include RenderingSupport
|
5
|
+
|
6
|
+
example "with neither identifier nor attributes" do
|
7
|
+
presenter do
|
8
|
+
def high?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def low?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
render("{{#high?}}yup{{/high?}}").should == "yup"
|
18
|
+
render("{{#low?}}nah{{/low?}}").should == ""
|
19
|
+
end
|
20
|
+
|
21
|
+
example "with an identifier" do
|
22
|
+
presenter do
|
23
|
+
def even?(number)
|
24
|
+
number.to_i % 2 == 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
render("{{#even.42?}}even{{/even.42?}}").should == "even"
|
29
|
+
render("{{#even.13?}}even{{/even.13?}}").should == ""
|
30
|
+
end
|
31
|
+
|
32
|
+
example "with attributes" do
|
33
|
+
presenter do
|
34
|
+
def square?(width:, height:)
|
35
|
+
width.to_i == height.to_i
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
render("{{#square? width=2 height=2}}square{{/square?}}").should == "square"
|
40
|
+
render("{{#square? width=3 height=2}}square{{/square?}}").should == ""
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,24 @@ end
|
|
11
11
|
|
12
12
|
require 'curly'
|
13
13
|
|
14
|
+
module RenderingSupport
|
15
|
+
def presenter(&block)
|
16
|
+
@presenter = block
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(source)
|
20
|
+
stub_const("TestPresenter", Class.new(Curly::Presenter, &@presenter))
|
21
|
+
identifier = "test"
|
22
|
+
handler = Curly::TemplateHandler
|
23
|
+
details = { virtual_path: 'test' }
|
24
|
+
template = ActionView::Template.new(source, identifier, handler, details)
|
25
|
+
locals = {}
|
26
|
+
view = ActionView::Base.new
|
27
|
+
|
28
|
+
template.render(view, locals)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
14
32
|
module CompilationSupport
|
15
33
|
def evaluate(template, options = {}, &block)
|
16
34
|
code = Curly::Compiler.compile(template, presenter_class)
|
@@ -105,7 +105,7 @@ describe Curly::TemplateHandler do
|
|
105
105
|
it "should fail if there's no matching presenter class" do
|
106
106
|
template.stub(:virtual_path) { "missing" }
|
107
107
|
template.stub(:source) { " FOO " }
|
108
|
-
expect { output }.to raise_exception(Curly::
|
108
|
+
expect { output }.to raise_exception(Curly::PresenterNotFound)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "allows calling public methods on the presenter" do
|
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.0.0
|
4
|
+
version: 2.0.0
|
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
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -107,7 +107,6 @@ files:
|
|
107
107
|
- lib/curly-templates.rb
|
108
108
|
- lib/curly.rb
|
109
109
|
- lib/curly/attribute_parser.rb
|
110
|
-
- lib/curly/compilation_error.rb
|
111
110
|
- lib/curly/compiler.rb
|
112
111
|
- lib/curly/component_compiler.rb
|
113
112
|
- lib/curly/component_parser.rb
|
@@ -117,6 +116,7 @@ files:
|
|
117
116
|
- lib/curly/incorrect_ending_error.rb
|
118
117
|
- lib/curly/invalid_component.rb
|
119
118
|
- lib/curly/presenter.rb
|
119
|
+
- lib/curly/presenter_not_found.rb
|
120
120
|
- lib/curly/railtie.rb
|
121
121
|
- lib/curly/scanner.rb
|
122
122
|
- lib/curly/syntax_error.rb
|
@@ -131,6 +131,9 @@ files:
|
|
131
131
|
- spec/component_compiler_spec.rb
|
132
132
|
- spec/generators/controller_generator_spec.rb
|
133
133
|
- spec/incorrect_ending_error_spec.rb
|
134
|
+
- spec/integration/collection_blocks_spec.rb
|
135
|
+
- spec/integration/components_spec.rb
|
136
|
+
- spec/integration/conditional_blocks_spec.rb
|
134
137
|
- spec/presenter_spec.rb
|
135
138
|
- spec/scanner_spec.rb
|
136
139
|
- spec/spec_helper.rb
|
@@ -152,9 +155,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
155
|
version: '0'
|
153
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
157
|
requirements:
|
155
|
-
- - "
|
158
|
+
- - ">="
|
156
159
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
160
|
+
version: '0'
|
158
161
|
requirements: []
|
159
162
|
rubyforge_project:
|
160
163
|
rubygems_version: 2.2.2
|
@@ -168,6 +171,9 @@ test_files:
|
|
168
171
|
- spec/component_compiler_spec.rb
|
169
172
|
- spec/generators/controller_generator_spec.rb
|
170
173
|
- spec/incorrect_ending_error_spec.rb
|
174
|
+
- spec/integration/collection_blocks_spec.rb
|
175
|
+
- spec/integration/components_spec.rb
|
176
|
+
- spec/integration/conditional_blocks_spec.rb
|
171
177
|
- spec/presenter_spec.rb
|
172
178
|
- spec/scanner_spec.rb
|
173
179
|
- spec/syntax_error_spec.rb
|