curly-templates 2.5.0 → 2.6.0
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/.gitignore +20 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +28 -0
- data/Gemfile +4 -2
- data/README.md +76 -3
- data/Rakefile +3 -116
- data/circle.yml +1 -1
- data/curly-templates.gemspec +6 -83
- data/lib/curly.rb +1 -1
- data/lib/curly/compiler.rb +2 -12
- data/lib/curly/component_compiler.rb +6 -3
- data/lib/curly/presenter.rb +32 -20
- data/lib/curly/presenter_name_error.rb +16 -0
- data/lib/curly/rspec.rb +16 -0
- data/lib/curly/version.rb +3 -0
- metadata +14 -72
- data/perf/compile_benchmark.rb +0 -71
- data/perf/compile_profile.rb +0 -64
- data/perf/component_benchmark.rb +0 -41
- data/spec/attribute_scanner_spec.rb +0 -44
- data/spec/collection_blocks_spec.rb +0 -78
- data/spec/compiler/collections_spec.rb +0 -230
- data/spec/compiler/context_blocks_spec.rb +0 -106
- data/spec/compiler_spec.rb +0 -192
- data/spec/component_compiler_spec.rb +0 -107
- data/spec/component_scanner_spec.rb +0 -36
- data/spec/components_spec.rb +0 -43
- data/spec/conditional_blocks_spec.rb +0 -40
- data/spec/dummy/.gitignore +0 -1
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/dashboards_controller.rb +0 -14
- data/spec/dummy/app/helpers/application_helper.rb +0 -5
- data/spec/dummy/app/presenters/dashboards/collection_presenter.rb +0 -7
- data/spec/dummy/app/presenters/dashboards/item_presenter.rb +0 -23
- data/spec/dummy/app/presenters/dashboards/new_presenter.rb +0 -29
- data/spec/dummy/app/presenters/dashboards/partials_presenter.rb +0 -5
- data/spec/dummy/app/presenters/dashboards/show_presenter.rb +0 -12
- data/spec/dummy/app/presenters/layouts/application_presenter.rb +0 -21
- data/spec/dummy/app/views/dashboards/_item.html.curly +0 -1
- data/spec/dummy/app/views/dashboards/collection.html.curly +0 -8
- data/spec/dummy/app/views/dashboards/new.html.curly +0 -7
- data/spec/dummy/app/views/dashboards/partials.html.curly +0 -3
- data/spec/dummy/app/views/dashboards/show.html.curly +0 -3
- data/spec/dummy/app/views/layouts/application.html.curly +0 -11
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -12
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/routes.rb +0 -6
- data/spec/generators/controller_generator_spec.rb +0 -34
- data/spec/integration/application_layout_spec.rb +0 -22
- data/spec/integration/collection_blocks_spec.rb +0 -37
- data/spec/integration/context_blocks_spec.rb +0 -27
- data/spec/integration/partials_spec.rb +0 -24
- data/spec/matchers/have_structure.rb +0 -29
- data/spec/parser_spec.rb +0 -92
- data/spec/presenter_spec.rb +0 -247
- data/spec/scanner_spec.rb +0 -124
- data/spec/spec_helper.rb +0 -45
- data/spec/syntax_error_spec.rb +0 -12
- data/spec/template_handler_spec.rb +0 -209
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dc47b05807f9a31c5c14d714c1f2edc3b0f8544
|
4
|
+
data.tar.gz: 79e7274d887bde4a5078e2573fa923682b58aa2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51eff4770731f8c3aadf3342595c0d8e513d0931790443bb0b8372376bf4893fc3c0ce82ad78542f1c70cc5aba151b696d7c7fda61c5e3e2f76b2b2c0ca41c62
|
7
|
+
data.tar.gz: 67015325572d49db533fab92f11319670074531ef424bb5182124e3d0ce3f85413338b488b000673566e05e80aca15ec99ce7886f6e3c06145d731e82f1723cf
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-r spec_helper
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### Curly 2.6.0 (July 4, 2016)
|
4
|
+
|
5
|
+
* Add support for Rails 5.
|
6
|
+
|
7
|
+
* Add support for arbitrary component attributes. If the presenter method accepts
|
8
|
+
arbitrary keyword arguments, the corresponding component is allowed to pass
|
9
|
+
any attribute it wants.
|
10
|
+
|
11
|
+
*Jeremy Rodi*
|
12
|
+
|
13
|
+
* Add support for testing presenters with RSpec:
|
14
|
+
|
15
|
+
```ruby\
|
16
|
+
require 'curly/rspec'
|
17
|
+
|
18
|
+
# spec/presenters/posts/show_presenter_spec.rb
|
19
|
+
describe Posts::ShowPresenter, type: :presenter do
|
20
|
+
describe "#body" do
|
21
|
+
it "renders the post's body as Markdown" do
|
22
|
+
assign(:post, double(:post, body: "**hello!**"))
|
23
|
+
expect(presenter.body).to eq "<strong>hello!</strong>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
*Daniel Schierbeck*
|
30
|
+
|
3
31
|
### Curly 2.5.0 (May 19, 2015)
|
4
32
|
|
5
33
|
* Allow passing a block as the `default:` option to `presents`.
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
@@ -7,8 +7,10 @@ platform :ruby do
|
|
7
7
|
gem 'yard-tomdoc'
|
8
8
|
gem 'redcarpet'
|
9
9
|
gem 'github-markup'
|
10
|
-
gem 'rails', '~>
|
10
|
+
gem 'rails', '~> 5.0.0', require: false
|
11
11
|
gem 'rspec-rails', require: false
|
12
12
|
gem 'benchmark-ips', require: false
|
13
13
|
gem 'stackprof', require: false
|
14
14
|
end
|
15
|
+
|
16
|
+
gem 'genspec', github: "bquorning/genspec", ref: "rails-5-support"
|
data/README.md
CHANGED
@@ -21,7 +21,8 @@ to a presenter class.
|
|
21
21
|
3. [Presenters](#presenters)
|
22
22
|
1. [Layouts and content blocks](#layouts-and-content-blocks)
|
23
23
|
2. [Rails helper methods](#rails-helper-methods)
|
24
|
-
3. [
|
24
|
+
3. [Testing](#testing)
|
25
|
+
4. [Examples](#examples)
|
25
26
|
4. [Caching](#caching)
|
26
27
|
|
27
28
|
|
@@ -151,7 +152,28 @@ All argument values will be strings. A compilation error will be raised if
|
|
151
152
|
- a required keyword argument in the method definition is not set as an attribute in the
|
152
153
|
component.
|
153
154
|
|
154
|
-
You can define default values using Ruby's own syntax.
|
155
|
+
You can define default values using Ruby's own syntax. Additionally, if the presenter
|
156
|
+
method accepts arbitrary keyword arguments using the `**doublesplat` syntax then all
|
157
|
+
attributes will be valid for the component, e.g.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
def greetings(**names)
|
161
|
+
names.map {|name, greeting| "#{name}: #{greeting}!" }.join("\n")
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
```html
|
166
|
+
{{greetings alice=hello bob=hi}}
|
167
|
+
<!-- The above would be rendered as: -->
|
168
|
+
alice: hello!
|
169
|
+
bob: hi!
|
170
|
+
```
|
171
|
+
|
172
|
+
Note that since keyword arguments in Ruby are represented as Symbol objects, which are
|
173
|
+
not garbage collected in Ruby versions less than 2.2, accepting arbitrary attributes
|
174
|
+
represents a security vulnerability if your application allows untrusted Curly templates
|
175
|
+
to be rendered. Only use this feature with trusted templates if you're not on Ruby 2.2
|
176
|
+
yet.
|
155
177
|
|
156
178
|
|
157
179
|
### Conditional blocks
|
@@ -512,6 +534,57 @@ end
|
|
512
534
|
```
|
513
535
|
|
514
536
|
|
537
|
+
### Testing
|
538
|
+
|
539
|
+
Presenters can be tested directly, but sometimes it makes sense to integrate with
|
540
|
+
Rails on some levels. Currently, only RSpec is directly supported, but you can
|
541
|
+
easily instantiate a presenter:
|
542
|
+
|
543
|
+
```ruby
|
544
|
+
SomePresenter.new(context, assigns)
|
545
|
+
```
|
546
|
+
|
547
|
+
`context` is a view context, i.e. an object that responds to `render`, has all
|
548
|
+
the helper methods you expect, etc. You can pass in a test double and see what
|
549
|
+
you need to stub out. `assigns` is the hash containing the controller and local
|
550
|
+
assigns. You need to pass in a key for each argument the presenter expects.
|
551
|
+
|
552
|
+
#### Testing with RSpec
|
553
|
+
|
554
|
+
In order to test presenters with RSpec, make sure you have `rspec-rails` in your
|
555
|
+
Gemfile. Given the following presenter:
|
556
|
+
|
557
|
+
```ruby
|
558
|
+
# app/presenters/posts/show_presenter.rb
|
559
|
+
class Posts::ShowPresenter < Curly::Presenter
|
560
|
+
presents :post
|
561
|
+
|
562
|
+
def body
|
563
|
+
Markdown.render(@post.body)
|
564
|
+
end
|
565
|
+
end
|
566
|
+
```
|
567
|
+
|
568
|
+
You can test the presenter methods like this:
|
569
|
+
|
570
|
+
```ruby
|
571
|
+
# You can put this in your `spec_helper.rb`.
|
572
|
+
require 'curly/rspec'
|
573
|
+
|
574
|
+
# spec/presenters/posts/show_presenter_spec.rb
|
575
|
+
describe Posts::ShowPresenter, type: :presenter do
|
576
|
+
describe "#body" do
|
577
|
+
it "renders the post's body as Markdown" do
|
578
|
+
assign(:post, double(:post, body: "**hello!**"))
|
579
|
+
expect(presenter.body).to eq "<strong>hello!</strong>"
|
580
|
+
end
|
581
|
+
end
|
582
|
+
end
|
583
|
+
```
|
584
|
+
|
585
|
+
Note that your spec *must* be tagged with `type: :presenter`.
|
586
|
+
|
587
|
+
|
515
588
|
### Examples
|
516
589
|
|
517
590
|
Here is a simple Curly template – it will be looked up by Rails automatically.
|
@@ -698,7 +771,7 @@ Thanks to [Zendesk](http://zendesk.com/) for sponsoring the work on Curly.
|
|
698
771
|
|
699
772
|
- Daniel Schierbeck ([@dasch](https://github.com/dasch))
|
700
773
|
- Benjamin Quorning ([@bquorning](https://github.com/bquorning))
|
701
|
-
- Jeremy Rodi ([@
|
774
|
+
- Jeremy Rodi ([@medcat](https://github.com/medcat))
|
702
775
|
- Alisson Cavalcante Agiani ([@thelinuxlich](https://github.com/thelinuxlich))
|
703
776
|
- Łukasz Niemier ([@hauleth](https://github.com/hauleth))
|
704
777
|
- Cristian Planas ([@Gawyn](https://github.com/Gawyn))
|
data/Rakefile
CHANGED
@@ -1,119 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'bundler'
|
3
|
-
require 'rake'
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
Bundler.setup
|
7
|
-
|
8
|
-
#############################################################################
|
9
|
-
#
|
10
|
-
# Helper functions
|
11
|
-
#
|
12
|
-
#############################################################################
|
13
|
-
|
14
|
-
def name
|
15
|
-
"curly"
|
16
|
-
end
|
17
|
-
|
18
|
-
def gem_name
|
19
|
-
"#{name}-templates"
|
20
|
-
end
|
21
|
-
|
22
|
-
def version
|
23
|
-
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
24
|
-
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
25
|
-
end
|
26
|
-
|
27
|
-
def date
|
28
|
-
Date.today.to_s
|
29
|
-
end
|
30
|
-
|
31
|
-
def gemspec_file
|
32
|
-
"#{gem_name}.gemspec"
|
33
|
-
end
|
34
|
-
|
35
|
-
def gem_file
|
36
|
-
"#{gem_name}-#{version}.gem"
|
37
|
-
end
|
38
|
-
|
39
|
-
def replace_header(head, header_name, value = nil)
|
40
|
-
value ||= send(header_name)
|
41
|
-
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{value}'"}
|
42
|
-
end
|
43
|
-
|
44
|
-
#############################################################################
|
45
|
-
#
|
46
|
-
# Standard tasks
|
47
|
-
#
|
48
|
-
#############################################################################
|
49
|
-
|
50
|
-
task :default => :spec
|
51
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
52
2
|
require 'rspec/core/rake_task'
|
53
|
-
RSpec::Core::RakeTask.new(:spec)
|
54
|
-
|
55
|
-
desc "Open an irb session preloaded with this library"
|
56
|
-
task :console do
|
57
|
-
sh "irb -rubygems -r ./lib/#{name}.rb"
|
58
|
-
end
|
59
|
-
|
60
|
-
#############################################################################
|
61
|
-
#
|
62
|
-
# Packaging tasks
|
63
|
-
#
|
64
|
-
#############################################################################
|
65
|
-
|
66
|
-
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
67
|
-
task :release => :build do
|
68
|
-
unless `git branch` =~ /^\* master$/
|
69
|
-
puts "You must be on the master branch to release!"
|
70
|
-
exit!
|
71
|
-
end
|
72
|
-
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
73
|
-
sh "git tag v#{version}"
|
74
|
-
sh "git push origin master"
|
75
|
-
sh "git push origin v#{version}"
|
76
|
-
sh "gem push pkg/#{gem_name}-#{version}.gem"
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "Build #{gem_file} into the pkg directory"
|
80
|
-
task :build => :gemspec do
|
81
|
-
sh "mkdir -p pkg"
|
82
|
-
sh "gem build #{gemspec_file}"
|
83
|
-
sh "mv #{gem_file} pkg"
|
84
|
-
end
|
85
3
|
|
86
|
-
|
87
|
-
task :gemspec => :validate do
|
88
|
-
# read spec file and split out manifest section
|
89
|
-
spec = File.read(gemspec_file)
|
90
|
-
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
91
|
-
|
92
|
-
# replace name version and date
|
93
|
-
replace_header(head, :name, gem_name)
|
94
|
-
replace_header(head, :version)
|
95
|
-
replace_header(head, :date)
|
96
|
-
|
97
|
-
# determine file list from git ls-files
|
98
|
-
files = `git ls-files`.
|
99
|
-
split("\n").
|
100
|
-
sort.
|
101
|
-
reject { |file| file =~ /^\./ }.
|
102
|
-
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
103
|
-
map { |file| " #{file}" }.
|
104
|
-
join("\n")
|
105
|
-
|
106
|
-
# piece file back together and write
|
107
|
-
manifest = " s.files = %w[\n#{files}\n ]\n"
|
108
|
-
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
109
|
-
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
110
|
-
puts "Updated #{gemspec_file}"
|
111
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
112
5
|
|
113
|
-
|
114
|
-
task :validate do
|
115
|
-
unless Dir['VERSION*'].empty?
|
116
|
-
puts "A `VERSION` file at root level violates Gem best practices."
|
117
|
-
exit!
|
118
|
-
end
|
119
|
-
end
|
6
|
+
task :default => :spec
|
data/circle.yml
CHANGED
data/curly-templates.gemspec
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require './lib/curly/version'
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
6
|
s.rubygems_version = '1.3.5'
|
5
7
|
|
6
8
|
s.name = 'curly-templates'
|
7
|
-
s.version =
|
9
|
+
s.version = Curly::VERSION
|
8
10
|
s.date = '2015-05-19'
|
9
11
|
|
10
12
|
s.summary = "Free your views!"
|
@@ -19,92 +21,13 @@ Gem::Specification.new do |s|
|
|
19
21
|
|
20
22
|
s.rdoc_options = ["--charset=UTF-8"]
|
21
23
|
|
22
|
-
s.add_dependency("actionpack", [">= 3.1", "< 5.
|
24
|
+
s.add_dependency("actionpack", [">= 3.1", "< 5.1"])
|
23
25
|
|
24
|
-
s.add_development_dependency("railties", [">= 3.1", "< 5.
|
26
|
+
s.add_development_dependency("railties", [">= 3.1", "< 5.1"])
|
25
27
|
s.add_development_dependency("rake")
|
26
28
|
s.add_development_dependency("rspec", "~> 2.12")
|
27
29
|
s.add_development_dependency("genspec")
|
28
30
|
|
29
|
-
|
30
|
-
s.files = %w[
|
31
|
-
CHANGELOG.md
|
32
|
-
CONTRIBUTING.md
|
33
|
-
Gemfile
|
34
|
-
README.md
|
35
|
-
Rakefile
|
36
|
-
circle.yml
|
37
|
-
curly-templates.gemspec
|
38
|
-
lib/curly-templates.rb
|
39
|
-
lib/curly.rb
|
40
|
-
lib/curly/attribute_scanner.rb
|
41
|
-
lib/curly/compiler.rb
|
42
|
-
lib/curly/component_compiler.rb
|
43
|
-
lib/curly/component_scanner.rb
|
44
|
-
lib/curly/dependency_tracker.rb
|
45
|
-
lib/curly/error.rb
|
46
|
-
lib/curly/incomplete_block_error.rb
|
47
|
-
lib/curly/incorrect_ending_error.rb
|
48
|
-
lib/curly/invalid_component.rb
|
49
|
-
lib/curly/parser.rb
|
50
|
-
lib/curly/presenter.rb
|
51
|
-
lib/curly/presenter_not_found.rb
|
52
|
-
lib/curly/railtie.rb
|
53
|
-
lib/curly/scanner.rb
|
54
|
-
lib/curly/syntax_error.rb
|
55
|
-
lib/curly/template_handler.rb
|
56
|
-
lib/generators/curly/controller/controller_generator.rb
|
57
|
-
lib/generators/curly/controller/templates/presenter.rb.erb
|
58
|
-
lib/generators/curly/controller/templates/view.html.curly.erb
|
59
|
-
lib/rails/projections.json
|
60
|
-
perf/compile_benchmark.rb
|
61
|
-
perf/compile_profile.rb
|
62
|
-
perf/component_benchmark.rb
|
63
|
-
spec/attribute_scanner_spec.rb
|
64
|
-
spec/collection_blocks_spec.rb
|
65
|
-
spec/compiler/collections_spec.rb
|
66
|
-
spec/compiler/context_blocks_spec.rb
|
67
|
-
spec/compiler_spec.rb
|
68
|
-
spec/component_compiler_spec.rb
|
69
|
-
spec/component_scanner_spec.rb
|
70
|
-
spec/components_spec.rb
|
71
|
-
spec/conditional_blocks_spec.rb
|
72
|
-
spec/dummy/.gitignore
|
73
|
-
spec/dummy/app/controllers/application_controller.rb
|
74
|
-
spec/dummy/app/controllers/dashboards_controller.rb
|
75
|
-
spec/dummy/app/helpers/application_helper.rb
|
76
|
-
spec/dummy/app/presenters/dashboards/collection_presenter.rb
|
77
|
-
spec/dummy/app/presenters/dashboards/item_presenter.rb
|
78
|
-
spec/dummy/app/presenters/dashboards/new_presenter.rb
|
79
|
-
spec/dummy/app/presenters/dashboards/partials_presenter.rb
|
80
|
-
spec/dummy/app/presenters/dashboards/show_presenter.rb
|
81
|
-
spec/dummy/app/presenters/layouts/application_presenter.rb
|
82
|
-
spec/dummy/app/views/dashboards/_item.html.curly
|
83
|
-
spec/dummy/app/views/dashboards/collection.html.curly
|
84
|
-
spec/dummy/app/views/dashboards/new.html.curly
|
85
|
-
spec/dummy/app/views/dashboards/partials.html.curly
|
86
|
-
spec/dummy/app/views/dashboards/show.html.curly
|
87
|
-
spec/dummy/app/views/layouts/application.html.curly
|
88
|
-
spec/dummy/config.ru
|
89
|
-
spec/dummy/config/application.rb
|
90
|
-
spec/dummy/config/boot.rb
|
91
|
-
spec/dummy/config/environment.rb
|
92
|
-
spec/dummy/config/environments/test.rb
|
93
|
-
spec/dummy/config/routes.rb
|
94
|
-
spec/generators/controller_generator_spec.rb
|
95
|
-
spec/integration/application_layout_spec.rb
|
96
|
-
spec/integration/collection_blocks_spec.rb
|
97
|
-
spec/integration/context_blocks_spec.rb
|
98
|
-
spec/integration/partials_spec.rb
|
99
|
-
spec/matchers/have_structure.rb
|
100
|
-
spec/parser_spec.rb
|
101
|
-
spec/presenter_spec.rb
|
102
|
-
spec/scanner_spec.rb
|
103
|
-
spec/spec_helper.rb
|
104
|
-
spec/syntax_error_spec.rb
|
105
|
-
spec/template_handler_spec.rb
|
106
|
-
]
|
107
|
-
# = MANIFEST =
|
108
|
-
|
31
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(perf|spec)/}) }
|
109
32
|
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
|
110
33
|
end
|