curly-templates 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +4 -0
- data/curly-templates.gemspec +5 -2
- data/lib/curly.rb +1 -1
- data/lib/curly/presenter.rb +6 -2
- data/perf/compile_benchmark.rb +71 -0
- data/perf/compile_profile.rb +64 -0
- data/perf/component_benchmark.rb +41 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f038cf925ee66f41bb273477733836d3be22594
|
4
|
+
data.tar.gz: 8d39cf352d8638c847154ce3fdccbcbfca9ae4a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8616749a1fe10664053e2048059a19618ad2b5d6878fce96587b39cc7322565349099ece2e40737f55404ee84de4e041227270f0be18e02de0fd2a2627d42979
|
7
|
+
data.tar.gz: 59036f8b9086a6196ba1c99291e6701f2f99735cc45dbc23b80c00123662618b71ae7f233cd814a66a8ef93a15bdd70341ee2cafb463b46be8f9a39e4cec120c
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -101,6 +101,10 @@ render comment
|
|
101
101
|
render collection: post.comments
|
102
102
|
```
|
103
103
|
|
104
|
+
Curly _components_ are surrounded by curly brackets, e.g. `{{hello}}`. They always map to a
|
105
|
+
public method on the presenter class, in this case `#hello`. Methods ending in a question mark
|
106
|
+
can be used for [conditional blocks](#conditional-blocks), e.g. `{{#admin?}} ... {{/admin?}}`.
|
107
|
+
|
104
108
|
### Identifiers
|
105
109
|
|
106
110
|
Curly components can specify an _identifier_ using the so-called dot notation: `{{x.y.z}}`.
|
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.4.
|
8
|
-
s.date = '2015-
|
7
|
+
s.version = '2.4.1'
|
8
|
+
s.date = '2015-04-27'
|
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."
|
@@ -57,6 +57,9 @@ Gem::Specification.new do |s|
|
|
57
57
|
lib/generators/curly/controller/templates/presenter.rb.erb
|
58
58
|
lib/generators/curly/controller/templates/view.html.curly.erb
|
59
59
|
lib/rails/projections.json
|
60
|
+
perf/compile_benchmark.rb
|
61
|
+
perf/compile_profile.rb
|
62
|
+
perf/component_benchmark.rb
|
60
63
|
spec/attribute_scanner_spec.rb
|
61
64
|
spec/collection_blocks_spec.rb
|
62
65
|
spec/compiler/collections_spec.rb
|
data/lib/curly.rb
CHANGED
data/lib/curly/presenter.rb
CHANGED
@@ -211,8 +211,10 @@ module Curly
|
|
211
211
|
#
|
212
212
|
# Returns an Array of String component names.
|
213
213
|
def available_components
|
214
|
-
|
215
|
-
|
214
|
+
@_available_components ||= begin
|
215
|
+
methods = public_instance_methods - Curly::Presenter.public_instance_methods
|
216
|
+
methods.map(&:to_s)
|
217
|
+
end
|
216
218
|
end
|
217
219
|
|
218
220
|
# The set of view paths that the presenter depends on.
|
@@ -311,6 +313,8 @@ module Curly
|
|
311
313
|
self.presented_names = [].freeze
|
312
314
|
self.default_values = {}.freeze
|
313
315
|
|
316
|
+
delegate :render, to: :@_context
|
317
|
+
|
314
318
|
# Delegates private method calls to the current view context.
|
315
319
|
#
|
316
320
|
# The view context, an instance of ActionView::Base, is set by Rails.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'benchmark/ips'
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
|
6
|
+
require_relative '../spec/dummy/config/environment'
|
7
|
+
|
8
|
+
class TestPresenter < Curly::Presenter
|
9
|
+
def foo
|
10
|
+
end
|
11
|
+
|
12
|
+
def bar
|
13
|
+
end
|
14
|
+
|
15
|
+
def form(&block)
|
16
|
+
xcontent_tag :form, block.call
|
17
|
+
end
|
18
|
+
|
19
|
+
class FormPresenter < Curly::Presenter
|
20
|
+
def fields
|
21
|
+
%w[]
|
22
|
+
end
|
23
|
+
|
24
|
+
class FieldPresenter < Curly::Presenter
|
25
|
+
presents :field
|
26
|
+
|
27
|
+
def field_name
|
28
|
+
@field
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Build a huge template.
|
35
|
+
TEMPLATE = <<-CURLY
|
36
|
+
<h1>{{foo}}</h1>
|
37
|
+
<h2>{{bar}}</h2>
|
38
|
+
|
39
|
+
{{@form}}
|
40
|
+
{{*fields}}
|
41
|
+
<input name={{field_name}}><br>
|
42
|
+
{{/fields}}
|
43
|
+
{{*fields}}
|
44
|
+
<input name={{field_name}}><br>
|
45
|
+
{{/fields}}
|
46
|
+
{{*fields}}
|
47
|
+
<input name={{field_name}}><br>
|
48
|
+
{{/fields}}
|
49
|
+
{{*fields}}
|
50
|
+
<input name={{field_name}}><br>
|
51
|
+
{{/fields}}
|
52
|
+
{{*fields}}
|
53
|
+
<input name={{field_name}}><br>
|
54
|
+
{{/fields}}
|
55
|
+
{{*fields}}
|
56
|
+
<input name={{field_name}}><br>
|
57
|
+
{{/fields}}
|
58
|
+
{{/form}}
|
59
|
+
CURLY
|
60
|
+
|
61
|
+
Benchmark.ips do |x|
|
62
|
+
x.report "compiling a huge template" do
|
63
|
+
Curly::Compiler.compile(TEMPLATE * 100, TestPresenter)
|
64
|
+
end
|
65
|
+
|
66
|
+
x.report "compiling a normal template" do
|
67
|
+
Curly::Compiler.compile(TEMPLATE, TestPresenter)
|
68
|
+
end
|
69
|
+
|
70
|
+
x.compare!
|
71
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'benchmark/ips'
|
3
|
+
require 'stackprof'
|
4
|
+
|
5
|
+
ENV["RAILS_ENV"] = "test"
|
6
|
+
|
7
|
+
require_relative '../spec/dummy/config/environment'
|
8
|
+
|
9
|
+
class TestPresenter < Curly::Presenter
|
10
|
+
def foo
|
11
|
+
end
|
12
|
+
|
13
|
+
def bar
|
14
|
+
end
|
15
|
+
|
16
|
+
def form(&block)
|
17
|
+
xcontent_tag :form, block.call
|
18
|
+
end
|
19
|
+
|
20
|
+
class FormPresenter < Curly::Presenter
|
21
|
+
def fields
|
22
|
+
%w[]
|
23
|
+
end
|
24
|
+
|
25
|
+
class FieldPresenter < Curly::Presenter
|
26
|
+
presents :field
|
27
|
+
|
28
|
+
def field_name
|
29
|
+
@field
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Build a huge template.
|
36
|
+
TEMPLATE = <<-CURLY
|
37
|
+
<h1>{{foo}}</h1>
|
38
|
+
<h2>{{bar}}</h2>
|
39
|
+
|
40
|
+
{{@form}}
|
41
|
+
{{*fields}}
|
42
|
+
<input name={{field_name}}><br>
|
43
|
+
{{/fields}}
|
44
|
+
{{*fields}}
|
45
|
+
<input name={{field_name}}><br>
|
46
|
+
{{/fields}}
|
47
|
+
{{*fields}}
|
48
|
+
<input name={{field_name}}><br>
|
49
|
+
{{/fields}}
|
50
|
+
{{*fields}}
|
51
|
+
<input name={{field_name}}><br>
|
52
|
+
{{/fields}}
|
53
|
+
{{*fields}}
|
54
|
+
<input name={{field_name}}><br>
|
55
|
+
{{/fields}}
|
56
|
+
{{*fields}}
|
57
|
+
<input name={{field_name}}><br>
|
58
|
+
{{/fields}}
|
59
|
+
{{/form}}
|
60
|
+
CURLY
|
61
|
+
|
62
|
+
StackProf.run(mode: :cpu, out: "tmp/stackprof-cpu-compile.dump") do
|
63
|
+
Curly::Compiler.compile(TEMPLATE * 100, TestPresenter)
|
64
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'benchmark/ips'
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
|
6
|
+
require_relative '../spec/dummy/config/environment'
|
7
|
+
|
8
|
+
class TestPresenter < Curly::Presenter
|
9
|
+
def hello_with_delegation
|
10
|
+
some_helper
|
11
|
+
end
|
12
|
+
|
13
|
+
def hello_without_delegation
|
14
|
+
not_some_helper
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def not_some_helper
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TestContext
|
24
|
+
def some_helper
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context = TestContext.new
|
29
|
+
presenter = TestPresenter.new(context)
|
30
|
+
|
31
|
+
Benchmark.ips do |x|
|
32
|
+
x.report "presenter method that delegates to the view context" do
|
33
|
+
presenter.hello_with_delegation
|
34
|
+
end
|
35
|
+
|
36
|
+
x.report "presenter method that doesn't delegate to the view context" do
|
37
|
+
presenter.hello_without_delegation
|
38
|
+
end
|
39
|
+
|
40
|
+
x.compare!
|
41
|
+
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: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -127,6 +127,9 @@ files:
|
|
127
127
|
- lib/generators/curly/controller/templates/presenter.rb.erb
|
128
128
|
- lib/generators/curly/controller/templates/view.html.curly.erb
|
129
129
|
- lib/rails/projections.json
|
130
|
+
- perf/compile_benchmark.rb
|
131
|
+
- perf/compile_profile.rb
|
132
|
+
- perf/component_benchmark.rb
|
130
133
|
- spec/attribute_scanner_spec.rb
|
131
134
|
- spec/collection_blocks_spec.rb
|
132
135
|
- spec/compiler/collections_spec.rb
|