getinline 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Gemfile +0 -7
- data/Rakefile +3 -3
- data/bin/console +5 -5
- data/exe/getinline +73 -19
- data/getinline.gemspec +15 -12
- data/lib/getinline.rb +2 -2
- data/lib/getinline/transformer.rb +11 -7
- data/lib/getinline/version.rb +1 -1
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a02e79e72792bc59b5a1f2ce8fac01f2ab49e8b4
|
4
|
+
data.tar.gz: c37596ccbd34fc3a1da68f5eeb52fa739e8d7f06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5884a60805ecdec97665505d8cfa1af06c816150c6ce28ab84afc0dd27ab5697cb3c9988eb0353dcff84ea16a7c7be1b60e0bd47f078529ed4e9ab4fbbf077a4
|
7
|
+
data.tar.gz: 0365058cdfb46720933437cd27a358c42625f6632fbd34422a6ea1a6d0f5bc12112aca649f6729ca9414e9495bfbdc4e62fb01ca83e08df43ddabcbd25440cf3
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'getinline'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
10
|
+
# require 'pry'
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
14
|
-
IRB.start
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/exe/getinline
CHANGED
@@ -5,21 +5,80 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
5
5
|
require 'getinline'
|
6
6
|
require 'optparse'
|
7
7
|
|
8
|
-
options = {
|
8
|
+
options = {
|
9
|
+
mode: :html
|
10
|
+
}
|
11
|
+
premailer_options = {
|
12
|
+
base_url: nil,
|
13
|
+
link_query_string: nil,
|
14
|
+
remove_classes: false,
|
15
|
+
verbose: false,
|
16
|
+
line_length: 9001,
|
17
|
+
warn_level: Premailer::Warnings::SAFE
|
18
|
+
}
|
9
19
|
|
10
20
|
option_parser = OptionParser.new do |opts|
|
11
21
|
executable_name = File.basename($PROGRAM_NAME)
|
12
|
-
opts.banner = "
|
13
|
-
|
22
|
+
opts.banner = "A CSS inliner for Ruby ERB templates.\n\n"
|
23
|
+
opts.define_head 'Usage: getinline <optional path> [options]'
|
24
|
+
opts.separator ''
|
25
|
+
opts.separator 'Examples:'
|
26
|
+
opts.separator " #{executable_name} ./public/index.html"
|
27
|
+
opts.separator " #{executable_name} < ./public/index.html"
|
28
|
+
opts.separator " cat ./public/index.html | #{executable_name}"
|
29
|
+
opts.separator ''
|
30
|
+
opts.separator 'Options:'
|
14
31
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
cat file_name | #{executable_name}
|
19
|
-
"
|
32
|
+
opts.on('--mode MODE', [:html, :txt], 'Output: html or txt') do |v|
|
33
|
+
options[:mode] = v
|
34
|
+
end
|
20
35
|
|
21
36
|
opts.on('-h', '--help', 'Print usage instructions') do
|
22
|
-
|
37
|
+
puts option_parser
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
|
41
|
+
# TODO: Ideally this gem would be an option within premailer and unfortunately
|
42
|
+
# there is no way to extend the premailer CLI or interface with its options so
|
43
|
+
# copying the options from premailer/executor is a temporary solution.
|
44
|
+
# Github issue: https://github.com/premailer/premailer/issues/259
|
45
|
+
opts.separator ''
|
46
|
+
opts.separator 'Premailer Options:'
|
47
|
+
|
48
|
+
opts.on('-b', '--base-url STRING', String, 'Base URL, useful for local files') do |v|
|
49
|
+
premailer_options[:base_url] = v
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-q', '--query-string STRING', String, 'Query string to append to links') do |v|
|
53
|
+
premailer_options[:link_query_string] = v
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('--css FILE,FILE', Array, 'Additional CSS stylesheets') do |v|
|
57
|
+
premailer_options[:css] = v
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on('-r', '--remove-classes', 'Remove HTML classes') do |v|
|
61
|
+
premailer_options[:remove_classes] = v
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on('-j', '--remove-scripts', 'Remove <script> elements') do |v|
|
65
|
+
premailer_options[:remove_classes] = v
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on('-l', '--line-length N', Integer, "Line length for plaintext (default: #{premailer_options[:line_length]})") do |v|
|
69
|
+
premailer_options[:line_length] = v
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on('-e', '--entities', 'Output HTML entities instead of UTF-8 when using Nokogiri') do
|
73
|
+
premailer_options[:output_encoding] = 'US-ASCII'
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on('-d', '--io-exceptions', 'Abort on I/O errors') do |v|
|
77
|
+
premailer_options[:io_exceptions] = v
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on('-v', '--verbose', 'Print additional information at runtime') do |v|
|
81
|
+
premailer_options[:verbose] = v
|
23
82
|
end
|
24
83
|
end
|
25
84
|
|
@@ -31,19 +90,14 @@ rescue OptionParser::AmbiguousOption => error
|
|
31
90
|
abort "That's an #{error}"
|
32
91
|
end
|
33
92
|
|
34
|
-
|
35
|
-
|
36
|
-
exit
|
37
|
-
end
|
38
|
-
|
39
|
-
def transform (file_contents)
|
40
|
-
transformer = Getinline::Transformer.new(file_contents)
|
93
|
+
def transform(file_contents, options, premailer_options)
|
94
|
+
transformer = Getinline::Transformer.new(file_contents, options, premailer_options)
|
41
95
|
puts transformer.transform
|
42
96
|
end
|
43
97
|
|
44
|
-
if ARGF.filename != '-'
|
45
|
-
transform
|
98
|
+
if ARGF.filename != '-' || (!STDIN.tty? && !STDIN.closed?)
|
99
|
+
transform(ARGF.read, options, premailer_options)
|
46
100
|
else
|
47
|
-
puts option_parser
|
101
|
+
puts option_parser
|
48
102
|
exit
|
49
103
|
end
|
data/getinline.gemspec
CHANGED
@@ -4,22 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'getinline/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'getinline'
|
8
8
|
spec.version = Getinline::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Jeremy Kahn', 'Travis Pennetti']
|
10
|
+
spec.email = ['jeremy@jellyvision.com', 'tpennetti@jellyvision.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'Inlines CSS styles for HTML email development'
|
13
|
+
spec.description = 'Inlines CSS styles for HTML email development and preserves ERB tags'
|
14
|
+
spec.homepage = 'https://github.com/jellyvision/getinline'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'pry', '~> 0.10.3'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_runtime_dependency 'premailer', '~> 1.8.6'
|
27
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6.6.4'
|
25
28
|
end
|
data/lib/getinline.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'getinline/version'
|
2
|
+
require 'getinline/transformer'
|
@@ -1,12 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'premailer'
|
2
|
+
require 'nokogiri'
|
2
3
|
|
3
|
-
TOKEN =
|
4
|
-
TOKENIZED_ERB_FILE_NAME =
|
4
|
+
TOKEN = '@TOKEN'
|
5
|
+
TOKENIZED_ERB_FILE_NAME = '/tmp/tokenized.erb'
|
5
6
|
|
6
7
|
module Getinline
|
7
8
|
class Transformer
|
8
|
-
def initialize
|
9
|
+
def initialize(raw_text, options = {}, premailer_options = {})
|
9
10
|
@raw_text = raw_text
|
11
|
+
@options = options
|
12
|
+
@premailer_options = premailer_options
|
10
13
|
end
|
11
14
|
|
12
15
|
def transform
|
@@ -18,8 +21,9 @@ module Getinline
|
|
18
21
|
|
19
22
|
File.write(TOKENIZED_ERB_FILE_NAME, tokenized_text)
|
20
23
|
|
21
|
-
@premailer = Premailer.new(TOKENIZED_ERB_FILE_NAME,
|
22
|
-
premailed_tokenized_text = @
|
24
|
+
@premailer = Premailer.new(TOKENIZED_ERB_FILE_NAME, @premailer_options)
|
25
|
+
premailed_tokenized_text = @options[:mode] == :txt ?
|
26
|
+
@premailer.to_plain_text : Nokogiri::HTML(@premailer.to_inline_css).to_html(encoding:'US-ASCII')
|
23
27
|
premailed_text = premailed_tokenized_text.dup
|
24
28
|
|
25
29
|
matches.each do |match|
|
@@ -29,4 +33,4 @@ module Getinline
|
|
29
33
|
premailed_text
|
30
34
|
end
|
31
35
|
end
|
32
|
-
end
|
36
|
+
end
|
data/lib/getinline/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getinline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Kahn
|
8
|
+
- Travis Pennetti
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
12
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -38,6 +39,20 @@ dependencies:
|
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.10.3
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.10.3
|
41
56
|
- !ruby/object:Gem::Dependency
|
42
57
|
name: rspec
|
43
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,9 +67,38 @@ dependencies:
|
|
52
67
|
- - ">="
|
53
68
|
- !ruby/object:Gem::Version
|
54
69
|
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: premailer
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.6
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.8.6
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: nokogiri
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.6.6.4
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.6.6.4
|
55
98
|
description: Inlines CSS styles for HTML email development and preserves ERB tags
|
56
99
|
email:
|
57
100
|
- jeremy@jellyvision.com
|
101
|
+
- tpennetti@jellyvision.com
|
58
102
|
executables:
|
59
103
|
- getinline
|
60
104
|
extensions: []
|
@@ -99,4 +143,3 @@ signing_key:
|
|
99
143
|
specification_version: 4
|
100
144
|
summary: Inlines CSS styles for HTML email development
|
101
145
|
test_files: []
|
102
|
-
has_rdoc:
|