curly-templates 2.0.1 → 2.1.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +2 -0
  4. data/README.md +85 -5
  5. data/curly-templates.gemspec +37 -8
  6. data/lib/curly.rb +1 -1
  7. data/lib/curly/{attribute_parser.rb → attribute_scanner.rb} +6 -4
  8. data/lib/curly/compiler.rb +81 -72
  9. data/lib/curly/component_compiler.rb +37 -31
  10. data/lib/curly/component_scanner.rb +19 -0
  11. data/lib/curly/incomplete_block_error.rb +0 -7
  12. data/lib/curly/incorrect_ending_error.rb +0 -21
  13. data/lib/curly/parser.rb +171 -0
  14. data/lib/curly/presenter.rb +1 -1
  15. data/lib/curly/scanner.rb +23 -9
  16. data/spec/attribute_scanner_spec.rb +46 -0
  17. data/spec/collection_blocks_spec.rb +88 -0
  18. data/spec/compiler/context_blocks_spec.rb +42 -0
  19. data/spec/component_compiler_spec.rb +26 -77
  20. data/spec/component_scanner_spec.rb +19 -0
  21. data/spec/{integration/components_spec.rb → components_spec.rb} +0 -0
  22. data/spec/{integration/conditional_blocks_spec.rb → conditional_blocks_spec.rb} +0 -0
  23. data/spec/dummy/.gitignore +1 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  25. data/spec/dummy/app/controllers/dashboards_controller.rb +13 -0
  26. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  27. data/spec/dummy/app/presenters/dashboards/collection_presenter.rb +7 -0
  28. data/spec/dummy/app/presenters/dashboards/item_presenter.rb +7 -0
  29. data/spec/dummy/app/presenters/dashboards/new_presenter.rb +19 -0
  30. data/spec/dummy/app/presenters/dashboards/partials_presenter.rb +5 -0
  31. data/spec/dummy/app/presenters/dashboards/show_presenter.rb +12 -0
  32. data/spec/dummy/app/presenters/layouts/application_presenter.rb +9 -0
  33. data/spec/dummy/app/views/dashboards/_item.html.curly +1 -0
  34. data/spec/dummy/app/views/dashboards/collection.html.curly +5 -0
  35. data/spec/dummy/app/views/dashboards/new.html.curly +3 -0
  36. data/spec/dummy/app/views/dashboards/partials.html.curly +3 -0
  37. data/spec/dummy/app/views/dashboards/show.html.curly +3 -0
  38. data/spec/dummy/app/views/layouts/application.html.curly +8 -0
  39. data/spec/dummy/config.ru +4 -0
  40. data/spec/dummy/config/application.rb +12 -0
  41. data/spec/dummy/config/boot.rb +5 -0
  42. data/spec/dummy/config/environment.rb +5 -0
  43. data/spec/dummy/config/environments/test.rb +36 -0
  44. data/spec/dummy/config/routes.rb +6 -0
  45. data/spec/integration/application_layout_spec.rb +21 -0
  46. data/spec/integration/collection_blocks_spec.rb +17 -78
  47. data/spec/integration/context_blocks_spec.rb +21 -0
  48. data/spec/integration/partials_spec.rb +23 -0
  49. data/spec/parser_spec.rb +95 -0
  50. data/spec/scanner_spec.rb +24 -14
  51. data/spec/spec_helper.rb +4 -3
  52. metadata +49 -14
  53. data/lib/curly/component_parser.rb +0 -13
  54. data/spec/attribute_parser_spec.rb +0 -46
  55. data/spec/incorrect_ending_error_spec.rb +0 -13
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,36 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = 'public, max-age=3600'
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Print deprecation notices to the stderr.
30
+ config.active_support.deprecation = :stderr
31
+
32
+ # Raises error for missing translations
33
+ # config.action_view.raise_on_missing_translations = true
34
+
35
+ config.secret_key_base = "yolo"
36
+ end
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ root to: "dashboards#show"
3
+ get "/collection", to: "dashboards#collection"
4
+ get "/partials", to: "dashboards#partials"
5
+ get "/new", to: "dashboards#new"
6
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Using Curly for the application layout", type: :request do
4
+ example "A simple layout view" do
5
+ get '/'
6
+
7
+ response.body.should == <<-HTML.strip_heredoc
8
+ <html>
9
+ <head>
10
+ <title>Dummy app</title>
11
+ </head>
12
+ <body>
13
+ <h1>Dashboard</h1>
14
+ <p>Hello, World!</p>
15
+ <p>Welcome!</p>
16
+
17
+ </body>
18
+ </html>
19
+ HTML
20
+ end
21
+ end
@@ -1,88 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Collection block components" do
4
- include RenderingSupport
3
+ describe "Collection blocks", type: :request do
4
+ example "Rendering collections" do
5
+ get '/collection'
5
6
 
