curly-templates 1.0.1 → 2.0.0.beta1
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 +13 -4
- data/README.md +179 -8
- data/Rakefile +1 -1
- data/curly-templates.gemspec +10 -3
- data/lib/curly.rb +4 -4
- data/lib/curly/attribute_parser.rb +69 -0
- data/lib/curly/compiler.rb +77 -47
- data/lib/curly/component_compiler.rb +119 -0
- data/lib/curly/component_parser.rb +13 -0
- data/lib/curly/incomplete_block_error.rb +3 -3
- data/lib/curly/incorrect_ending_error.rb +17 -3
- data/lib/curly/invalid_component.rb +13 -0
- data/lib/curly/presenter.rb +31 -11
- data/lib/curly/scanner.rb +24 -11
- data/spec/attribute_parser_spec.rb +46 -0
- data/spec/compiler/collections_spec.rb +153 -0
- data/spec/compiler_spec.rb +18 -34
- data/spec/component_compiler_spec.rb +160 -0
- data/spec/incorrect_ending_error_spec.rb +13 -0
- data/spec/presenter_spec.rb +27 -10
- data/spec/scanner_spec.rb +22 -13
- data/spec/spec_helper.rb +15 -0
- data/spec/template_handler_spec.rb +1 -1
- metadata +16 -5
- data/lib/curly/invalid_reference.rb +0 -13
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Curly::IncorrectEndingError do
|
4
|
+
it "has a nice error message" do
|
5
|
+
error = Curly::IncorrectEndingError.new(["bar", nil], ["foo", nil])
|
6
|
+
error.message.should == "compilation error: expected `{{/foo}}`, got `{{/bar}}`"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "handles components with an identifier" do
|
10
|
+
error = Curly::IncorrectEndingError.new(["foo", "y"], ["foo", "x"])
|
11
|
+
error.message.should == "compilation error: expected `{{/foo.x}}`, got `{{/foo.y}}`"
|
12
|
+
end
|
13
|
+
end
|
data/spec/presenter_spec.rb
CHANGED
@@ -23,10 +23,13 @@ describe Curly::Presenter do
|
|
23
23
|
presents :champagne
|
24
24
|
end
|
25
25
|
|
26
|
+
class CircusPresenter::MonkeyPresenter < Curly::Presenter
|
27
|
+
end
|
28
|
+
|
26
29
|
describe "#initialize" do
|
27
30
|
let(:context) { double("context") }
|
28
31
|
|
29
|
-
it "sets the presented
|
32
|
+
it "sets the presented identifiers as instance variables" do
|
30
33
|
presenter = CircusPresenter.new(context,
|
31
34
|
midget: "Meek Harolson",
|
32
35
|
clown: "Bubbles"
|
@@ -36,13 +39,13 @@ describe Curly::Presenter do
|
|
36
39
|
presenter.clown.should == "Bubbles"
|
37
40
|
end
|
38
41
|
|
39
|
-
it "raises an exception if a required
|
42
|
+
it "raises an exception if a required identifier is not specified" do
|
40
43
|
expect {
|
41
44
|
FancyCircusPresenter.new(context, {})
|
42
|
-
}.to raise_exception(ArgumentError, "required
|
45
|
+
}.to raise_exception(ArgumentError, "required identifier `champagne` missing")
|
43
46
|
end
|
44
47
|
|
45
|
-
it "allows specifying default values for
|
48
|
+
it "allows specifying default values for identifiers" do
|
46
49
|
# Make sure subclasses can change default values.
|
47
50
|
french_presenter = FrenchCircusPresenter.new(context)
|
48
51
|
french_presenter.elephant.should == "Babar"
|
@@ -75,23 +78,37 @@ describe Curly::Presenter do
|
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
|
-
describe ".
|
81
|
+
describe ".presenter_for_name" do
|
82
|
+
it "returns the presenter class for the given name" do
|
83
|
+
CircusPresenter.presenter_for_name("monkey").should == CircusPresenter::MonkeyPresenter
|
84
|
+
end
|
85
|
+
|
86
|
+
it "looks in the namespace" do
|
87
|
+
CircusPresenter.presenter_for_name("french_circus").should == FrenchCircusPresenter
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns NameError if the presenter class doesn't exist" do
|
91
|
+
expect { CircusPresenter.presenter_for_name("clown") }.to raise_exception(NameError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe ".available_components" do
|
79
96
|
it "includes the methods on the presenter" do
|
80
|
-
CircusPresenter.
|
97
|
+
CircusPresenter.available_components.should include("midget")
|
81
98
|
end
|
82
99
|
|
83
100
|
it "does not include methods on the Curly::Presenter base class" do
|
84
|
-
CircusPresenter.
|
101
|
+
CircusPresenter.available_components.should_not include("cache_key")
|
85
102
|
end
|
86
103
|
end
|
87
104
|
|
88
|
-
describe ".
|
105
|
+
describe ".component_available?" do
|
89
106
|
it "returns true if the method is available" do
|
90
|
-
CircusPresenter.
|
107
|
+
CircusPresenter.component_available?("midget").should == true
|
91
108
|
end
|
92
109
|
|
93
110
|
it "returns false if the method is not available" do
|
94
|
-
CircusPresenter.
|
111
|
+
CircusPresenter.component_available?("bear").should == false
|
95
112
|
end
|
96
113
|
end
|
97
114
|
|
data/spec/scanner_spec.rb
CHANGED
@@ -4,20 +4,20 @@ describe Curly::Scanner, ".scan" do
|
|
4
4
|
it "returns the tokens in the source" do
|
5
5
|
scan("foo {{bar}} baz").should == [
|
6
6
|
[:text, "foo "],
|
7
|
-
[:
|
7
|
+
[:component, "bar"],
|
8
8
|
[:text, " baz"]
|
9
9
|
]
|
10
10
|
end
|
11
11
|
|
12
|
-
it "scans
|
12
|
+
it "scans components with identifiers" do
|
13
13
|
scan("{{foo.bar}}").should == [
|
14
|
-
[:
|
14
|
+
[:component, "foo.bar"]
|
15
15
|
]
|
16
16
|
end
|
17
17
|
|
18
|
-
it "allows
|
18
|
+
it "allows components with whitespace" do
|
19
19
|
scan("{{ foo bar}}").should == [
|
20
|
-
[:
|
20
|
+
[:component, " foo bar"]
|
21
21
|
]
|
22
22
|
end
|
23
23
|
|
@@ -59,21 +59,30 @@ describe Curly::Scanner, ".scan" do
|
|
59
59
|
]
|
60
60
|
end
|
61
61
|
|
62
|
-
it "scans block tags" do
|
63
|
-
scan('foo {{#bar}} hello {{/bar}}').should == [
|
62
|
+
it "scans conditional block tags" do
|
63
|
+
scan('foo {{#bar?}} hello {{/bar?}}').should == [
|
64
64
|
[:text, "foo "],
|
65
|
-
[:
|
65
|
+
[:conditional_block_start, "bar?"],
|
66
66
|
[:text, " hello "],
|
67
|
-
[:
|
67
|
+
[:conditional_block_end, "bar?"]
|
68
68
|
]
|
69
69
|
end
|
70
70
|
|
71
71
|
it "scans inverse block tags" do
|
72
|
-
scan('foo {{^bar}} hello {{/bar}}').should == [
|
72
|
+
scan('foo {{^bar?}} hello {{/bar?}}').should == [
|
73
73
|
[:text, "foo "],
|
74
|
-
[:
|
74
|
+
[:inverse_conditional_block_start, "bar?"],
|
75
75
|
[:text, " hello "],
|
76
|
-
[:
|
76
|
+
[:conditional_block_end, "bar?"]
|
77
|
+
]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "scans collection block tags" do
|
81
|
+
scan('foo {{*bar}} hello {{/bar}}').should == [
|
82
|
+
[:text, "foo "],
|
83
|
+
[:collection_block_start, "bar"],
|
84
|
+
[:text, " hello "],
|
85
|
+
[:collection_block_end, "bar"]
|
77
86
|
]
|
78
87
|
end
|
79
88
|
|
@@ -89,7 +98,7 @@ describe Curly::Scanner, ".scan" do
|
|
89
98
|
]
|
90
99
|
end
|
91
100
|
|
92
|
-
it "raises Curly::SyntaxError on unclosed
|
101
|
+
it "raises Curly::SyntaxError on unclosed components" do
|
93
102
|
["{{", "{{yolo"].each do |template|
|
94
103
|
expect { scan(template) }.to raise_error(Curly::SyntaxError)
|
95
104
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,3 +10,18 @@ if ENV['CI']
|
|
10
10
|
end
|
11
11
|
|
12
12
|
require 'curly'
|
13
|
+
|
14
|
+
module CompilationSupport
|
15
|
+
def evaluate(template, options = {}, &block)
|
16
|
+
code = Curly::Compiler.compile(template, presenter_class)
|
17
|
+
context = double("context")
|
18
|
+
|
19
|
+
context.instance_eval(<<-RUBY)
|
20
|
+
def self.render(presenter, options)
|
21
|
+
#{code}
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
|
25
|
+
context.render(presenter, options, &block)
|
26
|
+
end
|
27
|
+
end
|
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:
|
4
|
+
version: 2.0.0.beta1
|
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-06-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -106,13 +106,16 @@ files:
|
|
106
106
|
- curly-templates.gemspec
|
107
107
|
- lib/curly-templates.rb
|
108
108
|
- lib/curly.rb
|
109
|
+
- lib/curly/attribute_parser.rb
|
109
110
|
- lib/curly/compilation_error.rb
|
110
111
|
- lib/curly/compiler.rb
|
112
|
+
- lib/curly/component_compiler.rb
|
113
|
+
- lib/curly/component_parser.rb
|
111
114
|
- lib/curly/dependency_tracker.rb
|
112
115
|
- lib/curly/error.rb
|
113
116
|
- lib/curly/incomplete_block_error.rb
|
114
117
|
- lib/curly/incorrect_ending_error.rb
|
115
|
-
- lib/curly/
|
118
|
+
- lib/curly/invalid_component.rb
|
116
119
|
- lib/curly/presenter.rb
|
117
120
|
- lib/curly/railtie.rb
|
118
121
|
- lib/curly/scanner.rb
|
@@ -122,8 +125,12 @@ files:
|
|
122
125
|
- lib/generators/curly/controller/templates/presenter.rb.erb
|
123
126
|
- lib/generators/curly/controller/templates/view.html.curly.erb
|
124
127
|
- lib/rails/projections.json
|
128
|
+
- spec/attribute_parser_spec.rb
|
129
|
+
- spec/compiler/collections_spec.rb
|
125
130
|
- spec/compiler_spec.rb
|
131
|
+
- spec/component_compiler_spec.rb
|
126
132
|
- spec/generators/controller_generator_spec.rb
|
133
|
+
- spec/incorrect_ending_error_spec.rb
|
127
134
|
- spec/presenter_spec.rb
|
128
135
|
- spec/scanner_spec.rb
|
129
136
|
- spec/spec_helper.rb
|
@@ -145,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
152
|
version: '0'
|
146
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
154
|
requirements:
|
148
|
-
- - "
|
155
|
+
- - ">"
|
149
156
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
157
|
+
version: 1.3.1
|
151
158
|
requirements: []
|
152
159
|
rubyforge_project:
|
153
160
|
rubygems_version: 2.2.2
|
@@ -155,8 +162,12 @@ signing_key:
|
|
155
162
|
specification_version: 2
|
156
163
|
summary: Free your views!
|
157
164
|
test_files:
|
165
|
+
- spec/attribute_parser_spec.rb
|
166
|
+
- spec/compiler/collections_spec.rb
|
158
167
|
- spec/compiler_spec.rb
|
168
|
+
- spec/component_compiler_spec.rb
|
159
169
|
- spec/generators/controller_generator_spec.rb
|
170
|
+
- spec/incorrect_ending_error_spec.rb
|
160
171
|
- spec/presenter_spec.rb
|
161
172
|
- spec/scanner_spec.rb
|
162
173
|
- spec/syntax_error_spec.rb
|