getinline 0.1.1 → 0.1.2

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: a02e79e72792bc59b5a1f2ce8fac01f2ab49e8b4
4
- data.tar.gz: c37596ccbd34fc3a1da68f5eeb52fa739e8d7f06
3
+ metadata.gz: 52b2a9ad2702d5c0b7affe50fd0269698d22a6d9
4
+ data.tar.gz: 12c9c09a501dc65a98f346cc870e51177c639728
5
5
  SHA512:
6
- metadata.gz: 5884a60805ecdec97665505d8cfa1af06c816150c6ce28ab84afc0dd27ab5697cb3c9988eb0353dcff84ea16a7c7be1b60e0bd47f078529ed4e9ab4fbbf077a4
7
- data.tar.gz: 0365058cdfb46720933437cd27a358c42625f6632fbd34422a6ea1a6d0f5bc12112aca649f6729ca9414e9495bfbdc4e62fb01ca83e08df43ddabcbd25440cf3
6
+ metadata.gz: 4c238eca8ebe86d34dd442f300b9fecca172f4e66afada078b8155a66c36ac8f20da69e8b5c3d68d85b8b24dc8a26f11b8c8f198f8b71aec16025b1acd994ff8
7
+ data.tar.gz: f7e7c11ae032ecf5a609226d44c3c26861c9fbc78b9ea660480a378fa7203878144285f43e35908eb1efb6c16753db58a739b9753330a94f0caaf6f37f5f1e0a
data/README.md CHANGED
@@ -1,35 +1,52 @@
1
1
  # Getinline
2
2
 
