mandrill-template-manager 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mandrill_template/cli.rb +27 -1
- data/mandrill-template-manager.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 497f8837541cb94617a859849e922a4453e44eff
|
4
|
+
data.tar.gz: 3bce101be2c0cec531c19f9578767f4dc98d1c88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9950d411e0efa386ec90ede940715c6e01ab5761f368bc14e76e75966c6b132872efa3832c6015832e2c82cd05c75c831259840d80e059acb7059006492c7e18
|
7
|
+
data.tar.gz: ff2cfc9dce47f6716153e2d71d7c2ff157174fcea1fa5cddb2574373377054b657b6314f650f631834bf836a9906f546e91b1a165c492f83ab2eb2b4c463058e
|
@@ -5,10 +5,11 @@ require 'formatador'
|
|
5
5
|
require 'unicode' unless ['jruby'].include?(RbConfig::CONFIG['ruby_install_name'])
|
6
6
|
require 'yaml'
|
7
7
|
require "mandrill_template/monkey_create_file"
|
8
|
+
autoload "Handlebars", 'handlebars'
|
8
9
|
|
9
10
|
class MandrillTemplateManager < Thor
|
10
11
|
include Thor::Actions
|
11
|
-
VERSION = "0.
|
12
|
+
VERSION = "0.2.0"
|
12
13
|
|
13
14
|
desc "export NAME", "export template from remote to local files."
|
14
15
|
def export(name)
|
@@ -50,6 +51,25 @@ class MandrillTemplateManager < Thor
|
|
50
51
|
puts MandrillClient.client.templates.publish(name).to_yaml
|
51
52
|
end
|
52
53
|
|
54
|
+
desc "render NAME [PARAMS_FILE]", "render mailbody from local template data. File should be Array. see https://mandrillapp.com/api/docs/templates.JSON.html#method=render."
|
55
|
+
option :handlebars, type: :boolean, default: false
|
56
|
+
def render(name, params = nil)
|
57
|
+
merge_vars = params ? JSON.parse(File.read(params)) : []
|
58
|
+
template = MandrillTemplate::Local.new(name)
|
59
|
+
if template.avail
|
60
|
+
if options[:handlebars]
|
61
|
+
handlebars = Handlebars::Context.new
|
62
|
+
h_template = handlebars.compile(template['code'])
|
63
|
+
puts h_template.call(localize_merge_vars(merge_vars))
|
64
|
+
else
|
65
|
+
result = MandrillClient.client.templates.render template.name, template['code'], merge_vars
|
66
|
+
puts result["html"]
|
67
|
+
end
|
68
|
+
else
|
69
|
+
puts "Template data not found #{name}. Please generate first."
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
53
73
|
desc "list", "show template list both of remote and local."
|
54
74
|
def list
|
55
75
|
puts "Remote Templates"
|
@@ -162,4 +182,10 @@ class MandrillTemplateManager < Thor
|
|
162
182
|
false
|
163
183
|
end
|
164
184
|
end
|
185
|
+
|
186
|
+
def localize_merge_vars(merge_vars)
|
187
|
+
h = {}
|
188
|
+
merge_vars.each {|kv| h[kv["name"]] = kv["content"] }
|
189
|
+
h
|
190
|
+
end
|
165
191
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandrill-template-manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawanoboly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.4.
|
180
|
+
rubygems_version: 2.4.8
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Manage Mandrill Template CLI
|