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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37f8600f2a05a1fb8407741f16ae2a2597460a47b03109906eb2761c64316766
4
- data.tar.gz: caaa0bd1fc564d110b53343201201f43c227953d04016ff54b42f9587517aa93
3
+ metadata.gz: 74cb5ffbabf0716b59a0894113a78b24b8b2c1ffe5f20224ec60ad4efb0e60aa
4
+ data.tar.gz: 2a049f47430f2a2aa45cfd2c7641281068da25af6d2bbba7de62f1372e02d8b0
5
5
  SHA512:
6
- metadata.gz: f1b73a183b889305b8d6cae158f52ddb00ed151c590aa2254ff2462b8293142582871c2f26c30739587e5c2ed5e4a6ab9cb7f608966af3474c0ecc8a087d0ffd
7
- data.tar.gz: 321c9806c86632d2d3421da98d0a6cb8378bafc38535f4c196ffd496f8154ed7a62ca4ac0bc45b9cc38122a109a66c6e13906a8674fa5953943070881794392f
6
+ metadata.gz: 57c9807907c9831169b98344ada306e3a7dff73b2af20788e13fd775b20c2d9432cdd1a67bc954bc5299e09cad31f9174d7760c482bfc769492d1415664edac5
7
+ data.tar.gz: b9139e73cec066f2b863dfd3a873db29e9642958e50e9a08842e1264f72373499e0347df125695f707b0f0f4ef7347c2f1a63a9f39ec2f3740d92770fac67903
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_template (0.1.0.pre.2)
4
+ rake_template (0.1.0.pre.3)
5
5
  rake_factory (~> 0.23)
6
6
 
7
7
  GEM
@@ -1,4 +1,8 @@
1
+ require 'rake_template/tasks'
1
2
  require 'rake_template/version'
2
3
 
3
4
  module RakeTemplate
5
+ def self.define_render_task(opts = {}, &block)
6
+ RakeTemplate::Tasks::Render.define(opts, &block)
7
+ end
4
8
  end
@@ -0,0 +1,7 @@
1
+ require_relative 'tasks/render'
2
+
3
+ module RakeTemplate
4
+ module Tasks
5
+
6
+ end
7
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RakeTemplate
2
- VERSION = '0.1.0.pre.2'
2
+ VERSION = '0.1.0.pre.3'
3
3
  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.2
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-08 00:00:00.000000000 Z
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