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.
@@ -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
@@ -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 parameters as instance variables" do
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 parameter is not specified" do
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 parameter `champagne` missing")
45
+ }.to raise_exception(ArgumentError, "required identifier `champagne` missing")
43
46
  end
44
47
 
45
- it "allows specifying default values for parameters" do
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 ".available_methods" do
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.available_methods.should include(:midget)
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.available_methods.should_not include(:cache_key)
101
+ CircusPresenter.available_components.should_not include("cache_key")
85
102
  end
86
103
  end
87
104
 
88
- describe ".method_available?" do
105
+ describe ".component_available?" do
89
106
  it "returns true if the method is available" do
90
- CircusPresenter.method_available?(:midget).should be_true
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.method_available?(:bear).should be_false
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
- [:reference, "bar"],
7
+ [:component, "bar"],
8
8
  [:text, " baz"]
9
9
  ]
10
10
  end
11
11
 
12
- it "scans parameterized references" do
12
+ it "scans components with identifiers" do
13
13
  scan("{{foo.bar}}").should == [
14
- [:reference, "foo.bar"]
14
+ [:component, "foo.bar"]
15
15
  ]
16
16
  end
17
17
 
18
- it "allows references with whitespace" do
18
+ it "allows components with whitespace" do
19
19
  scan("{{ foo bar}}").should == [
20
- [:reference, " foo bar"]
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
- [:block_start, "bar"],
65
+ [:conditional_block_start, "bar?"],
66
66
  [:text, " hello "],
67
- [:block_end, "bar"]
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
- [:inverse_block_start, "bar"],
74
+ [:inverse_conditional_block_start, "bar?"],
75
75
  [:text, " hello "],
76
- [:block_end, "bar"]
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 references" do
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
@@ -29,7 +29,7 @@ describe Curly::TemplateHandler do
29
29
  @cache_duration
30
30
  end
31
31
 
32
- def self.method_available?(method)
32
+ def self.component_available?(method)
33
33
  true
34
34
  end
35
35
  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: 1.0.1
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-24 00:00:00.000000000 Z
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/invalid_reference.rb
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: '0'
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
@@ -1,13 +0,0 @@
1
- module Curly
2
- class InvalidReference < Error
3
- attr_reader :reference
4
-
5
- def initialize(reference)
6
- @reference = reference
7
- end
8
-
9
- def message
10
- "invalid reference `{{#{reference}}}'"
11
- end
12
- end
13
- end