3
- Inlines CSS styles for HTML email development and preserves ERB tags.
3
+ A CSS inliner for Ruby ERB templates.
4
+
5
+ The motivation for this project is automating the premailer inliner and plain text generator such that ERB template variables are respected.
4
6
 
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ Install the Getinline gem from [RubyGems](https://rubygems.org/gems/getinline):
8
10
 
9
- ```ruby
10
- gem 'getinline'
11
+ $ gem install getinline
12
+
13
+ or add it to your `Gemfile` and run `bundle`.
14
+
15
+ ## Examples
16
+
17
+ #### Command Line
18
+
19
+ `getinline` can be invoked in any of the following ways on the command line:
20
+
21
+ ```shell
22
+ getinline ./public/index.erb --mode txt
23
+ getinline < ./public/index.erb
24
+ cat ./public/index.erb | getinline
11
25
  ```
12
26
 
13
- And then execute:
27
+ #### Rake Task
14
28
 
15
- $ bundle
29
+ ```ruby
30
+ require 'getinline'
16
31
 
17
- Or install it yourself as:
32
+ namespace :generate do
33
+ desc 'Generate inlined and plain text email templates'
34
+ task emails: :environment do
18
35
 
19
- $ gem install getinline
36
+ file = File.read('./public/index.erb')
20
37
 
21
- ## Usage
38
+ html_transformer = Getinline::Transformer.new(file)
39
+ html_template = html_transformer.transform
22
40
 
23
- `getinline` can be invoked in any of the following ways:
41
+ text_transformer = Getinline::Transformer.new(file, mode: :txt)
42
+ text_template = text_transformer.transform
24
43
 
25
- ```shell
26
- getinline file_name
27
- getinline < file_name
28
- cat file_name | getinline
44
+ File.write('./public/inline/index.erb', html_template)
45
+ File.write('./public/text/index.erb', text_template)
46
+ end
47
+ end
29
48
  ```
30
49
 
31
- Output is printed to stdout.
32
-
33
50
  ## Development
34
51
 
35
52
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -40,7 +57,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
40
57
 
41
58
  Bug reports and pull requests are welcome on GitHub at https://github.com/jellyvision/getinline.
42
59
 
43
-
44
60
  ## License
45
61
 
46
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
62
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/exe/getinline CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
5
  require 'getinline'
6
6
  require 'optparse'
7
7
 
8
- options = {
8
+ getinline_options = {
9
9
  mode: :html
10
10
  }
11
11
  premailer_options = {
@@ -14,6 +14,7 @@ premailer_options = {
14
14
  remove_classes: false,
15
15
  verbose: false,
16
16
  line_length: 9001,
17
+ output_encoding: 'US-ASCII',
17
18
  warn_level: Premailer::Warnings::SAFE
18
19
  }
19
20
 
@@ -30,7 +31,7 @@ option_parser = OptionParser.new do |opts|
30
31
  opts.separator 'Options:'
31
32
 
32
33
  opts.on('--mode MODE', [:html, :txt], 'Output: html or txt') do |v|
33
- options[:mode] = v
34
+ getinline_options[:mode] = v
34
35
  end
35
36
 
36
37
  opts.on('-h', '--help', 'Print usage instructions') do
@@ -69,8 +70,8 @@ option_parser = OptionParser.new do |opts|
69
70
  premailer_options[:line_length] = v
70
71
  end
71
72
 
72
- opts.on('-e', '--entities', 'Output HTML entities instead of UTF-8 when using Nokogiri') do
73
- premailer_options[:output_encoding] = 'US-ASCII'
73
+ opts.on('-n', '--no-entities', 'Output UTF-8 instead of HTML entities when using Nokogiri') do
74
+ premailer_options[:output_encoding] = nil
74
75
  end
75
76
 
76
77
  opts.on('-d', '--io-exceptions', 'Abort on I/O errors') do |v|
@@ -90,13 +91,13 @@ rescue OptionParser::AmbiguousOption => error
90
91
  abort "That's an #{error}"
91
92
  end
92
93
 
93
- def transform(file_contents, options, premailer_options)
94
- transformer = Getinline::Transformer.new(file_contents, options, premailer_options)
94
+ def transform(file_contents, getinline_options, premailer_options)
95
+ transformer = Getinline::Transformer.new(file_contents, getinline_options, premailer_options)
95
96
  puts transformer.transform
96
97
  end
97
98
 
98
99
  if ARGF.filename != '-' || (!STDIN.tty? && !STDIN.closed?)
99
- transform(ARGF.read, options, premailer_options)
100
+ transform(ARGF.read, getinline_options, premailer_options)
100
101
  else
101
102
  puts option_parser
102
103
  exit
@@ -1,7 +1,7 @@
1
1
  require 'premailer'
2
- require 'nokogiri'
3
2
 
4
3
  TOKEN = '@TOKEN'
4
+ ERB_TAG = /<%.+?%>/
5
5
  TOKENIZED_ERB_FILE_NAME = '/tmp/tokenized.erb'
6
6
 
7
7
  module Getinline
@@ -13,7 +13,7 @@ module Getinline
13
13
  end
14
14
 
15
15
  def transform
16
- matches = @raw_text.scan(/<%.+?%>/)
16
+ matches = @raw_text.scan(ERB_TAG)
17
17
  tokenized_text = @raw_text.dup
18
18
  matches.each do |match|
19
19
  tokenized_text.sub!(match, TOKEN)
@@ -23,7 +23,7 @@ module Getinline
23
23
 
24
24
  @premailer = Premailer.new(TOKENIZED_ERB_FILE_NAME, @premailer_options)
25
25
  premailed_tokenized_text = @options[:mode] == :txt ?
26
- @premailer.to_plain_text : Nokogiri::HTML(@premailer.to_inline_css).to_html(encoding:'US-ASCII')
26
+ @premailer.to_plain_text : @premailer.to_inline_css
27
27
  premailed_text = premailed_tokenized_text.dup
28
28
 
29
29
  matches.each do |match|
@@ -1,3 +1,3 @@
1
1
  module Getinline
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getinline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Kahn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-12-16 00:00:00.000000000 Z
12
+ date: 2016-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler