ufo 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +11 -6
- data/lib/ufo.rb +1 -3
- data/lib/ufo/ship.rb +1 -1
- data/lib/ufo/upgrade3.rb +30 -0
- data/lib/ufo/version.rb +1 -1
- data/ufo.gemspec +1 -3
- metadata +3 -24
- data/vendor/render_me_pretty/CHANGELOG.md +0 -27
- data/vendor/render_me_pretty/Gemfile +0 -6
- data/vendor/render_me_pretty/Gemfile.lock +0 -52
- data/vendor/render_me_pretty/README.md +0 -90
- data/vendor/render_me_pretty/Rakefile +0 -2
- data/vendor/render_me_pretty/bin/console +0 -14
- data/vendor/render_me_pretty/bin/setup +0 -8
- data/vendor/render_me_pretty/lib/render_me_pretty.rb +0 -14
- data/vendor/render_me_pretty/lib/render_me_pretty/erb.rb +0 -153
- data/vendor/render_me_pretty/lib/render_me_pretty/erb/base_handler.rb +0 -80
- data/vendor/render_me_pretty/lib/render_me_pretty/erb/main_error_handler.rb +0 -16
- data/vendor/render_me_pretty/lib/render_me_pretty/erb/syntax_error_handler.rb +0 -21
- data/vendor/render_me_pretty/lib/render_me_pretty/version.rb +0 -3
- data/vendor/render_me_pretty/render_me_pretty.gemspec +0 -28
- data/vendor/render_me_pretty/spec/fixtures/invalid/syntax.erb +0 -5
- data/vendor/render_me_pretty/spec/fixtures/invalid/variable.erb +0 -3
- data/vendor/render_me_pretty/spec/fixtures/valid.erb +0 -4
- data/vendor/render_me_pretty/spec/lib/render_me_pretty/erb_spec.rb +0 -69
- data/vendor/render_me_pretty/spec/spec_helper.rb +0 -87
- data/vendor/render_me_pretty/spec/test_context.rb +0 -20
- data/vendor/render_me_pretty/tilt_examples.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4cd7a59e7976f154950cf4549762565dc012a5e2a74644ca593e2f9805d46b2
|
4
|
+
data.tar.gz: d3afe20c93b5d3234d71c7fa1be39c76a1274899385237a9338eedfc7d5c0e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a0d229886a6e6fe529f2174f177b7c2956f89b2fcbbfb23b2c7beb7089d220ca5cfa4643e8bcd4129e57aaaa74e2481d05eedc39a6f34ce25dcfef7b37ae86b
|
7
|
+
data.tar.gz: 8ad4894dcaf057160249c6885a7e1afd522707d97f1e280a6dbcd92ec646857410d22399639987349690e0700b711695693b4f911ec29dbd872c03d216432bd3
|
data/.gitmodules
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [3.1.0]
|
7
|
+
- fix container_info to refer to .ufo instead of old ufo folder #20
|
8
|
+
- fix ufo upgrade3 #20
|
9
|
+
- add render_me_pretty as gemspec dependency, remove vendor/render_me_pretty submodule #20 #18
|
10
|
+
|
6
11
|
## [3.0.1]
|
7
12
|
- add vendor files to gem package: fixes gem install ufo misses 'render_me_pretty' #18
|
8
13
|
|
@@ -13,7 +18,7 @@ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), eve
|
|
13
18
|
- add auto-completion, to setup: eval $(ufo completion_script)
|
14
19
|
- ufo upgrade3 command
|
15
20
|
- ufo init: Use Thor::Group as generator
|
16
|
-
- default UFO_ENV is now development, not
|
21
|
+
- default UFO_ENV is now development, not prod
|
17
22
|
- Merge pull request #9 from jlchenwenbo/master
|
18
23
|
- Merge branch 'patch-1' of https://github.com/breezeight/ufo into breezeight-patch-1
|
19
24
|
- Bug: Update ship.rb: list all ecs services instead of just the first page
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ufo (3.0.
|
5
|
-
activesupport
|
4
|
+
ufo (3.0.1)
|
6
5
|
aws-sdk-cloudwatchlogs
|
7
6
|
aws-sdk-ec2
|
8
7
|
aws-sdk-ecr
|
@@ -11,25 +10,26 @@ PATH
|
|
11
10
|
colorize
|
12
11
|
deep_merge
|
13
12
|
plissken
|
13
|
+
render_me_pretty
|
14
14
|
thor
|
15
15
|
|
16
16
|
GEM
|
17
17
|
remote: https://rubygems.org/
|
18
18
|
specs:
|
19
|
-
activesupport (5.1.
|
19
|
+
activesupport (5.1.5)
|
20
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
21
|
i18n (~> 0.7)
|
22
22
|
minitest (~> 5.1)
|
23
23
|
tzinfo (~> 1.1)
|
24
|
-
aws-partitions (1.
|
24
|
+
aws-partitions (1.65.0)
|
25
25
|
aws-sdk-cloudwatchlogs (1.2.0)
|
26
26
|
aws-sdk-core (~> 3)
|
27
27
|
aws-sigv4 (~> 1.0)
|
28
|
-
aws-sdk-core (3.
|
28
|
+
aws-sdk-core (3.16.0)
|
29
29
|
aws-partitions (~> 1.0)
|
30
30
|
aws-sigv4 (~> 1.0)
|
31
31
|
jmespath (~> 1.0)
|
32
|
-
aws-sdk-ec2 (1.
|
32
|
+
aws-sdk-ec2 (1.28.0)
|
33
33
|
aws-sdk-core (~> 3)
|
34
34
|
aws-sigv4 (~> 1.0)
|
35
35
|
aws-sdk-ecr (1.2.0)
|
@@ -57,6 +57,10 @@ GEM
|
|
57
57
|
minitest (5.11.3)
|
58
58
|
plissken (1.2.0)
|
59
59
|
rake (12.3.0)
|
60
|
+
render_me_pretty (0.7.0)
|
61
|
+
activesupport
|
62
|
+
colorize
|
63
|
+
tilt
|
60
64
|
rspec (3.7.0)
|
61
65
|
rspec-core (~> 3.7.0)
|
62
66
|
rspec-expectations (~> 3.7.0)
|
@@ -77,6 +81,7 @@ GEM
|
|
77
81
|
simplecov-html (0.10.2)
|
78
82
|
thor (0.20.0)
|
79
83
|
thread_safe (0.3.6)
|
84
|
+
tilt (2.0.8)
|
80
85
|
tzinfo (1.2.5)
|
81
86
|
thread_safe (~> 0.1)
|
82
87
|
|
data/lib/ufo.rb
CHANGED
@@ -3,9 +3,7 @@ require 'ufo/version'
|
|
3
3
|
require 'deep_merge'
|
4
4
|
require 'colorize'
|
5
5
|
require 'fileutils'
|
6
|
-
|
7
|
-
$:.unshift(File.expand_path("../../vendor/render_me_pretty/lib", __FILE__))
|
8
|
-
require "render_me_pretty"
|
6
|
+
require 'render_me_pretty'
|
9
7
|
|
10
8
|
module Ufo
|
11
9
|
autoload :Core, 'ufo/core'
|
data/lib/ufo/ship.rb
CHANGED
@@ -313,7 +313,7 @@ module Ufo
|
|
313
313
|
# assume only 1 port mapping in that container_defintion
|
314
314
|
def container_info(task_definition)
|
315
315
|
Ufo.check_task_definition!(task_definition)
|
316
|
-
task_definition_path = "ufo/output/#{task_definition}.json"
|
316
|
+
task_definition_path = ".ufo/output/#{task_definition}.json"
|
317
317
|
task_definition = JSON.load(IO.read(task_definition_path))
|
318
318
|
container_def = task_definition["containerDefinitions"].first
|
319
319
|
mappings = container_def["portMappings"]
|
data/lib/ufo/upgrade3.rb
CHANGED
@@ -35,6 +35,7 @@ module Ufo
|
|
35
35
|
new_structure = {}
|
36
36
|
|
37
37
|
(data["aws_profile_ufo_env_map"] || {}).each do |aws_profile, ufo_env|
|
38
|
+
ufo_env = map_env(ufo_env)
|
38
39
|
new_structure[ufo_env] ||= {}
|
39
40
|
new_structure[ufo_env]["aws_profiles"] ||= []
|
40
41
|
new_structure[ufo_env]["aws_profiles"] << aws_profile
|
@@ -42,6 +43,7 @@ module Ufo
|
|
42
43
|
data.delete("aws_profile_ufo_env_map")
|
43
44
|
|
44
45
|
(data["ufo_env_cluster_map"] || {}).each do |ufo_env, cluster|
|
46
|
+
ufo_env = map_env(ufo_env)
|
45
47
|
new_structure[ufo_env] ||= {}
|
46
48
|
new_structure[ufo_env]["cluster"] = cluster
|
47
49
|
end
|
@@ -54,6 +56,34 @@ module Ufo
|
|
54
56
|
if path.include?(ENV['HOME'])
|
55
57
|
puts "NOTE: Your ~/.ufo/settings.yml file was also upgraded to the new format. If you are using ufo in other projects those will have to be upgraded also."
|
56
58
|
end
|
59
|
+
|
60
|
+
new_env_info
|
61
|
+
end
|
62
|
+
|
63
|
+
ENV_MAP = {
|
64
|
+
"dev" => "development",
|
65
|
+
"prod" => "production",
|
66
|
+
"stag" => "staging",
|
67
|
+
}
|
68
|
+
def map_env(ufo_env)
|
69
|
+
ENV_MAP[ufo_env] || ufo_env
|
70
|
+
end
|
71
|
+
|
72
|
+
def new_env_info
|
73
|
+
puts <<-EOL.colorize(:yellow)
|
74
|
+
INFO: The UFO_ENV default environment is now development.
|
75
|
+
The short env names have been mapped over to their longer names.
|
76
|
+
Examples:
|
77
|
+
|
78
|
+
prod => production
|
79
|
+
dev => development
|
80
|
+
|
81
|
+
To adjust the default UFO_ENV, export it in your ~/.profile. Example:
|
82
|
+
|
83
|
+
export UFO_ENV=production # the default is now development, when not set
|
84
|
+
|
85
|
+
Refer to https://github.com/tongueroo/ufo/blob/master/CHANGELOG.md for other notable changes.
|
86
|
+
EOL
|
57
87
|
end
|
58
88
|
|
59
89
|
def mv(src, dest)
|
data/lib/ufo/version.rb
CHANGED
data/ufo.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "ufo/version"
|
@@ -29,8 +28,7 @@ Gem::Specification.new do |spec|
|
|
29
28
|
spec.add_dependency "deep_merge"
|
30
29
|
spec.add_dependency "plissken"
|
31
30
|
spec.add_dependency "thor"
|
32
|
-
|
33
|
-
spec.add_dependency "activesupport" # render_me_pretty submodule dependency
|
31
|
+
spec.add_dependency "render_me_pretty"
|
34
32
|
|
35
33
|
spec.add_development_dependency "bundler"
|
36
34
|
spec.add_development_dependency "byebug"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ufo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-cloudwatchlogs
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: render_me_pretty
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -416,27 +416,6 @@ files:
|
|
416
416
|
- spec/lib/task_spec.rb
|
417
417
|
- spec/spec_helper.rb
|
418
418
|
- ufo.gemspec
|
419
|
-
- vendor/render_me_pretty/CHANGELOG.md
|
420
|
-
- vendor/render_me_pretty/Gemfile
|
421
|
-
- vendor/render_me_pretty/Gemfile.lock
|
422
|
-
- vendor/render_me_pretty/README.md
|
423
|
-
- vendor/render_me_pretty/Rakefile
|
424
|
-
- vendor/render_me_pretty/bin/console
|
425
|
-
- vendor/render_me_pretty/bin/setup
|
426
|
-
- vendor/render_me_pretty/lib/render_me_pretty.rb
|
427
|
-
- vendor/render_me_pretty/lib/render_me_pretty/erb.rb
|
428
|
-
- vendor/render_me_pretty/lib/render_me_pretty/erb/base_handler.rb
|
429
|
-
- vendor/render_me_pretty/lib/render_me_pretty/erb/main_error_handler.rb
|
430
|
-
- vendor/render_me_pretty/lib/render_me_pretty/erb/syntax_error_handler.rb
|
431
|
-
- vendor/render_me_pretty/lib/render_me_pretty/version.rb
|
432
|
-
- vendor/render_me_pretty/render_me_pretty.gemspec
|
433
|
-
- vendor/render_me_pretty/spec/fixtures/invalid/syntax.erb
|
434
|
-
- vendor/render_me_pretty/spec/fixtures/invalid/variable.erb
|
435
|
-
- vendor/render_me_pretty/spec/fixtures/valid.erb
|
436
|
-
- vendor/render_me_pretty/spec/lib/render_me_pretty/erb_spec.rb
|
437
|
-
- vendor/render_me_pretty/spec/spec_helper.rb
|
438
|
-
- vendor/render_me_pretty/spec/test_context.rb
|
439
|
-
- vendor/render_me_pretty/tilt_examples.rb
|
440
419
|
homepage: http://ufoships.com
|
441
420
|
licenses:
|
442
421
|
- MIT
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Change Log
|
2
|
-
|
3
|
-
All notable changes to this project will be documented in this file.
|
4
|
-
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
|
-
|
6
|
-
## [0.6.0]
|
7
|
-
- Handle SyntaxError errors correctly
|
8
|
-
- refactor into MainErrorHandler and SyntaxError classes
|
9
|
-
|
10
|
-
## [0.5.0]
|
11
|
-
- fix find_template_error_line
|
12
|
-
- remove some of the filtering for backtrace lines
|
13
|
-
|
14
|
-
## [0.4.0]
|
15
|
-
- fix erb and context definitions, fix bug with empty variables={}
|
16
|
-
- improve original backtrace info, colorize exact line
|
17
|
-
|
18
|
-
## [0.3.0]
|
19
|
-
- fix bug with empty variables={}
|
20
|
-
- fix erb and context definitions
|
21
|
-
|
22
|
-
## [0.2.0]
|
23
|
-
- add RenderMePretty.result convenience class method
|
24
|
-
|
25
|
-
## [0.1.0]
|
26
|
-
- initial release
|
27
|
-
|
@@ -1,52 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
render_me_pretty (0.6.0)
|
5
|
-
activesupport
|
6
|
-
colorize
|
7
|
-
tilt
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
activesupport (5.1.5)
|
13
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (~> 0.7)
|
15
|
-
minitest (~> 5.1)
|
16
|
-
tzinfo (~> 1.1)
|
17
|
-
colorize (0.8.1)
|
18
|
-
concurrent-ruby (1.0.5)
|
19
|
-
diff-lcs (1.3)
|
20
|
-
i18n (0.9.5)
|
21
|
-
concurrent-ruby (~> 1.0)
|
22
|
-
minitest (5.11.3)
|
23
|
-
rake (12.3.0)
|
24
|
-
rspec (3.7.0)
|
25
|
-
rspec-core (~> 3.7.0)
|
26
|
-
rspec-expectations (~> 3.7.0)
|
27
|
-
rspec-mocks (~> 3.7.0)
|
28
|
-
rspec-core (3.7.1)
|
29
|
-
rspec-support (~> 3.7.0)
|
30
|
-
rspec-expectations (3.7.0)
|
31
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.7.0)
|
33
|
-
rspec-mocks (3.7.0)
|
34
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.7.0)
|
36
|
-
rspec-support (3.7.1)
|
37
|
-
thread_safe (0.3.6)
|
38
|
-
tilt (2.0.8)
|
39
|
-
tzinfo (1.2.5)
|
40
|
-
thread_safe (~> 0.1)
|
41
|
-
|
42
|
-
PLATFORMS
|
43
|
-
ruby
|
44
|
-
|
45
|
-
DEPENDENCIES
|
46
|
-
bundler
|
47
|
-
rake
|
48
|
-
render_me_pretty!
|
49
|
-
rspec
|
50
|
-
|
51
|
-
BUNDLED WITH
|
52
|
-
1.16.1
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# Render Me Pretty
|
2
|
-
|
3
|
-
Let's say you have an error in your ERB template:
|
4
|
-
|
5
|
-
```
|
6
|
-
line 1
|
7
|
-
<%= sdsd %>
|
8
|
-
line 3
|
9
|
-
```
|
10
|
-
|
11
|
-
Normally, when render it with ERB you get an error message that looks something like this:
|
12
|
-
|
13
|
-
```sh
|
14
|
-
NameError:
|
15
|
-
undefined local variable or method `sdsd' for #<RenderMePretty::Context:0x00007fcda414d358>
|
16
|
-
(erb):2:in `get_binding'
|
17
|
-
./lib/render_me_pretty.rb:71:in `render'
|
18
|
-
./spec/lib/render_me_pretty/erb_spec.rb:41:in `block (3 levels) in <top (required)>'
|
19
|
-
```
|
20
|
-
|
21
|
-
Instead, this library produces an output with an error pointing out the original line in the ERB template like so:
|
22
|
-
|
23
|
-
```
|
24
|
-
NameError evaluating ERB template on line 2 of: spec/fixtures/invalid.erb
|
25
|
-
1 line 1
|
26
|
-
2 <%= sdsd %>
|
27
|
-
3 line 3
|
28
|
-
```
|
29
|
-
|
30
|
-
The output also colorizes the error line in red so it stands out.
|
31
|
-
|
32
|
-
|
33
|
-
## Usage
|
34
|
-
|
35
|
-
Here's a simple example:
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
erb = RenderMePretty::Erb.new("/path/to/tempate.erb", a: 3) }
|
39
|
-
erb.render(a: 4)
|
40
|
-
```
|
41
|
-
|
42
|
-
There's also a convenience class method:
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
RenderMePretty.result("/path/to/tempate.erb", a: 5)
|
46
|
-
```
|
47
|
-
|
48
|
-
### Custom Context
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
person = Person.new("tung")
|
52
|
-
erb = RenderMePretty::Erb.new("/path/to/tempate.erb", a: 3, context: person) } # passing context here
|
53
|
-
erb.render(a: 4)
|
54
|
-
|
55
|
-
person = Person.new("tung")
|
56
|
-
erb = RenderMePretty::Erb.new("/path/to/tempate.erb", a: 3) }
|
57
|
-
erb.render(person, a: 4) # passing context here
|
58
|
-
```
|
59
|
-
|
60
|
-
The context's methods and instance variables are available in the ERB template. Variables passed at initialization time to `RenderMePretty::Erb.new` or at call time for `render` be set as instance variables to a clone of the original context object.
|
61
|
-
|
62
|
-
So in the case above, if there was an `@a` instance variable in the Person object, it will not get respected. Instead the value would be `@a = 4`.
|
63
|
-
|
64
|
-
### Context
|
65
|
-
|
66
|
-
You can pass in a context object also. Examples:
|
67
|
-
|
68
|
-
A few more examples are in the [erb_spec.rb](spec/lib/render_me_pretty/erb_spec.rb)
|
69
|
-
|
70
|
-
## Installation
|
71
|
-
|
72
|
-
Add this line to your application's Gemfile:
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
gem 'render_me_pretty'
|
76
|
-
```
|
77
|
-
|
78
|
-
And then execute:
|
79
|
-
|
80
|
-
$ bundle
|
81
|
-
|
82
|
-
## Contributing
|
83
|
-
|
84
|
-
Please fork the project and open a pull request! I'd love your pull requests. Contributions are encouraged and welcomed!
|
85
|
-
|
86
|
-
1. Fork it
|
87
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
88
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
89
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
90
|
-
5. Create new Pull Request
|
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "render_me_pretty"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require "render_me_pretty/version"
|
2
|
-
require "active_support/core_ext/string"
|
3
|
-
require "colorize"
|
4
|
-
|
5
|
-
module RenderMePretty
|
6
|
-
autoload :Erb, 'render_me_pretty/erb'
|
7
|
-
|
8
|
-
def result(path, variables={})
|
9
|
-
erb = Erb.new(path, variables)
|
10
|
-
erb.render
|
11
|
-
end
|
12
|
-
|
13
|
-
extend self
|
14
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
## Usage examples:
|
3
|
-
|
4
|
-
Given an example template /path/to/template.erb that contains:
|
5
|
-
|
6
|
-
a: <%= @a %>
|
7
|
-
|
8
|
-
### Variables at initialization
|
9
|
-
|
10
|
-
erb = RenderMePretty::Erb.new("/path/to/template.erb", a: 1)
|
11
|
-
erb.render
|
12
|
-
|
13
|
-
Result: a: 1
|
14
|
-
|
15
|
-
### Variables at render time
|
16
|
-
|
17
|
-
erb = RenderMePretty::Erb.new("/path/to/template.erb")
|
18
|
-
erb.render(a: 2)
|
19
|
-
|
20
|
-
Result: a: 2
|
21
|
-
|
22
|
-
### Variables at both initialization and render time:
|
23
|
-
|
24
|
-
erb = RenderMePretty::Erb.new("/path/to/template.erb", a: 3)
|
25
|
-
erb.render(a: "override", a: 4)
|
26
|
-
|
27
|
-
Result: a: 4
|
28
|
-
|
29
|
-
Variables at render time will override variables at initialization time.
|
30
|
-
|
31
|
-
## Context Scope
|
32
|
-
|
33
|
-
If you want to use your own context object, pass it as a variable. The context variable is specially treated as a context object. Example:
|
34
|
-
|
35
|
-
person = Person.new # must implement get_binding
|
36
|
-
erb = RenderMePretty::Erb.new("/path/to/template.erb")
|
37
|
-
erb.render(context: person, a: 2)
|
38
|
-
|
39
|
-
The context will be `person`. So person methods and instance variables will be available in the ERB templates.
|
40
|
-
|
41
|
-
=end
|
42
|
-
require 'tilt/erb'
|
43
|
-
|
44
|
-
module RenderMePretty
|
45
|
-
class Erb
|
46
|
-
autoload :BaseHandler, 'render_me_pretty/erb/base_handler'
|
47
|
-
autoload :SyntaxErrorHandler, "render_me_pretty/erb/syntax_error_handler"
|
48
|
-
autoload :MainErrorHandler, "render_me_pretty/erb/main_error_handler"
|
49
|
-
|
50
|
-
def initialize(path, variables={})
|
51
|
-
@path = path
|
52
|
-
@init_vars = variables
|
53
|
-
@context = variables.delete(:context)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Usage:
|
57
|
-
#
|
58
|
-
# render(context, a: 1, b: 2)
|
59
|
-
# render(a: 1, b: 2)
|
60
|
-
# render
|
61
|
-
def render(*args)
|
62
|
-
if args.last.is_a?(Hash)
|
63
|
-
render_vars = args.pop
|
64
|
-
@init_vars = @init_vars.merge(render_vars)
|
65
|
-
end
|
66
|
-
context = args[0]
|
67
|
-
context ||= @context || Object.new
|
68
|
-
|
69
|
-
context = context.clone # so we dont stomp the original object
|
70
|
-
# override context's instance variables with init and render vars.
|
71
|
-
@init_vars.each do |key, value|
|
72
|
-
context.instance_variable_set('@' + key.to_s, value)
|
73
|
-
end
|
74
|
-
|
75
|
-
template = Tilt::ERBTemplate.new(@path)
|
76
|
-
begin
|
77
|
-
template.render(context)
|
78
|
-
rescue Exception => e
|
79
|
-
handle_exception(e)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Handles Tilt error in prettier manner.
|
84
|
-
#
|
85
|
-
# When there's a syntax error Tilt does not include the line nubmer of the
|
86
|
-
# error in the backtrace it is instead included in the e.message itself.
|
87
|
-
#
|
88
|
-
# When for other errors the line_number is included in the backtrace.
|
89
|
-
#
|
90
|
-
# Refer to specs and uncomment puts out to see the different types of errors.
|
91
|
-
def handle_exception(e)
|
92
|
-
# puts "*" * 30
|
93
|
-
# puts e.class.to_s.colorize(:cyan)
|
94
|
-
# puts e.message.colorize(:cyan)
|
95
|
-
# puts e.backtrace
|
96
|
-
# puts "*" * 30
|
97
|
-
handler = e.is_a?(SyntaxError) ?
|
98
|
-
SyntaxErrorHandler.new(@path, e) :
|
99
|
-
MainErrorHandler.new(@path, e)
|
100
|
-
io = handler.handle
|
101
|
-
print_result(io)
|
102
|
-
end
|
103
|
-
|
104
|
-
def print_result(io)
|
105
|
-
if ENV['TEST']
|
106
|
-
io.string
|
107
|
-
else
|
108
|
-
puts io.string
|
109
|
-
exit 1
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Method produces a filtered original stack trace that can be appended to
|
114
|
-
# the pretty backtrace output.
|
115
|
-
#
|
116
|
-
# It parses the original backtrace that looks something like this:
|
117
|
-
#
|
118
|
-
# (erb):380:in `get_binding'
|
119
|
-
# /Users/tung/.rbenv/versions/2.5.0/lib/ruby/2.5.0/erb.rb:885:in `eval'
|
120
|
-
# /Users/tung/.rbenv/versions/2.5.0/lib/ruby/2.5.0/erb.rb:885:in `result'
|
121
|
-
# /Users/tung/src/tongueroo/lono/vendor/render_me_pretty/lib/render_me_pretty/erb.rb:67:in `render'
|
122
|
-
# /Users/tung/src/tongueroo/lono/vendor/render_me_pretty/lib/render_me_pretty.rb:11:in `result'
|
123
|
-
# /Users/tung/src/tongueroo/lono/lib/lono/template/template.rb:32:in `build'
|
124
|
-
# /Users/tung/src/tongueroo/lono/lib/lono/template/dsl.rb:82:in `block in build_templates'
|
125
|
-
# /Users/tung/src/tongueroo/lono/lib/lono/template/dsl.rb:81:in `each'
|
126
|
-
def backtrace_lines(e)
|
127
|
-
full = ENV['FULL_BACKTRACE']
|
128
|
-
if full
|
129
|
-
lines = e.backtrace
|
130
|
-
else
|
131
|
-
lines = e.backtrace
|
132
|
-
# This filtering business makes is hiding useful info.
|
133
|
-
# Think it was needed for ERB but Tilt provides a better stack trace.
|
134
|
-
# Commenting out for now.
|
135
|
-
|
136
|
-
# filter out internal lines
|
137
|
-
# removal_index = lines.find_index { |l| l =~ %r[lib/render_me_pretty] }
|
138
|
-
# lines = lines[removal_index..-1] # remove leading lines above the lib/
|
139
|
-
# render_me_pretty lines by keeping lines past the removal index
|
140
|
-
# lines.reject! { |l| l =~ %r[lib/render_me_pretty] } # now filter out
|
141
|
-
# render_me_pretty lines
|
142
|
-
lines = lines[0..7] # keep 8 lines
|
143
|
-
end
|
144
|
-
lines[0] = lines[0].colorize(:red)
|
145
|
-
|
146
|
-
# header
|
147
|
-
lines.unshift "\nOriginal backtrace#{full ? '' : ' (last 8 lines)'}:"
|
148
|
-
# footer
|
149
|
-
lines << "\nRe-run with FULL_BACKTRACE=1 to see all lines"
|
150
|
-
lines.join("\n")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
class RenderMePretty::Erb
|
2
|
-
class BaseHandler
|
3
|
-
def initialize(path, exception)
|
4
|
-
@path = path
|
5
|
-
@exception = exception
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
line_number = find_line_number
|
10
|
-
pretty_trace(line_number, full_message=true) # returns StringIO
|
11
|
-
end
|
12
|
-
|
13
|
-
def pretty_trace(error_line_number, full_message=true)
|
14
|
-
io = StringIO.new
|
15
|
-
|
16
|
-
message = full_message ? ": #{@exception.message}" : ""
|
17
|
-
io.puts "#{@exception.class}#{message}".colorize(:red)
|
18
|
-
|
19
|
-
pretty_path = @path.sub(/^\.\//, '')
|
20
|
-
io.puts "Error evaluating ERB template around line #{error_line_number.to_s.colorize(:red)} of: #{pretty_path}:"
|
21
|
-
|
22
|
-
context = 5 # lines of context
|
23
|
-
top, bottom = [error_line_number-context-1, 0].max, error_line_number+context-1
|
24
|
-
|
25
|
-
lines = IO.read(@path).split("\n")
|
26
|
-
spacing = lines.size.to_s.size
|
27
|
-
lines[top..bottom].each_with_index do |line_content, index|
|
28
|
-
current_line_number = top+index+1
|
29
|
-
if current_line_number == error_line_number
|
30
|
-
io.printf("%#{spacing}d %s\n".colorize(:red), current_line_number, line_content)
|
31
|
-
else
|
32
|
-
io.printf("%#{spacing}d %s\n", current_line_number, line_content)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
io.puts backtrace_lines
|
37
|
-
io
|
38
|
-
end
|
39
|
-
|
40
|
-
# Method produces a filtered original stack trace that can be appended to
|
41
|
-
# the pretty backtrace output.
|
42
|
-
#
|
43
|
-
# It parses the original backtrace that looks something like this:
|
44
|
-
#
|
45
|
-
# (erb):380:in `get_binding'
|
46
|
-
# /Users/tung/.rbenv/versions/2.5.0/lib/ruby/2.5.0/erb.rb:885:in `eval'
|
47
|
-
# /Users/tung/.rbenv/versions/2.5.0/lib/ruby/2.5.0/erb.rb:885:in `result'
|
48
|
-
# /Users/tung/src/tongueroo/lono/vendor/render_me_pretty/lib/render_me_pretty/erb.rb:67:in `render'
|
49
|
-
# /Users/tung/src/tongueroo/lono/vendor/render_me_pretty/lib/render_me_pretty.rb:11:in `result'
|
50
|
-
# /Users/tung/src/tongueroo/lono/lib/lono/template/template.rb:32:in `build'
|
51
|
-
# /Users/tung/src/tongueroo/lono/lib/lono/template/dsl.rb:82:in `block in build_templates'
|
52
|
-
# /Users/tung/src/tongueroo/lono/lib/lono/template/dsl.rb:81:in `each'
|
53
|
-
def backtrace_lines
|
54
|
-
full = ENV['FULL_BACKTRACE']
|
55
|
-
if full
|
56
|
-
lines = @exception.backtrace
|
57
|
-
else
|
58
|
-
lines = @exception.backtrace
|
59
|
-
# This filtering business makes is hiding useful info.
|
60
|
-
# Think it was needed for ERB but Tilt provides a better stack trace.
|
61
|
-
# Commenting out for now.
|
62
|
-
|
63
|
-
# filter out internal lines
|
64
|
-
# removal_index = lines.find_index { |l| l =~ %r[lib/render_me_pretty] }
|
65
|
-
# lines = lines[removal_index..-1] # remove leading lines above the lib/
|
66
|
-
# render_me_pretty lines by keeping lines past the removal index
|
67
|
-
# lines.reject! { |l| l =~ %r[lib/render_me_pretty] } # now filter out
|
68
|
-
# render_me_pretty lines
|
69
|
-
lines = lines[0..7] # keep 8 lines
|
70
|
-
end
|
71
|
-
lines[0] = lines[0].colorize(:red)
|
72
|
-
|
73
|
-
# header
|
74
|
-
lines.unshift "\nOriginal backtrace#{full ? '' : ' (last 8 lines)'}:"
|
75
|
-
# footer
|
76
|
-
lines << "\nRe-run with FULL_BACKTRACE=1 to see all lines"
|
77
|
-
lines.join("\n")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class RenderMePretty::Erb
|
2
|
-
class MainErrorHandler < BaseHandler
|
3
|
-
# For general Tilt errors first line of the backtrace that contains the path
|
4
|
-
# of the file we're rendeirng and has the line number. Example:
|
5
|
-
#
|
6
|
-
# spec/fixtures/invalid.erb:2:in `block in singleton class'
|
7
|
-
# error_info = e.backtrace[0]
|
8
|
-
def find_line_number
|
9
|
-
lines = @exception.backtrace
|
10
|
-
error_line = lines.select do |line|
|
11
|
-
line.include?(@path)
|
12
|
-
end.first
|
13
|
-
error_line.split(':')[1].to_i
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class RenderMePretty::Erb
|
2
|
-
class SyntaxErrorHandler < BaseHandler
|
3
|
-
# spec/fixtures/invalid/syntax.erb:2: syntax error, unexpected ';', expecting ']'
|
4
|
-
# ); if ENV['TEST' ; _erbout.<<(-" missing ending...
|
5
|
-
# ^
|
6
|
-
# spec/fixtures/invalid/syntax.erb:12: syntax error, unexpected keyword_end, expecting end-of-input
|
7
|
-
# end;end;end;end
|
8
|
-
# ^~~
|
9
|
-
#
|
10
|
-
# We will only find the first line number for the error.
|
11
|
-
def find_line_number
|
12
|
-
pattern = Regexp.new("#{@path}:(\\\d+): syntax error")
|
13
|
-
lines = @exception.message.split("\n")
|
14
|
-
found_line = lines.find do |line|
|
15
|
-
line.match(pattern)
|
16
|
-
end
|
17
|
-
md = found_line.match(pattern)
|
18
|
-
md[1].to_i # line_number
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "render_me_pretty/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "render_me_pretty"
|
7
|
-
spec.version = RenderMePretty::VERSION
|
8
|
-
spec.authors = ["Tung Nguyen"]
|
9
|
-
spec.email = ["tongueroo@gmail.com"]
|
10
|
-
|
11
|
-
spec.summary = %q{Render ERB template and provide more useful message pointing out the line with the error in the view}
|
12
|
-
spec.homepage = "https://github.com/tongueroo/render_me_pretty"
|
13
|
-
|
14
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
-
f.match(%r{^(test|spec|features)/})
|
16
|
-
end
|
17
|
-
spec.bindir = "exe"
|
18
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "activesupport"
|
22
|
-
spec.add_dependency "colorize"
|
23
|
-
spec.add_dependency "tilt"
|
24
|
-
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec"
|
28
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RenderMePretty do
|
4
|
-
let(:context) { TestContext.new }
|
5
|
-
|
6
|
-
context "valid" do
|
7
|
-
let(:path) { "spec/fixtures/valid.erb" }
|
8
|
-
|
9
|
-
context "initial variables" do
|
10
|
-
let(:erb) { RenderMePretty::Erb.new(path, a: 1) }
|
11
|
-
it "#render" do
|
12
|
-
out = erb.render(context)
|
13
|
-
expect(out).to include "a: 1"
|
14
|
-
# test helper methods also
|
15
|
-
expect(out).to include "my_helper: my_helper value"
|
16
|
-
expect(out).to include "hello test: hello tung"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "render time variables" do
|
21
|
-
let(:erb) { RenderMePretty::Erb.new(path) }
|
22
|
-
it "#render" do
|
23
|
-
out = erb.render(context, a: 2)
|
24
|
-
expect(out).to include "a: 2"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "both initial and render time variables" do
|
29
|
-
let(:erb) { RenderMePretty::Erb.new(path, a: 3) }
|
30
|
-
it "#render" do
|
31
|
-
out = erb.render(context, a: 4)
|
32
|
-
expect(out).to include "a: 4"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "convenience class method" do
|
37
|
-
out = RenderMePretty.result(path, context: context)
|
38
|
-
expect(out).to include "hello test: hello tung"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "invalid" do
|
43
|
-
let(:erb) { RenderMePretty::Erb.new(path) }
|
44
|
-
|
45
|
-
context "variable" do
|
46
|
-
let(:path) { "spec/fixtures/invalid/variable.erb" }
|
47
|
-
it "#render" do
|
48
|
-
out = erb.render(context)
|
49
|
-
# puts out
|
50
|
-
expect(out).to include("2 <%= breakme %>")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "syntax" do
|
55
|
-
let(:path) { "spec/fixtures/invalid/syntax.erb" }
|
56
|
-
it "#render" do
|
57
|
-
out = erb.render(context)
|
58
|
-
# puts out
|
59
|
-
# spec/fixtures/invalid/syntax.erb:2: syntax error, unexpected ';', expecting ']'
|
60
|
-
# ); if ENV['TEST' ; _erbout.<<(-" missing ending...
|
61
|
-
# ^
|
62
|
-
# spec/fixtures/invalid/syntax.erb:12: syntax error, unexpected keyword_end, expecting end-of-input
|
63
|
-
# end;end;end;end
|
64
|
-
# ^~~
|
65
|
-
expect(out).to include("ENV['TEST' ")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
ENV['TEST'] = '1'
|
2
|
-
|
3
|
-
require "./lib/render_me_pretty"
|
4
|
-
require "./spec/test_context"
|
5
|
-
|
6
|
-
RSpec.configure do |config|
|
7
|
-
config.expect_with :rspec do |expectations|
|
8
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
9
|
-
# and `failure_message` of custom matchers include text for helper methods
|
10
|
-
# defined using `chain`, e.g.:
|
11
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
12
|
-
# # => "be bigger than 2 and smaller than 4"
|
13
|
-
# ...rather than:
|
14
|
-
# # => "be bigger than 2"
|
15
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
16
|
-
end
|
17
|
-
|
18
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
19
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
20
|
-
config.mock_with :rspec do |mocks|
|
21
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
22
|
-
# a real object. This is generally recommended, and will default to
|
23
|
-
# `true` in RSpec 4.
|
24
|
-
mocks.verify_partial_doubles = true
|
25
|
-
end
|
26
|
-
|
27
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
28
|
-
# have no way to turn it off -- the option exists only for backwards
|
29
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
30
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
31
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
32
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
33
|
-
|
34
|
-
# The settings below are suggested to provide a good initial experience
|
35
|
-
# with RSpec, but feel free to customize to your heart's content.
|
36
|
-
=begin
|
37
|
-
# This allows you to limit a spec run to individual examples or groups
|
38
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
39
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
40
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
41
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
42
|
-
config.filter_run_when_matching :focus
|
43
|
-
|
44
|
-
# Allows RSpec to persist some state between runs in order to support
|
45
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
46
|
-
# you configure your source control system to ignore this file.
|
47
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
48
|
-
|
49
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
50
|
-
# recommended. For more details, see:
|
51
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
52
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
53
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
54
|
-
config.disable_monkey_patching!
|
55
|
-
|
56
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
57
|
-
# be too noisy due to issues in dependencies.
|
58
|
-
config.warnings = true
|
59
|
-
|
60
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
61
|
-
# file, and it's useful to allow more verbose output when running an
|
62
|
-
# individual spec file.
|
63
|
-
if config.files_to_run.one?
|
64
|
-
# Use the documentation formatter for detailed output,
|
65
|
-
# unless a formatter has already been configured
|
66
|
-
# (e.g. via a command-line flag).
|
67
|
-
config.default_formatter = "doc"
|
68
|
-
end
|
69
|
-
|
70
|
-
# Print the 10 slowest examples and example groups at the
|
71
|
-
# end of the spec run, to help surface which specs are running
|
72
|
-
# particularly slow.
|
73
|
-
config.profile_examples = 10
|
74
|
-
|
75
|
-
# Run specs in random order to surface order dependencies. If you find an
|
76
|
-
# order dependency and want to debug it, you can fix the order by providing
|
77
|
-
# the seed, which is printed after each run.
|
78
|
-
# --seed 1234
|
79
|
-
config.order = :random
|
80
|
-
|
81
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
82
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
83
|
-
# test failures related to randomization by passing the same `--seed` value
|
84
|
-
# as the one that triggered the failure.
|
85
|
-
Kernel.srand config.seed
|
86
|
-
=end
|
87
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class TestContext
|
2
|
-
def initialize(hash={})
|
3
|
-
# http://stackoverflow.com/questions/1338960/ruby-templates-how-to-pass-variables-into-inlined-erb
|
4
|
-
hash.each do |key, value|
|
5
|
-
instance_variable_set('@' + key.to_s, value)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def my_helper
|
10
|
-
"my_helper value"
|
11
|
-
end
|
12
|
-
|
13
|
-
def hello(name)
|
14
|
-
"hello #{name}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def foo_helper
|
18
|
-
"foo_helper"
|
19
|
-
end
|
20
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'tilt/erb'
|
2
|
-
template = Tilt::ERBTemplate.new('templates/foo.erb')
|
3
|
-
joe = Person.find('joe')
|
4
|
-
output = template.render(joe, :x => 35, :y => 42)
|
5
|
-
# If no scope is provided, the template is evaluated within the context of an object created with Object.new.
|
6
|
-
|
7
|
-
# A single Template instance's render method may be called multiple times with different scope and locals arguments. Continuing the previous example, we render the same compiled template but this time in jane's scope:
|
8
|
-
|
9
|
-
jane = Person.find('jane')
|
10
|
-
output = template.render(jane, :x => 22, :y => nil)
|
11
|
-
# Blocks can be passed to render for templates that support running arbitrary ruby code (usually with some form of yield). For instance, assuming the following in foo.erb:
|
12
|
-
|
13
|
-
# Hey <%= yield %>!
|
14
|
-
# The block passed to render is called on yield:
|
15
|
-
|
16
|
-
template = Tilt::ERBTemplate.new('foo.erb')
|
17
|
-
template.render { 'Joe' }
|
18
|
-
# => "Hey Joe!"
|