ufo 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +3 -3
- data/README.md +1 -1
- data/docs/_docs/auto-completion.md +2 -0
- data/docs/_docs/settings.md +18 -13
- data/docs/_docs/structure.md +2 -2
- data/docs/_docs/tutorial-ufo-init.md +2 -2
- data/docs/_docs/tutorial-ufo-tasks-build.md +1 -1
- data/docs/_docs/ufo-init.md +2 -2
- data/docs/_docs/ufo-tasks-build.md +1 -1
- data/lib/template/.ufo/task_definitions.rb.tt +6 -0
- data/lib/ufo/cli.rb +1 -1
- data/lib/ufo/init.rb +2 -2
- data/lib/ufo/version.rb +1 -1
- data/spec/lib/cli_spec.rb +1 -1
- data/spec/lib/core_spec.rb +1 -1
- data/spec/lib/setting_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -6
- data/ufo.gemspec +2 -1
- data/vendor/render_me_pretty/CHANGELOG.md +27 -0
- data/vendor/render_me_pretty/Gemfile +6 -0
- data/vendor/render_me_pretty/Gemfile.lock +52 -0
- data/vendor/render_me_pretty/README.md +90 -0
- data/vendor/render_me_pretty/Rakefile +2 -0
- data/vendor/render_me_pretty/bin/console +14 -0
- data/vendor/render_me_pretty/bin/setup +8 -0
- data/vendor/render_me_pretty/lib/render_me_pretty.rb +14 -0
- data/vendor/render_me_pretty/lib/render_me_pretty/erb.rb +153 -0
- data/vendor/render_me_pretty/lib/render_me_pretty/erb/base_handler.rb +80 -0
- data/vendor/render_me_pretty/lib/render_me_pretty/erb/main_error_handler.rb +16 -0
- data/vendor/render_me_pretty/lib/render_me_pretty/erb/syntax_error_handler.rb +21 -0
- data/vendor/render_me_pretty/lib/render_me_pretty/version.rb +3 -0
- data/vendor/render_me_pretty/render_me_pretty.gemspec +28 -0
- data/vendor/render_me_pretty/spec/fixtures/invalid/syntax.erb +5 -0
- data/vendor/render_me_pretty/spec/fixtures/invalid/variable.erb +3 -0
- data/vendor/render_me_pretty/spec/fixtures/valid.erb +4 -0
- data/vendor/render_me_pretty/spec/lib/render_me_pretty/erb_spec.rb +69 -0
- data/vendor/render_me_pretty/spec/spec_helper.rb +87 -0
- data/vendor/render_me_pretty/spec/test_context.rb +20 -0
- data/vendor/render_me_pretty/tilt_examples.rb +18 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dedb38a858d8b1102de582ba673bd398f1e32bdae146242318e5d315b0f86179
|
4
|
+
data.tar.gz: 485ac8e92765ae56c44937d59f644d82b6396a6b077346b1ece4046ed11b724d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c20ad01a60c0948abe4725f5ed6920ab1285191fff50a634b8f71cd817f15ee1b68c745a7c523c6f49ca8bd6fd1d57c3df3f666138048cec124ba33e50f477
|
7
|
+
data.tar.gz: 1b115b297a6a1df69765d5824c107bf0e676b4cc838cbec1d1b72372df2427f980e2f28c16d2b3b4e1156b737c9377301c24bfa07f96c652ddbec11fa5726b36
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
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.0.1]
|
7
|
+
- add vendor files to gem package: fixes gem install ufo misses 'render_me_pretty' #18
|
8
|
+
|
6
9
|
## [3.0.0]
|
7
10
|
- dotufo: rename ufo folder to .ufo. Use ufo upgrade3 command to upgrade.
|
8
11
|
- new settings.yml format to account for multiple AWS accounts and environments.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ufo (
|
4
|
+
ufo (3.0.0)
|
5
5
|
activesupport
|
6
6
|
aws-sdk-cloudwatchlogs
|
7
7
|
aws-sdk-ec2
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
i18n (~> 0.7)
|
22
22
|
minitest (~> 5.1)
|
23
23
|
tzinfo (~> 1.1)
|
24
|
-
aws-partitions (1.
|
24
|
+
aws-partitions (1.61.0)
|
25
25
|
aws-sdk-cloudwatchlogs (1.2.0)
|
26
26
|
aws-sdk-core (~> 3)
|
27
27
|
aws-sigv4 (~> 1.0)
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
deep_merge (1.2.1)
|
51
51
|
diff-lcs (1.3)
|
52
52
|
docile (1.1.5)
|
53
|
-
i18n (0.9.
|
53
|
+
i18n (0.9.5)
|
54
54
|
concurrent-ruby (~> 1.0)
|
55
55
|
jmespath (1.3.1)
|
56
56
|
json (2.1.0)
|
data/README.md
CHANGED
data/docs/_docs/settings.md
CHANGED
@@ -2,18 +2,17 @@
|
|
2
2
|
title: Settings
|
3
3
|
---
|
4
4
|
|
5
|
-
The behavior of ufo can be configured
|
5
|
+
The behavior of ufo can be configured with a `settings.yml` file. A starter project `.ufo/settings.yml` file is generated as part of the `ufo init` command. You can have multiple settings files. The options from the files get merged and respected in the following precedence:
|
6
6
|
|
7
|
-
1. current folder - The current folder's
|
7
|
+
1. current folder - The current folder's `.ufo/settings.yml` values take the highest precedence.
|
8
8
|
2. user - The user's `~/.ufo/settings.yml` values take the second highest precedence.
|
9
9
|
3. default - The [default settings](https://github.com/tongueroo/ufo/blob/master/lib/ufo/default/settings.yml) bundled with the tool takes the lowest precedence.
|
10
10
|
|
11
|
-
Let's take a look at an example `
|
11
|
+
Let's take a look at an example `settings.yml`:
|
12
12
|
|
13
13
|
```yaml
|
14
|
-
image: tongueroo/hi
|
15
14
|
base:
|
16
|
-
image:
|
15
|
+
image: tongueroo/hi
|
17
16
|
# clean_keep: 30 # cleans up docker images on your docker server.
|
18
17
|
# ecr_keep: 30 # cleans up images on ECR and keeps this remaining amount. Defaults to keep all.
|
19
18
|
# defaults when an new ECS service is created by ufo ship
|
@@ -46,15 +45,12 @@ Setting | Description
|
|
46
45
|
`image` | The `image` value is the name that ufo will use for the Docker image name to be built. Only provide the basename part of the image name without the tag because ufo automatically generates the tag for you. For example, `tongueroo/hi` is correct and `tongueroo/hi:my-tag` is incorrect.
|
47
46
|
`clean_keep` | Docker images generated from ufo are cleaned up automatically for you at the end of `ufo ship`. This controls how many docker images to keep around. The default is 3.
|
48
47
|
`ecr_keep` | If you are using AWS ECR, then the ECR images can also be automatically cleaned up at the end of `ufo ship`. By default this is set to `nil` and all AWS ECR are kept.
|
49
|
-
`cluster` | By convention, the ECS cluster that ufo deploys to matches the `UFO_ENV`. If `UFO=development`, then `ufo ship` deploys to the `development` ECS cluster. This is option overrides this
|
48
|
+
`cluster` | By convention, the ECS cluster that ufo deploys to matches the `UFO_ENV`. If `UFO=development`, then `ufo ship` deploys to the `development` ECS cluster. This is option overrides this convention.
|
50
49
|
`aws_profiles` | If you have the `AWS_PROFILE` environment variable set, this will ensure that you are deploying the right `UFO_ENV` to the right AWS
|
51
50
|
|
52
|
-
Maps the `UFO_ENV` to an ECS cluster value. This allows you to override the convention where the default cluster equals to `UFO_ENV`. value. This is covered in detailed at [Conventions]({% link _docs/conventions.md %}).
|
53
|
-
|
54
|
-
|
55
51
|
### ECS Cluster Convention
|
56
52
|
|
57
|
-
Normally, the ECS cluster defaults to whatever UFO_ENV is set to by [convention]({% link _docs/conventions.md %}). For example, when `UFO_ENV=production` the ECS Cluster is `production` and when `UFO_ENV=development` the ECS Cluster is `development`.
|
53
|
+
Normally, the ECS cluster defaults to whatever UFO_ENV is set to by [convention]({% link _docs/conventions.md %}). For example, when `UFO_ENV=production` the ECS Cluster is `production` and when `UFO_ENV=development` the ECS Cluster is `development`. There are several ways to override this behavior. Let's go through an example:
|
58
54
|
|
59
55
|
By default, these are all the same:
|
60
56
|
|
@@ -71,16 +67,25 @@ UFO_ENV=production ufo ship hi-web
|
|
71
67
|
UFO_ENV=production ufo ship hi-web --cluster production # same
|
72
68
|
```
|
73
69
|
|
74
|
-
Override the convention
|
70
|
+
Override the convention by explicitly specifying the `--cluster` option in the CLI.
|
75
71
|
|
76
72
|
```sh
|
77
73
|
ufo ship hi-web --cluster custom-cluster # override the cluster
|
78
74
|
UFO_ENV=production ufo ship hi-web --cluster production-cluster # override the cluster
|
79
75
|
```
|
80
76
|
|
81
|
-
|
77
|
+
Override the convention by setting the cluster option in the `settings.yml` file, so you won't have to specify the `--cluster` option in the command repeatedly.
|
78
|
+
|
79
|
+
```yaml
|
80
|
+
development:
|
81
|
+
cluster: dev
|
82
|
+
|
83
|
+
production:
|
84
|
+
cluster: prod
|
85
|
+
```
|
86
|
+
|
82
87
|
|
83
|
-
### AWS_PROFILE
|
88
|
+
### AWS_PROFILE support
|
84
89
|
|
85
90
|
An interesting option is `aws_profiles`. Here's an example:
|
86
91
|
|
data/docs/_docs/structure.md
CHANGED
@@ -13,8 +13,8 @@ Ufo creates a `.ufo` folder within your project which contains the required file
|
|
13
13
|
| └── main.json.erb
|
14
14
|
└── variables
|
15
15
|
├── base.rb
|
16
|
-
├──
|
17
|
-
└──
|
16
|
+
├── production.rb
|
17
|
+
└── development.rb
|
18
18
|
```
|
19
19
|
|
20
20
|
The table below covers the purpose of each folder and file.
|
@@ -46,8 +46,8 @@ The `ufo init` command generated a few starter ufo files for you. The standard d
|
|
46
46
|
| └── main.json.erb
|
47
47
|
└── variables
|
48
48
|
├── base.rb
|
49
|
-
├──
|
50
|
-
└──
|
49
|
+
├── production.rb
|
50
|
+
└── development.rb
|
51
51
|
```
|
52
52
|
|
53
53
|
The explanation of the folders and files were covered in detailed earlier at [Structure]({% link _docs/structure.md %}).
|
@@ -6,7 +6,7 @@ title: Task Definitions
|
|
6
6
|
|
7
7
|
Now that we have a docker image pushed to a registry we can use that image for ECS. Ufo takes that image and adds it to an ECS task definition. This is where ufo is super powerful. Ufo gives you the power to build and control your ECS task definition easily.
|
8
8
|
|
9
|
-
Let's take a look at the 2 files that are used by ufo to build the
|
9
|
+
Let's take a look at the 2 files that are used by ufo to build the ECS task definition. These files were generated by the `ufo init` command at the beginning.
|
10
10
|
|
11
11
|
1. ufo/templates/main.json.erb
|
12
12
|
2. ufo/task_definitions.rb
|
data/docs/_docs/ufo-init.md
CHANGED
@@ -42,8 +42,8 @@ ufo
|
|
42
42
|
├ └── main.json.erb
|
43
43
|
└── variables
|
44
44
|
├── base.rb
|
45
|
-
├──
|
46
|
-
└──
|
45
|
+
├── production.rb
|
46
|
+
└── development.rb
|
47
47
|
```
|
48
48
|
|
49
49
|
The explanation of the folders and files were covered in detailed earlier at [Structure]({% link _docs/structure.md %}).
|
@@ -20,6 +20,12 @@ task_definition "<%= @app %>-web" do
|
|
20
20
|
# Comment out awslogs_* if you do not want logs to be sent to CloudWatch.
|
21
21
|
# Strongly recommended to use CloudWatch/centralized logging.
|
22
22
|
# Ufo automatically creates the log group as part of deployment.
|
23
|
+
#
|
24
|
+
# More info on awslogs settings: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html
|
25
|
+
# The log stream takes the following format:
|
26
|
+
# prefix-name/container-name/ecs-task-id
|
27
|
+
# Here's an exmaple when you specify the prefix of "demo"
|
28
|
+
# demo/web/209e93b4-5523-4496-9a27-662fd151eb78
|
23
29
|
awslogs_group: "ecs/<%= @app %>-web",
|
24
30
|
awslogs_stream_prefix: "<%= @app %>",
|
25
31
|
awslogs_region: helper.current_region,
|
data/lib/ufo/cli.rb
CHANGED
data/lib/ufo/init.rb
CHANGED
@@ -17,9 +17,9 @@ module Ufo
|
|
17
17
|
|
18
18
|
# for specs
|
19
19
|
def set_destination_root
|
20
|
-
return unless ENV['
|
20
|
+
return unless ENV['UFO_ROOT']
|
21
21
|
|
22
|
-
dest = ENV['
|
22
|
+
dest = ENV['UFO_ROOT']
|
23
23
|
FileUtils.rm_rf(dest) && FileUtils.mkdir_p(dest)
|
24
24
|
self.destination_root = dest
|
25
25
|
FileUtils.cd(dest)
|
data/lib/ufo/version.rb
CHANGED
data/spec/lib/cli_spec.rb
CHANGED
data/spec/lib/core_spec.rb
CHANGED
data/spec/lib/setting_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -11,20 +11,18 @@ require "byebug"
|
|
11
11
|
root = File.expand_path("../", File.dirname(__FILE__))
|
12
12
|
require "#{root}/lib/ufo"
|
13
13
|
|
14
|
-
|
15
|
-
ENV['DEST_ROOT'] = $dest
|
16
|
-
ENV['UFO_ROOT'] = $dest
|
14
|
+
ENV['UFO_ROOT'] = "tmp/project"
|
17
15
|
|
18
16
|
module Helpers
|
19
|
-
def
|
20
|
-
FileUtils.rm_rf(
|
17
|
+
def create_ufo_project
|
18
|
+
FileUtils.rm_rf(Ufo.root)
|
21
19
|
execute("exe/ufo init --app hi --image tongueroo/hi")
|
22
20
|
create_test_settings
|
23
21
|
end
|
24
22
|
|
25
23
|
# modify the generated settings so we can spec the settings themselves
|
26
24
|
def create_test_settings
|
27
|
-
FileUtils.cp("spec/fixtures/settings.yml", "#{
|
25
|
+
FileUtils.cp("spec/fixtures/settings.yml", "#{Ufo.root}/.ufo/settings.yml")
|
28
26
|
end
|
29
27
|
|
30
28
|
def execute(cmd)
|
data/ufo.gemspec
CHANGED
@@ -13,7 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://ufoships.com"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
|
16
|
+
vendor_files = Dir.glob("vendor/**/*")
|
17
|
+
spec.files = `git ls-files`.split($/) + vendor_files
|
17
18
|
spec.bindir = "exe"
|
18
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
@@ -0,0 +1,52 @@
|
|
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
|
@@ -0,0 +1,90 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
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__)
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,153 @@
|
|
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
|
@@ -0,0 +1,80 @@
|
|
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
|
@@ -0,0 +1,16 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,69 @@
|
|
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
|
@@ -0,0 +1,87 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
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
|
@@ -0,0 +1,18 @@
|
|
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!"
|
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.0.1
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-cloudwatchlogs
|
@@ -416,6 +416,27 @@ 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
|
419
440
|
homepage: http://ufoships.com
|
420
441
|
licenses:
|
421
442
|
- MIT
|