malvolio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +184 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +61 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/malvolio +6 -0
  12. data/bin/setup +8 -0
  13. data/lib/generators/malvolio/create_generator.rb +27 -0
  14. data/lib/generators/malvolio/create_with_inky_generator.rb +27 -0
  15. data/lib/generators/malvolio/templates/base/config.yaml +1 -0
  16. data/lib/generators/malvolio/templates/base/index.html +16 -0
  17. data/lib/generators/malvolio/templates/base/index.scss +0 -0
  18. data/lib/generators/malvolio/templates/base_with_inky/config.yaml +1 -0
  19. data/lib/generators/malvolio/templates/base_with_inky/index.html +22 -0
  20. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/_foundation_emails.scss +27 -0
  21. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/_global.scss +95 -0
  22. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_alignment.scss +88 -0
  23. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_button.scss +312 -0
  24. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_callout.scss +85 -0
  25. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_code.scss +0 -0
  26. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_media-query.scss +139 -0
  27. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_menu.scss +83 -0
  28. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_normalize.scss +86 -0
  29. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_outlook-first.scss +11 -0
  30. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_thumbnail.scss +49 -0
  31. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_typography.scss +404 -0
  32. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_visibility.scss +66 -0
  33. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/grid/_block-grid.scss +32 -0
  34. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/grid/_grid.scss +180 -0
  35. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/settings/_settings.scss +148 -0
  36. data/lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/util/_util.scss +22 -0
  37. data/lib/generators/malvolio/templates/base_with_inky/scss/index.scss +1 -0
  38. data/lib/malvolio.rb +7 -0
  39. data/lib/malvolio/cli.rb +50 -0
  40. data/lib/malvolio/compiler.rb +85 -0
  41. data/lib/malvolio/version.rb +3 -0
  42. data/malvolio.gemspec +46 -0
  43. metadata +228 -0