6
- before do
7
- item_presenter do
8
- presents :item
7
+ response.body.should == <<-HTML.strip_heredoc
8
+ <html>
9
+ <head>
10
+ <title>Dummy app</title>
11
+ </head>
12
+ <body>
13
+ <ul>
9
14
 
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
15
+ <li>uno</li>
50
16
 
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
17
+ <li>dos</li>
69
18
 
70
- part_presenter do
71
- presents :part
19
+ <li>tres!</li>
72
20
 
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
21
+ </ul>
84
22
 
85
- def part_presenter(&block)
86
- stub_const("ItemPresenter::PartPresenter", Class.new(Curly::Presenter, &block))
23
+ </body>
24
+ </html>
25
+ HTML
87
26
  end
88
27
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Context blocks", type: :request do
4
+ example "A context block" do
5
+ get '/new'
6
+
7
+ response.body.should == <<-HTML.strip_heredoc
8
+ <html>
9
+ <head>
10
+ <title>Dummy app</title>
11
+ </head>
12
+ <body>
13
+ <form accept-charset="UTF-8" action="/new" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div>
14
+ <b>Name</b> <input id="dashboard_name" name="dashboard[name]" type="text" value="test" />
15
+ </form>
16
+
17
+ </body>
18
+ </html>
19
+ HTML
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Using Curly for Rails partials", type: :request do
4
+ example "Rendering a partial" do
5
+ get '/partials'
6
+
7
+ response.body.should == <<-HTML.strip_heredoc
8
+ <html>
9
+ <head>
10
+ <title>Dummy app</title>
11
+ </head>
12
+ <body>
13
+ <ul>
14
+ <li>One</li>
15
+ <li>Two</li>
16
+
17
+ </ul>
18
+
19
+ </body>
20
+ </html>
21
+ HTML
22
+ end
23
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+ require 'curly/parser'
3
+
4
+ describe Curly::Parser do
5
+ it "parses component tokens" do
6
+ tokens = [
7
+ [:component, "a", nil, {}],
8
+ ]
9
+
10
+ parse(tokens).should == [
11
+ component("a")
12
+ ]
13
+ end
14
+
15
+ it "parses conditional blocks" do
16
+ tokens = [
17
+ [:conditional_block_start, "a?", nil, {}],
18
+ [:component, "hello", nil, {}],
19
+ [:block_end, "a?", nil],
20
+ ]
21
+
22
+ parse(tokens).should == [
23
+ conditional_block(component("a?"), [component("hello")])
24
+ ]
25
+ end
26
+
27
+ it "parses inverse conditional blocks" do
28
+ tokens = [
29
+ [:inverse_conditional_block_start, "a?", nil, {}],
30
+ [:component, "hello", nil, {}],
31
+ [:block_end, "a?", nil],
32
+ ]
33
+
34
+ parse(tokens).should == [
35
+ inverse_conditional_block(component("a?"), [component("hello")])
36
+ ]
37
+ end
38
+
39
+ it "parses collection blocks" do
40
+ tokens = [
41
+ [:collection_block_start, "mice", nil, {}],
42
+ [:component, "hello", nil, {}],
43
+ [:block_end, "mice", nil],
44
+ ]
45
+
46
+ parse(tokens).should == [
47
+ collection_block(component("mice"), [component("hello")])
48
+ ]
49
+ end
50
+
51
+ it "fails if a block is not closed" do
52
+ tokens = [
53
+ [:collection_block_start, "mice", nil, {}],
54
+ ]
55
+
56
+ expect { parse(tokens) }.to raise_exception(Curly::IncompleteBlockError)
57
+ end
58
+
59
+ it "fails if a block is closed with the wrong component" do
60
+ tokens = [
61
+ [:collection_block_start, "mice", nil, {}],
62
+ [:block_end, "men", nil, {}],
63
+ ]
64
+
65
+ expect { parse(tokens) }.to raise_exception(Curly::IncorrectEndingError)
66
+ end
67
+
68
+ it "fails if there is a closing component too many" do
69
+ tokens = [
70
+ [:block_end, "world", nil, {}],
71
+ ]
72
+
73
+ expect { parse(tokens) }.to raise_exception(Curly::IncorrectEndingError)
74
+ end
75
+
76
+ def parse(tokens)
77
+ described_class.parse(tokens)
78
+ end
79
+
80
+ def component(*args)
81
+ Curly::Parser::Component.new(*args)
82
+ end
83
+
84
+ def conditional_block(*args)
85
+ Curly::Parser::Block.new(:conditional, *args)
86
+ end
87
+
88
+ def inverse_conditional_block(*args)
89
+ Curly::Parser::Block.new(:inverse_conditional, *args)
90
+ end
91
+
92
+ def collection_block(*args)
93
+ Curly::Parser::Block.new(:collection, *args)
94
+ end
95
+ end
@@ -4,20 +4,14 @@ 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
- [:component, "bar"],
7
+ [:component, "bar", nil, {}],
8
8
  [:text, " baz"]
