smallvictories 0.0.9 → 0.0.10

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
  SHA1:
3
- metadata.gz: b9faaa62c962fb36e4741fc2b55cbd053bffc334
4
- data.tar.gz: 01bc63dbf679d4da0909ee511c7ed2b10093f478
3
+ metadata.gz: 645eeae3478242e8e50693c5c870569981900c6d
4
+ data.tar.gz: 51c13ab7acb1edace8fea0023e73b1e338cf6baf
5
5
  SHA512:
6
- metadata.gz: f97d08f54216b0f09e7627ea54efdd2455cf09e2e8ec047a32682c57c5659268c1027f716bd1cc768df88b29ad539994bb39e63497f572e97469857f6421755c
7
- data.tar.gz: 2ca870ab41183e1e1ccedf8fccafce87c0820594a4e2eab9815c4026b2b7ce2466ead422a2e3bd701b0485a70cf82d9c371cc9aef33a15ddb6b4bba223540929
6
+ metadata.gz: 601dbb360a1113f48516f974500cdf7d36f46eb2cf90d8ff1c06034be1019718eaba42bb143817d9b08ab86ee6034be2e7431a93ab5506383fd78224dffe52e0
7
+ data.tar.gz: 102454bbde1a782a7003f606c76fe71cd84602762c1c44e0dd8b6795a7142658bef8b687c828b70d5310e3a24bc866d4c590738a02fae943664943eda891b955
data/README.md CHANGED
@@ -55,6 +55,12 @@ folder.
55
55
 
56
56
  Command: `sv compile`
57
57
 
58
+ ### Inline
59
+
60
+ Compile files and then inline CSS in your HTML files.
61
+
62
+ Command: `sv inline`
63
+
58
64
  ### Watch
59
65
 
60
66
  Watch for changes then compile files and notify LiveReload.
@@ -64,13 +70,13 @@ Command: `sv watch`
64
70
  ### Default Folder Structure
65
71
 
66
72
  The default setup for Small Victories is to have your production files in the
67
- root and your development files in the `_` directory.
73
+ root and your development files in the `src` directory.
68
74
 
69
75
  ```text
70
76
  Dropbox
71
77
  └── Small Victories
72
78
  └── Your Site
73
- └── _
79
+ └── src
74
80
  │ ├── _includes
75
81
  │ │ └── _head.liquid
76
82
  │ ├── _layout.liquid
@@ -84,7 +90,7 @@ Dropbox
84
90
  ```
85
91
 
86
92
  You would then run `sv watch` from within `Your Site` and Small Victories will
87
- watch for changes in `_` and compile them to the `Your Site` folder.
93
+ watch for changes in `src` and compile them to the `Your Site` folder.
88
94
 
89
95
  ## How does it work with Small Victories?
90
96
 
@@ -135,7 +141,7 @@ You can set the following options:
135
141
  ### Default Configuration
136
142
 