@@ -0,0 +1,85 @@
1
+ require "yaml"
2
+ require "inky"
3
+ require "sass/plugin"
4
+ require "premailer"
5
+
6
+ module Malvolio
7
+ class Compiler
8
+ def initialize(path = nil, no_warnings = false)
9
+ @path = File.expand_path(path || ".")
10
+ @config = YAML.load_file(File.join(@path, "config.yaml"))
11
+ @compiler = Sass::Plugin::Compiler.new
12
+ @compiler.on_compilation_error do |error, template, _css|
13
+ raise Malvolio::CompilationError, compilation_error(error, template)
14
+ end
15
+ @no_warnings = no_warnings
16
+ end
17
+
18
+ def run!
19
+ convert_html
20
+ compile_sass_to_css
21
+ inline_styles
22
+ clean_tmp_folder
23
+ print_colorized("New HTML email build was a success!", 32)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :path, :config, :compiler, :no_warnings
29
+
30
+ def convert_html
31
+ src_path = File.join(path, "src", "index.html")
32
+ dest_path = File.join(path, "tmp", "index.html")
33
+ if config["inky"]
34
+ html_string = File.read(src_path)
35
+ html_output = Inky::Core.new.release_the_kraken(html_string)
36
+ File.write(dest_path, html_output)
37
+ else
38
+ FileUtils.cp(src_path, dest_path)
39
+ end
40
+ end
41
+
42
+ def compile_sass_to_css
43
+ src_path = File.join(path, "src", "scss", "index.scss")
44
+ dest_path = File.join(path, "tmp", "index.css")
45
+ compiler.update_stylesheets([[src_path, dest_path]])
46
+ end
47
+
48
+ def inline_styles
49
+ src_path = File.join(path, "tmp", "index.html")
50
+ dist_path = File.join(path, "dist", "index.html")
51
+ warn_level = no_warnings ? Premailer::Warnings::NONE : Premailer::Warnings::SAFE
52
+ premailer = Premailer.new(src_path, warn_level: warn_level)
53
+ File.open(dist_path, "w") do |file|
54
+ file.puts premailer.to_inline_css
55
+ end
56
+ premailer.warnings.each do |warning|
57
+ print_premailer_warning(warning)
58
+ end
59
+ end
60
+
61
+ def clean_tmp_folder
62
+ remove_path = Dir[File.join(path, "tmp", "*")]
63
+ FileUtils.rm_rf(remove_path)
64
+ end
65
+
66
+ def compilation_error(error, template)
67
+ "Sass failed to compile. Error found in #{template}\n#{error}"
68
+ end
69
+
70
+ def print_colorized(string, code)
71
+ puts "\e[#{code}m#{string}\e[0m"
72
+ end
73
+
74
+ def print_premailer_warning(warning)
75
+ message = "(#{warning[:level]}) #{warning[:message]} may not render properly "\
76
+ "in the following clients:\n\t#{warning[:clients]}"
77
+ code = premailer_risk_color_codes[warning[:level]]
78
+ print_colorized(message, code)
79
+ end
80
+
81
+ def premailer_risk_color_codes
82
+ {"SAFE" => 32, "NONE" => 32, "POOR" => 33, "RISKY" => 31}
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module Malvolio
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,46 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "malvolio/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "malvolio"
8
+ spec.version = Malvolio::VERSION
9
+ spec.authors = ["Josh Reinhardt"]
10
+ spec.email = ["jereinhardt415@gmail.com"]
11
+
12
+ spec.summary = %q{A command line tool for building HTML emails.}
13
+ spec.description = %q{A command line tool for building HTML emails.}
14
+ spec.homepage = "https://github.com/jereinhardt/malvolio"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/jereinhardt/malvolio"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.executables = ["malvolio"]
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_dependency "thor"
36
+ spec.add_dependency "inky-rb"
37
+ spec.add_dependency "premailer"
38
+ spec.add_dependency "filewatcher"
39
+ spec.add_dependency "compass"
40
+ spec.add_dependency "sass"
41
+
42
+ spec.add_development_dependency "rails"
43
+ spec.add_development_dependency "bundler", "~> 1.17"
44
+ spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "rspec", "~> 3.0"
46
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: malvolio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Reinhardt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: inky-rb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: premailer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: filewatcher
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: compass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sass
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.17'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
153
+ description: A command line tool for building HTML emails.
154
+ email:
155
+ - jereinhardt415@gmail.com
156
+ executables:
157
+ - malvolio
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - bin/console
170
+ - bin/malvolio
171
+ - bin/setup
172
+ - lib/generators/malvolio/create_generator.rb
173
+ - lib/generators/malvolio/create_with_inky_generator.rb
174
+ - lib/generators/malvolio/templates/base/config.yaml
175
+ - lib/generators/malvolio/templates/base/index.html
176
+ - lib/generators/malvolio/templates/base/index.scss
177
+ - lib/generators/malvolio/templates/base_with_inky/config.yaml
178
+ - lib/generators/malvolio/templates/base_with_inky/index.html
179
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/_foundation_emails.scss
180
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/_global.scss
181
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_alignment.scss
182
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_button.scss
183
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_callout.scss
184
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_code.scss
185
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_media-query.scss
186
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_menu.scss
187
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_normalize.scss
188
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_outlook-first.scss
189
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_thumbnail.scss
190
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_typography.scss
191
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/components/_visibility.scss
192
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/grid/_block-grid.scss
193
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/grid/_grid.scss
194
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/settings/_settings.scss
195
+ - lib/generators/malvolio/templates/base_with_inky/scss/foundation_emails/util/_util.scss
196
+ - lib/generators/malvolio/templates/base_with_inky/scss/index.scss
197
+ - lib/malvolio.rb
198
+ - lib/malvolio/cli.rb
199
+ - lib/malvolio/compiler.rb
200
+ - lib/malvolio/version.rb
201
+ - malvolio.gemspec
202
+ homepage: https://github.com/jereinhardt/malvolio
203
+ licenses:
204
+ - MIT
205
+ metadata:
206
+ homepage_uri: https://github.com/jereinhardt/malvolio
207
+ source_code_uri: https://github.com/jereinhardt/malvolio
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 2.7.6
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: A command line tool for building HTML emails.
228
+ test_files: []