9
9
  ]
10
10
  end
11
11
 
12
12
  it "scans components with identifiers" do
13
13
  scan("{{foo.bar}}").should == [
14
- [:component, "foo.bar"]
15
- ]
16
- end
17
-
18
- it "allows components with whitespace" do
19
- scan("{{ foo bar}}").should == [
20
- [:component, " foo bar"]
14
+ [:component, "foo", "bar", {}]
21
15
  ]
22
16
  end
23
17
 
@@ -59,30 +53,46 @@ describe Curly::Scanner, ".scan" do
59
53
  ]
60
54
  end
61
55
 
56
+ it "scans context block tags" do
57
+ scan('{{@search_form}}{{query_field}}{{/search_form}}').should == [
58
+ [:context_block_start, "search_form", nil, {}],
59
+ [:component, "query_field", nil, {}],
60
+ [:block_end, "search_form", nil]
61
+ ]
62
+ end
63
+
62
64
  it "scans conditional block tags" do
63
65
  scan('foo {{#bar?}} hello {{/bar?}}').should == [
64
66
  [:text, "foo "],
65
- [:conditional_block_start, "bar?"],
67
+ [:conditional_block_start, "bar?", nil, {}],
66
68
  [:text, " hello "],
67
- [:conditional_block_end, "bar?"]
69
+ [:block_end, "bar?", nil]
70
+ ]
71
+ end
72
+
73
+ it "scans conditional block tags with parameters and attributes" do
74
+ scan('{{#active.test? name="test"}}yo{{/active.test?}}').should == [
75
+ [:conditional_block_start, "active?", "test", { "name" => "test" }],
76
+ [:text, "yo"],
77
+ [:block_end, "active?", "test"]
68
78
  ]
69
79
  end
70
80
 
71
81
  it "scans inverse block tags" do
72
82
  scan('foo {{^bar?}} hello {{/bar?}}').should == [
73
83
  [:text, "foo "],
74
- [:inverse_conditional_block_start, "bar?"],
84
+ [:inverse_conditional_block_start, "bar?", nil, {}],
75
85
  [:text, " hello "],
76
- [:conditional_block_end, "bar?"]
86
+ [:block_end, "bar?", nil]
77
87
  ]
78
88
  end
79
89
 
80
90
  it "scans collection block tags" do
81
91
  scan('foo {{*bar}} hello {{/bar}}').should == [
82
92
  [:text, "foo "],
83
- [:collection_block_start, "bar"],
93
+ [:collection_block_start, "bar", nil, {}],
84
94
  [:text, " hello "],
85
- [:collection_block_end, "bar"]
95
+ [:block_end, "bar", nil]
86
96
  ]
87
97
  end
88
98
 
@@ -1,4 +1,7 @@
1
- require 'active_support/all'
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require 'dummy/config/environment'
4
+ require 'rspec/rails'
2
5
 
3
6
  if ENV['CI']
4
7
  begin
@@ -9,8 +12,6 @@ if ENV['CI']
9
12
  end
10
13
  end
11
14
 
12
- require 'curly'
13
-
14
15
  module RenderingSupport
15
16
  def presenter(&block)
16
17
  @presenter = block
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.1
4
+ version: 2.1.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-09-09 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -106,15 +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
+ - lib/curly/attribute_scanner.rb
110
110
  - lib/curly/compiler.rb
111
111
  - lib/curly/component_compiler.rb
112
- - lib/curly/component_parser.rb
112
+ - lib/curly/component_scanner.rb
113
113
  - lib/curly/dependency_tracker.rb
114
114
  - lib/curly/error.rb
115
115
  - lib/curly/incomplete_block_error.rb
116
116
  - lib/curly/incorrect_ending_error.rb
117
117
  - lib/curly/invalid_component.rb
118
+ - lib/curly/parser.rb
118
119
  - lib/curly/presenter.rb
119
120
  - lib/curly/presenter_not_found.rb
120
121
  - lib/curly/railtie.rb
