chimplate 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +0 -4
- data/Gemfile.lock +5 -4
- data/bin/chimplate +18 -1
- data/chimplate.gemspec +1 -0
- data/lib/chimplate/base.rb +46 -21
- data/lib/chimplate/version.rb +1 -1
- data/readme.md +17 -3
- metadata +17 -1
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
chimplate (0.0.
|
4
|
+
chimplate (0.0.2)
|
5
|
+
diffy
|
5
6
|
json
|
7
|
+
listen
|
6
8
|
mailchimp
|
7
9
|
thor
|
8
10
|
|
9
11
|
GEM
|
10
12
|
remote: https://rubygems.org/
|
11
13
|
specs:
|
14
|
+
diffy (2.1.4)
|
12
15
|
httparty (0.11.0)
|
13
16
|
multi_json (~> 1.0)
|
14
17
|
multi_xml (>= 0.5.2)
|
15
18
|
json (1.7.7)
|
19
|
+
listen (0.7.3)
|
16
20
|
mailchimp (0.0.8)
|
17
21
|
httparty
|
18
22
|
multi_json (1.7.2)
|
@@ -24,6 +28,3 @@ PLATFORMS
|
|
24
28
|
|
25
29
|
DEPENDENCIES
|
26
30
|
chimplate!
|
27
|
-
json
|
28
|
-
mailchimp
|
29
|
-
thor
|
data/bin/chimplate
CHANGED
@@ -34,8 +34,14 @@ class ChimplateCli < Thor
|
|
34
34
|
end
|
35
35
|
|
36
36
|
desc "push", "Push current disk versions of templates to mailchimp."
|
37
|
+
option :filename, :default => ""
|
37
38
|
def push
|
38
|
-
|
39
|
+
unless options[:filename].empty?
|
40
|
+
puts "File #{options[:filename]} does not exist." and return unless File.exists? options[:filename]
|
41
|
+
Chimplate::Base.push_file(options[:filename])
|
42
|
+
else
|
43
|
+
Chimplate::Base.push
|
44
|
+
end
|
39
45
|
end
|
40
46
|
|
41
47
|
desc "watch", "Watch for file changes and push them to Mailchimp."
|
@@ -48,6 +54,17 @@ class ChimplateCli < Thor
|
|
48
54
|
|
49
55
|
listener.start
|
50
56
|
end
|
57
|
+
|
58
|
+
desc "diff", "Show the difference between Mailchimp's copy and my copy."
|
59
|
+
option :filename, :default => ""
|
60
|
+
def diff
|
61
|
+
unless options[:filename].empty?
|
62
|
+
puts "File #{options[:filename]} does not exist." and return unless File.exists? options[:filename]
|
63
|
+
Chimplate::Base.diff_file(options[:filename])
|
64
|
+
else
|
65
|
+
Chimplate::Base.diff
|
66
|
+
end
|
67
|
+
end
|
51
68
|
end
|
52
69
|
|
53
70
|
ChimplateCli.start(ARGV)
|
data/chimplate.gemspec
CHANGED
data/lib/chimplate/base.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "mailchimp"
|
2
2
|
require "yaml"
|
3
|
+
require "diffy"
|
3
4
|
|
4
5
|
module Chimplate
|
5
6
|
class Base
|
@@ -15,27 +16,27 @@ module Chimplate
|
|
15
16
|
|
16
17
|
def self.pull(options = {})
|
17
18
|
api.templates["user"].each do |template_info|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
template = api.templateInfo "tid" => template_info["id"]
|
20
|
+
filename = Dir.pwd + "/" + template_info["id"].to_s + "-" + sanitize_filename(template_info["name"]) + ".html"
|
21
|
+
|
22
|
+
write = true
|
23
|
+
if File.exist? filename
|
24
|
+
if options[:force] || yield(filename)
|
25
|
+
FileUtils.rm filename
|
26
|
+
else
|
27
|
+
puts "Skipping #{filename}.\n"
|
28
|
+
write = false
|
29
|
+
end
|
28
30
|
end
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if write
|
33
|
+
File.open(filename, "w+") do |file|
|
34
|
+
file.write(template["source"])
|
35
|
+
puts "Saved template #{filename}.\n";
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
41
|
def self.push
|
41
42
|
Dir.glob("*-*.html").each do |template_filename|
|
@@ -44,23 +45,47 @@ module Chimplate
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def self.push_file(template_filename)
|
47
|
-
|
48
|
+
file_data = file_info(template_filename)
|
48
49
|
|
49
50
|
File.open template_filename, "rb" do |file|
|
50
|
-
if tid == "new"
|
51
|
-
new_tid = api.templateAdd :name => template_name.gsub("_", " "), :html => file.read
|
52
|
-
new_filename = new_tid.to_s + '-' + template_name + ".html"
|
51
|
+
if file_data[:tid] == "new"
|
52
|
+
new_tid = api.templateAdd :name => file_data[:template_name].gsub("_", " "), :html => file.read
|
53
|
+
new_filename = new_tid.to_s + '-' + file_data[:template_name] + ".html"
|
53
54
|
FileUtils.mv template_filename, new_filename
|
54
55
|
|
55
56
|
puts "Saved new template #{new_filename}.\n";
|
56
57
|
else
|
57
|
-
api.templateUpdate "id" => tid, "values" => { "html" => file.read }
|
58
|
+
api.templateUpdate "id" => file_data[:tid], "values" => { "html" => file.read }
|
58
59
|
puts "Updated template #{template_filename}.\n";
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
64
|
+
def self.diff_file(template_filename)
|
65
|
+
file_info = file_info(template_filename)
|
66
|
+
|
67
|
+
File.open template_filename, "rb" do |file|
|
68
|
+
template = api.templateInfo "tid" => file_info[:tid]
|
69
|
+
puts "Diff between local #{template_filename} and remote template.\n\n"
|
70
|
+
|
71
|
+
puts Diffy::Diff.new(template["source"].chomp, file.read.chomp, :context => 2, :allow_empty_diff => true).to_s(:color)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.diff
|
76
|
+
Dir.glob("*-*.html").each do |template_filename|
|
77
|
+
diff_file(template_filename)
|
78
|
+
puts "\n\n----------------------------------------------------------\n\n"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
63
82
|
protected
|
83
|
+
def self.file_info(filename)
|
84
|
+
tid, template_name = filename.gsub(".html", "").split("-")
|
85
|
+
|
86
|
+
return {:tid => tid, :template_name => template_name}
|
87
|
+
end
|
88
|
+
|
64
89
|
def self.api
|
65
90
|
if !File.exist? destination
|
66
91
|
puts "No config file here, please run `chimplate setup` first"
|
data/lib/chimplate/version.rb
CHANGED
data/readme.md
CHANGED
@@ -7,7 +7,7 @@ What is it?
|
|
7
7
|
I've found myself doing a lot of template editing for clients lately,
|
8
8
|
and though Mailchimp's excellent in-browser editing tools make it easy
|
9
9
|
to get up and running, they don't provide any of the tools required for
|
10
|
-
managing a large number of with lots of common elements, managing
|
10
|
+
managing a large number of templates with lots of common elements, managing
|
11
11
|
revisions, etc, etc.
|
12
12
|
|
13
13
|
There are tons of tools available to make this process easier, chiefly
|
@@ -87,6 +87,18 @@ want to create a new file, kill the watch process via Ctrl+C, make the
|
|
87
87
|
new file, run `chimplate push`, and then re-start the `chimplate watch`
|
88
88
|
process to resume pushing your changes on the fly back to Mailchimp.
|
89
89
|
|
90
|
+
Gotchas
|
91
|
+
-------
|
92
|
+
|
93
|
+
Once you start editing your templates this way, it's important to avoid
|
94
|
+
using Mailchimp's editor in your browser. If you make changes there, and
|
95
|
+
then don't pull them with Chimplate before pushing your local copies
|
96
|
+
again, you could overwrite the changes you made directly in Mailchimp!
|
97
|
+
There's no function in Chimplate (or in Mailchimp) for checking
|
98
|
+
modification times, so you could lose work if you aren't rigorous about
|
99
|
+
doing it all in one place (or at least all via a git repo to centralize
|
100
|
+
version control). You have been warned!
|
101
|
+
|
90
102
|
TODO
|
91
103
|
----
|
92
104
|
|
@@ -96,5 +108,7 @@ it doesn't match the expected format Chimplate will probably give you a nasty
|
|
96
108
|
stack trace and run home to mommy. Sorry! I hope to fix this soon...
|
97
109
|
3. Provide some sort of support for template deletion. At this point I'm
|
98
110
|
happy leaving it to the Mailchimp UI, since accidental deletion would be
|
99
|
-
a
|
100
|
-
|
111
|
+
a bummer.
|
112
|
+
4. Provide some diff support, so you could diff a template to see what's
|
113
|
+
different between your local copy and Mailchimp's version before you
|
114
|
+
push.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chimplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: diffy
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: A small command line utility to ease local editing and version control
|
79
95
|
of mailchimp user templates.
|
80
96
|
email: matt@bitforge.us
|