curly-templates 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/README.md +5 -0
- data/curly-templates.gemspec +2 -2
- data/lib/curly.rb +1 -1
- data/lib/curly/scanner.rb +11 -2
- data/lib/curly/template_handler.rb +26 -24
- data/spec/scanner_spec.rb +18 -0
- data/spec/template_handler_spec.rb +5 -0
- metadata +14 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a564172d0d4f15b3bae6c5f05579d5deb0fe845b
|
4
|
+
data.tar.gz: d28d0cf8d4998251a08d88fb13d3e44250a61a5c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b360305771e280435d7ad2cb0fd07cd982728223e83701af89411037c1f61926f02e0594aee6c7e696da369dae600dcd3aceb437fc82178d2250897bf8a8a67
|
7
|
+
data.tar.gz: 8a16c5647e0059ec808fc48e92a4f843530d4036b7a744cc6aef3f19d52ae149f6d20e27c327f215b4cb2df40522b32d97a1b88d7559f34c84fff6ad9a7f7fdd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
* Allow Curly to output Curly syntax by using the `{{{ ... }}` syntax:
|
4
|
+
|
5
|
+
```
|
6
|
+
{{{curly_example}}
|
7
|
+
```
|
8
|
+
|
9
|
+
*Daniel Schierbeck and Benjamin Quorning*
|
10
|
+
|
3
11
|
### Curly 0.11.0 (July 31, 2013)
|
4
12
|
|
5
13
|
* Make Curly raise an exception when a reference or comment is not closed.
|
data/README.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 = '0.
|
8
|
-
s.date = '2013-
|
7
|
+
s.version = '0.12.0'
|
8
|
+
s.date = '2013-12-03'
|
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."
|
data/lib/curly.rb
CHANGED
data/lib/curly/scanner.rb
CHANGED
@@ -11,6 +11,9 @@ module Curly
|
|
11
11
|
class Scanner
|
12
12
|
CURLY_START = /\{\{/
|
13
13
|
CURLY_END = /\}\}/
|
14
|
+
|
15
|
+
ESCAPED_CURLY_START = /\{\{\{/
|
16
|
+
|
14
17
|
COMMENT_MARKER = /!/
|
15
18
|
|
16
19
|
# Scans a Curly template for tokens.
|
@@ -45,7 +48,13 @@ module Curly
|
|
45
48
|
# Returns a two-element Array, the first element being the Symbol type of
|
46
49
|
# the token and the second being the String value.
|
47
50
|
def scan_token
|
48
|
-
scan_curly || scan_text
|
51
|
+
scan_escaped_curly || scan_curly || scan_text
|
52
|
+
end
|
53
|
+
|
54
|
+
def scan_escaped_curly
|
55
|
+
if @scanner.scan(ESCAPED_CURLY_START)
|
56
|
+
[:text, "{{"]
|
57
|
+
end
|
49
58
|
end
|
50
59
|
|
51
60
|
def scan_curly
|
@@ -99,7 +108,7 @@ module Curly
|
|
99
108
|
end
|
100
109
|
|
101
110
|
def scan_until_end_of_curly
|
102
|
-
if value = @scanner.scan_until(CURLY_END)
|
111
|
+
if value = @scanner.scan_until(CURLY_END)
|
103
112
|
value[0..-3]
|
104
113
|
end
|
105
114
|
end
|
@@ -19,6 +19,26 @@ class Curly::TemplateHandler
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def cache_if_key_is_not_nil(context, presenter)
|
23
|
+
if key = presenter.cache_key
|
24
|
+
if presenter.class.respond_to?(:cache_key)
|
25
|
+
presenter_key = presenter.class.cache_key
|
26
|
+
else
|
27
|
+
presenter_key = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
options = {
|
31
|
+
expires_in: presenter.cache_duration
|
32
|
+
}
|
33
|
+
|
34
|
+
context.cache([key, presenter_key].compact, options) do
|
35
|
+
yield
|
36
|
+
end
|
37
|
+
else
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
22
42
|
private
|
23
43
|
|
24
44
|
def compile(template)
|
@@ -40,34 +60,16 @@ class Curly::TemplateHandler
|
|
40
60
|
end
|
41
61
|
|
42
62
|
presenter = #{presenter_class}.new(self, options.with_indifferent_access)
|
43
|
-
|
44
|
-
view_function = lambda do
|
45
|
-
#{source}
|
46
|
-
end
|
47
|
-
|
48
63
|
presenter.setup!
|
49
64
|
|
50
|
-
|
51
|
-
@output_buffer = ActiveSupport::SafeBuffer.new
|
52
|
-
|
53
|
-
if #{presenter_class}.respond_to?(:cache_key)
|
54
|
-
presenter_key = #{presenter_class}.cache_key
|
55
|
-
else
|
56
|
-
presenter_key = nil
|
57
|
-
end
|
65
|
+
@output_buffer = output_buffer || ActiveSupport::SafeBuffer.new
|
58
66
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
cache([key, presenter_key].compact, options) do
|
64
|
-
safe_concat(view_function.call)
|
65
|
-
end
|
66
|
-
|
67
|
-
@output_buffer
|
68
|
-
else
|
69
|
-
view_function.call.html_safe
|
67
|
+
Curly::TemplateHandler.cache_if_key_is_not_nil(self, presenter) do
|
68
|
+
result = #{source}
|
69
|
+
safe_concat(result)
|
70
70
|
end
|
71
|
+
|
72
|
+
@output_buffer
|
71
73
|
RUBY
|
72
74
|
end
|
73
75
|
|
data/spec/scanner_spec.rb
CHANGED
@@ -41,6 +41,24 @@ describe Curly::Scanner, ".scan" do
|
|
41
41
|
]
|
42
42
|
end
|
43
43
|
|
44
|
+
it "allows escaping Curly quotes" do
|
45
|
+
scan('foo {{{ bar').should == [
|
46
|
+
[:text, "foo "],
|
47
|
+
[:text, "{{"],
|
48
|
+
[:text, " bar"]
|
49
|
+
]
|
50
|
+
|
51
|
+
scan('foo }} bar').should == [
|
52
|
+
[:text, "foo }} bar"]
|
53
|
+
]
|
54
|
+
|
55
|
+
scan('foo {{{ lala! }} bar').should == [
|
56
|
+
[:text, "foo "],
|
57
|
+
[:text, "{{"],
|
58
|
+
[:text, " lala! }} bar"]
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
44
62
|
it "treats quotes as text" do
|
45
63
|
scan('"').should == [
|
46
64
|
[:text, '"']
|
@@ -47,6 +47,10 @@ describe Curly::TemplateHandler do
|
|
47
47
|
@clock = 0
|
48
48
|
end
|
49
49
|
|
50
|
+
def reset!
|
51
|
+
@output_buffer = ActiveSupport::SafeBuffer.new
|
52
|
+
end
|
53
|
+
|
50
54
|
def advance_clock(duration)
|
51
55
|
@clock += duration
|
52
56
|
end
|
@@ -179,6 +183,7 @@ describe Curly::TemplateHandler do
|
|
179
183
|
|
180
184
|
def output
|
181
185
|
code = Curly::TemplateHandler.call(template)
|
186
|
+
context.reset!
|
182
187
|
context.instance_eval(code)
|
183
188
|
end
|
184
189
|
end
|
metadata
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curly-templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.12.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel Schierbeck
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: actionpack
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.1'
|
22
20
|
- - <
|
@@ -25,9 +23,8 @@ dependencies:
|
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '3.1'
|
33
30
|
- - <
|
@@ -36,9 +33,8 @@ dependencies:
|
|
36
33
|
- !ruby/object:Gem::Dependency
|
37
34
|
name: railties
|
38
35
|
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
36
|
requirements:
|
41
|
-
- -
|
37
|
+
- - '>='
|
42
38
|
- !ruby/object:Gem::Version
|
43
39
|
version: '3.1'
|
44
40
|
- - <
|
@@ -47,9 +43,8 @@ dependencies:
|
|
47
43
|
type: :development
|
48
44
|
prerelease: false
|
49
45
|
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
46
|
requirements:
|
52
|
-
- -
|
47
|
+
- - '>='
|
53
48
|
- !ruby/object:Gem::Version
|
54
49
|
version: '3.1'
|
55
50
|
- - <
|
@@ -58,23 +53,20 @@ dependencies:
|
|
58
53
|
- !ruby/object:Gem::Dependency
|
59
54
|
name: rake
|
60
55
|
requirement: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
56
|
requirements:
|
63
|
-
- -
|
57
|
+
- - '>='
|
64
58
|
- !ruby/object:Gem::Version
|
65
59
|
version: '0'
|
66
60
|
type: :development
|
67
61
|
prerelease: false
|
68
62
|
version_requirements: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
63
|
requirements:
|
71
|
-
- -
|
64
|
+
- - '>='
|
72
65
|
- !ruby/object:Gem::Version
|
73
66
|
version: '0'
|
74
67
|
- !ruby/object:Gem::Dependency
|
75
68
|
name: rspec
|
76
69
|
requirement: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
70
|
requirements:
|
79
71
|
- - ~>
|
80
72
|
- !ruby/object:Gem::Version
|
@@ -82,7 +74,6 @@ dependencies:
|
|
82
74
|
type: :development
|
83
75
|
prerelease: false
|
84
76
|
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
77
|
requirements:
|
87
78
|
- - ~>
|
88
79
|
- !ruby/object:Gem::Version
|
@@ -90,17 +81,15 @@ dependencies:
|
|
90
81
|
- !ruby/object:Gem::Dependency
|
91
82
|
name: genspec
|
92
83
|
requirement: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
84
|
requirements:
|
95
|
-
- -
|
85
|
+
- - '>='
|
96
86
|
- !ruby/object:Gem::Version
|
97
87
|
version: '0'
|
98
88
|
type: :development
|
99
89
|
prerelease: false
|
100
90
|
version_requirements: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
91
|
requirements:
|
103
|
-
- -
|
92
|
+
- - '>='
|
104
93
|
- !ruby/object:Gem::Version
|
105
94
|
version: '0'
|
106
95
|
description: A view layer for your Rails apps that separates structure and logic.
|
@@ -139,29 +128,25 @@ files:
|
|
139
128
|
homepage: https://github.com/zendesk/curly
|
140
129
|
licenses:
|
141
130
|
- apache2
|
131
|
+
metadata: {}
|
142
132
|
post_install_message:
|
143
133
|
rdoc_options:
|
144
134
|
- --charset=UTF-8
|
145
135
|
require_paths:
|
146
136
|
- lib
|
147
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
-
none: false
|
149
138
|
requirements:
|
150
|
-
- -
|
139
|
+
- - '>='
|
151
140
|
- !ruby/object:Gem::Version
|
152
141
|
version: '0'
|
153
|
-
segments:
|
154
|
-
- 0
|
155
|
-
hash: 1896340551249669380
|
156
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
-
none: false
|
158
143
|
requirements:
|
159
|
-
- -
|
144
|
+
- - '>='
|
160
145
|
- !ruby/object:Gem::Version
|
161
146
|
version: '0'
|
162
147
|
requirements: []
|
163
148
|
rubyforge_project:
|
164
|
-
rubygems_version: 1.
|
149
|
+
rubygems_version: 2.1.11
|
165
150
|
signing_key:
|
166
151
|
specification_version: 2
|
167
152
|
summary: Free your views!
|