@@ -125,15 +126,43 @@ files:
125
126
  - lib/generators/curly/controller/templates/presenter.rb.erb
126
127
  - lib/generators/curly/controller/templates/view.html.curly.erb
127
128
  - lib/rails/projections.json
128
- - spec/attribute_parser_spec.rb
129
+ - spec/attribute_scanner_spec.rb
130
+ - spec/collection_blocks_spec.rb
129
131
  - spec/compiler/collections_spec.rb
132
+ - spec/compiler/context_blocks_spec.rb
130
133
  - spec/compiler_spec.rb
131
134
  - spec/component_compiler_spec.rb
135
+ - spec/component_scanner_spec.rb
136
+ - spec/components_spec.rb
137
+ - spec/conditional_blocks_spec.rb
138
+ - spec/dummy/.gitignore
139
+ - spec/dummy/app/controllers/application_controller.rb
140
+ - spec/dummy/app/controllers/dashboards_controller.rb
141
+ - spec/dummy/app/helpers/application_helper.rb
142
+ - spec/dummy/app/presenters/dashboards/collection_presenter.rb
143
+ - spec/dummy/app/presenters/dashboards/item_presenter.rb
144
+ - spec/dummy/app/presenters/dashboards/new_presenter.rb
145
+ - spec/dummy/app/presenters/dashboards/partials_presenter.rb
146
+ - spec/dummy/app/presenters/dashboards/show_presenter.rb
147
+ - spec/dummy/app/presenters/layouts/application_presenter.rb
148
+ - spec/dummy/app/views/dashboards/_item.html.curly
149
+ - spec/dummy/app/views/dashboards/collection.html.curly
150
+ - spec/dummy/app/views/dashboards/new.html.curly
151
+ - spec/dummy/app/views/dashboards/partials.html.curly
152
+ - spec/dummy/app/views/dashboards/show.html.curly
153
+ - spec/dummy/app/views/layouts/application.html.curly
154
+ - spec/dummy/config.ru
155
+ - spec/dummy/config/application.rb
156
+ - spec/dummy/config/boot.rb
157
+ - spec/dummy/config/environment.rb
158
+ - spec/dummy/config/environments/test.rb
159
+ - spec/dummy/config/routes.rb
132
160
  - spec/generators/controller_generator_spec.rb
133
- - spec/incorrect_ending_error_spec.rb
161
+ - spec/integration/application_layout_spec.rb
134
162
  - spec/integration/collection_blocks_spec.rb
135
- - spec/integration/components_spec.rb
136
- - spec/integration/conditional_blocks_spec.rb
163
+ - spec/integration/context_blocks_spec.rb
164
+ - spec/integration/partials_spec.rb
165
+ - spec/parser_spec.rb
137
166
  - spec/presenter_spec.rb
138
167
  - spec/scanner_spec.rb
139
168
  - spec/spec_helper.rb
@@ -155,9 +184,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
184
  version: '0'
156
185
  required_rubygems_version: !ruby/object:Gem::Requirement
157
186
  requirements:
158
- - - ">="
187
+ - - ">"
159
188
  - !ruby/object:Gem::Version
160
- version: '0'
189
+ version: 1.3.1
161
190
  requirements: []
162
191
  rubyforge_project:
163
192
  rubygems_version: 2.2.2
@@ -165,15 +194,21 @@ signing_key:
165
194
  specification_version: 2
166
195
  summary: Free your views!
167
196
  test_files:
168
- - spec/attribute_parser_spec.rb
197
+ - spec/attribute_scanner_spec.rb
198
+ - spec/collection_blocks_spec.rb
169
199
  - spec/compiler/collections_spec.rb
200
+ - spec/compiler/context_blocks_spec.rb
170
201
  - spec/compiler_spec.rb
171
202
  - spec/component_compiler_spec.rb
203
+ - spec/component_scanner_spec.rb
204
+ - spec/components_spec.rb
205
+ - spec/conditional_blocks_spec.rb
172
206
  - spec/generators/controller_generator_spec.rb
173
- - spec/incorrect_ending_error_spec.rb
207
+ - spec/integration/application_layout_spec.rb
174
208
  - spec/integration/collection_blocks_spec.rb
175
- - spec/integration/components_spec.rb
176
- - spec/integration/conditional_blocks_spec.rb
209
+ - spec/integration/context_blocks_spec.rb
210
+ - spec/integration/partials_spec.rb
211
+ - spec/parser_spec.rb
177
212
  - spec/presenter_spec.rb
178
213
  - spec/scanner_spec.rb
179
214
  - spec/syntax_error_spec.rb