mattpuchlerz-liquid_premailer 0.0.2
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/CHANGELOG +4 -0
- data/LICENSE +21 -0
- data/README.rdoc +84 -0
- data/bin/liquid_premailer +106 -0
- metadata +64 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 Matt Puchlerz, The Killswitch Collective
|
2
|
+
http://killswitchcollective.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= Liquid Premailer
|
2
|
+
|
3
|
+
<em>Developed by Matt Puchlerz, The Killswitch Collective (http://killswitchcollective.com) 02.10.2009</em>
|
4
|
+
|
5
|
+
As awesome as the Premailer gem is, it didn't help with making Liquid templates any easier. My idea was to create a simple, consistent method by which you could write your markup, style it, premailer-it, and have the associated Liquid calls right there as well.
|
6
|
+
|
7
|
+
Using liquid_premailer on the command line will convert your source HTML file, filled with dummy data and commented-out Liquid calls, into ready-to-go Liquid email templates.
|
8
|
+
|
9
|
+
== Examples
|
10
|
+
|
11
|
+
=== Using the liquid_premailer Command
|
12
|
+
|
13
|
+
$ liquid_premailer myfile.html
|
14
|
+
|
15
|
+
...will output myfile_liquid.html. That's it!
|
16
|
+
|
17
|
+
=== Dummy Data and Hidden Liquid Output
|
18
|
+
|
19
|
+
<style type="text/css">
|
20
|
+
h1 {
|
21
|
+
font-family: verdana, sans-serif;
|
22
|
+
font-size: 20px;
|
23
|
+
}
|
24
|
+
</style>
|
25
|
+
|
26
|
+
<h1><!---->Here is a Fake Headline<!--{{ email.headline }}--></h1>
|
27
|
+
|
28
|
+
...will become...
|
29
|
+
|
30
|
+
<h1 style="font-family: verdana, sans-serif; font-size: 20px;">{{ email.headline }}</h1>
|
31
|
+
|
32
|
+
=== Hidden Liquid Tags
|
33
|
+
|
34
|
+
<!--{% if email.is_a_pain %}-->
|
35
|
+
<p>Man, HTML emails are a pain to work with.</p>
|
36
|
+
<!--{% endif %}-->
|
37
|
+
|
38
|
+
...will become...
|
39
|
+
|
40
|
+
{% if email.is_a_pain %}
|
41
|
+
<p>Man, HTML emails are a pain to work with.</p>
|
42
|
+
{% endif %}
|
43
|
+
|
44
|
+
=== Complex Example
|
45
|
+
|
46
|
+
<style type="text/css">
|
47
|
+
p {
|
48
|
+
font-family: verdana, sans-serif;
|
49
|
+
font-size: 12px;
|
50
|
+
}
|
51
|
+
span.phone {
|
52
|
+
color: red;
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
|
56
|
+
<p>
|
57
|
+
<!--{% if sender.phone != blank %}-->
|
58
|
+
<span class="phone"><!---->123-456-7890<!--{{ sender.phone }}--></span><br />
|
59
|
+
<!--{% endif %}-->
|
60
|
+
<!--{% if sender.mobile_phone != blank %}-->
|
61
|
+
<span class="mobile"><!---->098-765-4321<!--{{ sender.mobile_phone }}--> (mobile)</span>
|
62
|
+
<!--{% endif %}-->
|
63
|
+
</p>
|
64
|
+
|
65
|
+
...will become...
|
66
|
+
|
67
|
+
<p style="font-family: verdana, sans-serif; font-size: 12px;">
|
68
|
+
{% if sender.phone != blank %}
|
69
|
+
<span>{{ sender.phone }}</span><br />
|
70
|
+
{% endif %}
|
71
|
+
{% if sender.mobile_phone != blank %}
|
72
|
+
<span style="color: red;">{{ sender.mobile_phone }} (mobile)</span>
|
73
|
+
{% endif %}
|
74
|
+
</p>
|
75
|
+
|
76
|
+
== Requirements, installation and use
|
77
|
+
|
78
|
+
First, download and install the Premailer gem from http://code.dunae.ca/premailer.web/local.html.
|
79
|
+
|
80
|
+
Then install the liquid_premailer gem:
|
81
|
+
|
82
|
+
$ sudo gem install mattpuchlerz-liquid_premailer
|
83
|
+
|
84
|
+
liquid_premailer should now be available in your path.
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'optparse/time'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
def exit_with_error(opts, msg = '')
|
9
|
+
puts msg + "\n\n" unless msg.empty?
|
10
|
+
puts opts
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
################################################################################
|
15
|
+
|
16
|
+
options = OpenStruct.new
|
17
|
+
options.plaintext = false
|
18
|
+
options.querystring = ''
|
19
|
+
options.baseurl = ''
|
20
|
+
options.warnings = false
|
21
|
+
|
22
|
+
opts = OptionParser.new do |opts|
|
23
|
+
opts.banner = "Usage: liquid_premailer inputfile outputfile [options]\n Examples:\n"
|
24
|
+
opts.banner << " liquid_premailer myfile.html\n"
|
25
|
+
opts.banner << " liquid_premailer http://example.com/myfile.html myliquidfile.html -w -q src=email"
|
26
|
+
opts.separator ""
|
27
|
+
opts.separator "Specific options:"
|
28
|
+
|
29
|
+
opts.on("-t", "--plaintext", "Create plain-text version") do |t|
|
30
|
+
options.plaintext = t
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-q", "--querystring [STRING]", "Query string to append to links") do |qs|
|
34
|
+
options.querystring = qs || ''
|
35
|
+
options.querystring.gsub!(/^\?/, '')
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-b", "--baseurl [STRING]", "Base URL; only applies to local files") do |bs|
|
39
|
+
options.baseurl = bs
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on("-w", "--warnings", "Generate CSS/HTML warnings") do |w|
|
43
|
+
options.warnings = w
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
47
|
+
puts opts
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
opts.parse!(ARGV)
|
52
|
+
|
53
|
+
src_url = ARGV[0]
|
54
|
+
exit_with_error(opts, "You must specify a file to parse") if src_url.nil?
|
55
|
+
|
56
|
+
outfile = ARGV[1] || src_url
|
57
|
+
outfile = "#{outfile.sub('.html', '')}_liquid"
|
58
|
+
exit_with_error(opts, "You must specify an output file") if outfile.nil?
|
59
|
+
|
60
|
+
outdir = File.dirname(outfile)
|
61
|
+
|
62
|
+
unless File.exists?(outdir) and File.directory?(outdir)
|
63
|
+
FileUtils.mkdir_p outdir
|
64
|
+
end
|
65
|
+
|
66
|
+
################################################################################
|
67
|
+
|
68
|
+
puts "Parsing #{src_url}"
|
69
|
+
puts " - plaintext: #{options.plaintext}"
|
70
|
+
puts " - querystring: #{options.querystring}"
|
71
|
+
|
72
|
+
unless src_url =~ /^(http|https|ftp)\:\/\//i
|
73
|
+
raise "Could not find #{src_url}" unless File.exists?(src_url)
|
74
|
+
end
|
75
|
+
|
76
|
+
premailer_cmd = "premailer #{src_url} #{outfile}"
|
77
|
+
premailer_cmd << " -t" if options.plaintext
|
78
|
+
premailer_cmd << " -q" unless options.querystring.empty?
|
79
|
+
premailer_cmd << " -b" unless options.baseurl.empty?
|
80
|
+
premailer_cmd << " -w" if options.warnings
|
81
|
+
`#{premailer_cmd}`
|
82
|
+
|
83
|
+
outfile << ".html"
|
84
|
+
|
85
|
+
################################################################################
|
86
|
+
|
87
|
+
html = File.new(outfile).read
|
88
|
+
liquid_file = File.new(outfile, 'w')
|
89
|
+
|
90
|
+
html.gsub!('%7B', '{')
|
91
|
+
html.gsub!('%7D', '}')
|
92
|
+
html.gsub!('%20', ' ')
|
93
|
+
|
94
|
+
html.gsub!(/ id=\".+?\"/, '')
|
95
|
+
html.gsub!(/ class=\"editable\"/, ' temp_editable')
|
96
|
+
html.gsub!(/ class=\".+?\"/, '')
|
97
|
+
html.gsub!(' temp_editable', ' class="editable"')
|
98
|
+
|
99
|
+
html.gsub!(/<!---->.+?<!--(.+?)-->/m, '\1')
|
100
|
+
html.gsub!(/<!--\s*\{\%/, '{%')
|
101
|
+
html.gsub!(/\%\}\s*-->/, '%}')
|
102
|
+
|
103
|
+
liquid_file.write(html)
|
104
|
+
liquid_file.close
|
105
|
+
|
106
|
+
puts "Finished premailer-ing and dummy-data-stripping and liquid-ing #{outfile}"
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattpuchlerz-liquid_premailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Puchlerz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-05 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: premailer
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.0
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: matt@killswitchcollective.com
|
26
|
+
executables:
|
27
|
+
- liquid_premailer
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- README.rdoc
|
34
|
+
- CHANGELOG
|
35
|
+
- LICENSE
|
36
|
+
- bin/liquid_premailer
|
37
|
+
has_rdoc: false
|
38
|
+
homepage: http://killswitchcollective.com
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Takes an HTML file, premailer-izes it, and then strips out any dummy data you have in place of Liquid calls.
|
63
|
+
test_files: []
|
64
|
+
|