rake_template 0.1.0.pre.2 → 0.1.0.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rake_template.rb +4 -0
- data/lib/rake_template/tasks.rb +7 -0
- data/lib/rake_template/tasks/render.rb +29 -0
- data/lib/rake_template/template.rb +22 -0
- data/lib/rake_template/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74cb5ffbabf0716b59a0894113a78b24b8b2c1ffe5f20224ec60ad4efb0e60aa
|
4
|
+
data.tar.gz: 2a049f47430f2a2aa45cfd2c7641281068da25af6d2bbba7de62f1372e02d8b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57c9807907c9831169b98344ada306e3a7dff73b2af20788e13fd775b20c2d9432cdd1a67bc954bc5299e09cad31f9174d7760c482bfc769492d1415664edac5
|
7
|
+
data.tar.gz: b9139e73cec066f2b863dfd3a873db29e9642958e50e9a08842e1264f72373499e0347df125695f707b0f0f4ef7347c2f1a63a9f39ec2f3740d92770fac67903
|
data/Gemfile.lock
CHANGED
data/lib/rake_template.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rake_factory'
|
2
|
+
|
3
|
+
require_relative '../template'
|
4
|
+
|
5
|
+
module RakeTemplate
|
6
|
+
module Tasks
|
7
|
+
class Render < RakeFactory::Task
|
8
|
+
default_name :render
|
9
|
+
default_description RakeFactory::DynamicValue.new { |t|
|
10
|
+
"Render #{t.template_name ? "the #{t.template_name}" : "a"} template"
|
11
|
+
}
|
12
|
+
|
13
|
+
parameter :template_name
|
14
|
+
parameter :template_file_path, required: true
|
15
|
+
parameter :output_file_path, required: true
|
16
|
+
parameter :vars, default: {}
|
17
|
+
|
18
|
+
action do |t|
|
19
|
+
puts "Rendering template at #{t.template_file_path} " +
|
20
|
+
"to #{t.output_file_path}..."
|
21
|
+
template = Template.from_file(t.template_file_path)
|
22
|
+
rendered = template.render(t.vars)
|
23
|
+
mkdir_p(File.dirname(t.output_file_path))
|
24
|
+
File.open(t.output_file_path, 'w') { |f| f.write(rendered) }
|
25
|
+
puts "Done."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module RakeTemplate
|
4
|
+
class Template
|
5
|
+
def self.from_file(path)
|
6
|
+
new(File.read(path))
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(contents)
|
10
|
+
@contents = contents
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(parameters = {})
|
14
|
+
context = Object.new
|
15
|
+
parameters.each do |key, value|
|
16
|
+
context.instance_variable_set("@#{key}", value)
|
17
|
+
end
|
18
|
+
context_binding = context.instance_eval {binding}
|
19
|
+
ERB.new(@contents).result(context_binding)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake_template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Clemson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake_factory
|
@@ -199,6 +199,9 @@ files:
|
|
199
199
|
- config/secrets/rubygems/credentials
|
200
200
|
- go
|
201
201
|
- lib/rake_template.rb
|
202
|
+
- lib/rake_template/tasks.rb
|
203
|
+
- lib/rake_template/tasks/render.rb
|
204
|
+
- lib/rake_template/template.rb
|
202
205
|
- lib/rake_template/version.rb
|
203
206
|
- rake_template.gemspec
|
204
207
|
- scripts/ci/common/configure-git.sh
|