137
143
  ```yaml
138
- source: '_'
144
+ source: 'src'
139
145
  destination: ''
140
146
  source_stylesheet: 'application.css'
141
147
  source_javascript: 'application.js'
data/bin/sv CHANGED
@@ -9,6 +9,7 @@ def help
9
9
  Commands:
10
10
  bootstrap, bootstrap FOLDER Setup folder with default files
11
11
  compile Compile files
12
+ inline Inline CSS in your HTML files
12
13
  watch Watch for changes and compile files
13
14
  help Prints this help document
14
15
  version Prints the small victories gem version
@@ -36,7 +37,29 @@ def compile
36
37
  compiler.compile_html
37
38
  end
38
39
 
40
+ def inline
41
+ config = SmallVictories::Configuration.new
42
+ compiler = SmallVictories::Compiler.new(config: config)
43
+ compiler.compile_css
44
+ compiler.compile_js
45
+ compiler.compile_html
46
+ compiler.minify_css
47
+ compiler.minify_js
48
+ compiler.inline_html
49
+ end
50
+
51
+ def minify
52
+ config = SmallVictories::Configuration.new
53
+ compiler = SmallVictories::Compiler.new(config: config)
54
+ compiler.compile_css
55
+ compiler.compile_js
56
+ compiler.compile_html
57
+ compiler.minify_css
58
+ compiler.minify_js
59
+ end
60
+
39
61
  def watch
62
+ compile
40
63
  config = SmallVictories::Configuration.new
41
64
  compiler = SmallVictories::Compiler.new(config: config)
42
65
  watcher = SmallVictories::Watcher.new(compiler: compiler)
@@ -52,6 +75,8 @@ when 'bootstrap'
52
75
  bootstrap ARGV[1]
53
76
  when 'compile'
54
77
  compile
78
+ when 'inline'
79
+ inline
55
80
  when 'watch'
56
81
  watch
57
82
  else
@@ -1,6 +1,7 @@
1
1
  require 'sprockets'
2
2
  require 'autoprefixer-rails'
3
3
  require 'liquid'
4
+ require 'premailer'
4
5
 
5
6
  module SmallVictories
6
7
  class Compiler
@@ -22,6 +23,10 @@ module SmallVictories
22
23
  liquid
23
24
  end
24
25
 
26
+ def inline_html
27
+ premail
28
+ end
29
+
25
30
  def liquid
26
31
  begin
27
32
  Liquid::Template.file_system = Liquid::LocalFileSystem.new(config.full_includes_path)
@@ -95,7 +100,7 @@ module SmallVictories
95
100
  sprockets.append_path(config.full_destination_path)
96
101
  if assets = sprockets.find_asset(config.stylesheets.last)
97
102
  assets.write_to File.join(config.full_destination_path, config.stylesheets.last)
98
- SmallVictories.logger.info "prefixed #{config.destination}/#{config.stylesheets.last}"
103
+ SmallVictories.logger.info "prefixed #{File.join(config.destination,config.stylesheets.last)}"
99
104
  end
100
105
  rescue => e
101
106
  SmallVictories.logger.error "#{path}\n#{e}\n#{e.backtrace.first}"
@@ -110,5 +115,29 @@ module SmallVictories
110
115
  def minify_js
111
116
  package [config.javascripts], { js_compressor: :closure }
112
117
  end
118
+
119
+ def premail
120
+ Dir.glob([File.join(config.full_destination_path, '*.html')]) do |path|
121
+ begin
122
+ premailer = Premailer.new(path, warn_level: Premailer::Warnings::SAFE)
123
+ File.open(path, 'w') { |file| file.write(premailer.to_inline_css) }
124
+
125
+ # Output any CSS warnings
126
+ premailer.warnings.each do |w|
127
+ SmallVictories.logger.warn "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}"
128
+ end
129
+ file_name = Pathname.new(path).basename
130
+ SmallVictories.logger.info "inlined #{File.join(config.destination, file_name)}"
131
+ size = File.size(path)
132
+ if size > 102000
133
+ SmallVictories.logger.warn "size is greater than 120kb (#{size})"
134
+ else
135
+ SmallVictories.logger.info "size is less than 120kb (#{size})"
136
+ end
137
+ rescue => e
138
+ SmallVictories.logger.error "Inline Error\n#{e}"
139
+ end
140
+ end
141
+ end
113
142
  end
114
143
  end
@@ -10,6 +10,8 @@ module SmallVictories
10
10
  case severity
11
11
  when 'INFO'
12
12
  string.concat("👍 ")
13
+ when 'WARN'
14
+ string.concat("⚠️ ")
13
15
  when 'ERROR'
14
16
  string.concat("🔥 ")
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module SmallVictories
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -29,6 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency 'uglifier', '~> 2.7'
30
30
  spec.add_runtime_dependency 'yui-compressor', '~> 0.12'
31
31
  spec.add_runtime_dependency 'closure-compiler', '~> 1.1'
32
+ spec.add_runtime_dependency 'premailer', '~> 1.8'
33
+ spec.add_runtime_dependency 'nokogiri', '~> 1.4'
32
34
 
33
35
  spec.add_development_dependency "bundler", "~> 1.7"
34
36
  spec.add_development_dependency "rake", "~> 10.0"
@@ -84,6 +84,18 @@ describe SmallVictories do
84
84
  end
85
85
  end
86
86
 
87
+ describe '#inline_html' do
88
+ before do
89
+ FileUtils.cp('fixtures/email/index.html', 'fixtures/destination')
90
+ FileUtils.cp('fixtures/email/_sv_custom.css', 'fixtures/destination')
91
+ end
92
+
93
+ it 'inlines the compiled files' do
94
+ compiler.inline_html
95
+ expect(File.open(destination_html).read).to include "<p style=\"font-size: 12px\">Hello Email Friend</p>"
96
+ end
97
+ end
98
+
87
99
  context 'with invalid files' do
88
100
  before do
89
101
  allow_any_instance_of(SmallVictories::Configuration).to receive(:source).and_return('./spec/fixtures/invalid')
@@ -1 +1,4 @@
1
- .bootstrap{color:black;box-sizing:content-box}html{background:white}body div{background:red}p{font-size:30px}
1
+ html {
2
+ background: red;
3
+ box-sizing: content-box;
4
+ }
@@ -0,0 +1,7 @@
1
+ html {
2
+ background: red;
3
+ }
4
+
5
+ p {
6
+ font-size: 12px;
7
+ }
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta name="viewport" content="width=device-width"/>
6
+ <link rel="stylesheet" href="_sv_custom.css" />
7
+ </head>
8
+ <body>
9
+ <p>Hello Email Friend</p>
10
+ </body>
11
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smallvictories
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dijkstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-24 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: autoprefixer-rails
@@ -164,6 +164,34 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: premailer
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.8'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.8'
181
+ - !ruby/object:Gem::Dependency
182
+ name: nokogiri
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.4'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.4'
167
195
  - !ruby/object:Gem::Dependency
168
196
  name: bundler
169
197
  requirement: !ruby/object:Gem::Requirement
@@ -240,6 +268,8 @@ files:
240
268
  - spec/fixtures/destination/.gitkeep
241
269
  - spec/fixtures/destination/application.css
242
270
  - spec/fixtures/destination/application.js
271
+ - spec/fixtures/email/_sv_custom.css
272
+ - spec/fixtures/email/index.html
243
273
  - spec/fixtures/invalid/_layout.liquid
244
274
  - spec/fixtures/invalid/_sass/stylesheet.scss
245
275
  - spec/fixtures/invalid/index.html
@@ -294,6 +324,8 @@ test_files:
294
324
  - spec/fixtures/destination/.gitkeep
295
325
  - spec/fixtures/destination/application.css
296
326
  - spec/fixtures/destination/application.js
327
+ - spec/fixtures/email/_sv_custom.css
328
+ - spec/fixtures/email/index.html
297
329
  - spec/fixtures/invalid/_layout.liquid
298
330
  - spec/fixtures/invalid/_sass/stylesheet.scss
299
331
  - spec/fixtures/invalid/index.html