premailer 1.23.0 → 1.24.0

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
  SHA256:
3
- metadata.gz: ea6e9ef14eeb9cdffd7e718f976d9e71e50fb1f154c947c9ee9b97399f1aceeb
4
- data.tar.gz: 02d8f609acce2abb421f607e1937e35e4d36f12c609386bef808378f56e9753c
3
+ metadata.gz: 893f0a35f19920e5a33bbaefc0c1cd2dd8a8fc2f56fc8f11bf7ed3bca2d4d437
4
+ data.tar.gz: 7d48ed502bc818064241ea372b4e0bdbffd204a845ff5e36a8da38af94a15202
5
5
  SHA512:
6
- metadata.gz: d1e580add5528f240e2170bb2aed29171227d35ce8acc31d5c8ceed7ea3f211072f8db8257f9665bef5838c606c9f77a56a792482c3d5f730025a6448374a4bb
7
- data.tar.gz: 3afd5c1330b5b1ddff158e77260c0fc87876779e839f5f1beb641ea4c00d424db97c0b5410a566f08ac97a3615cd125c8d9198a77d5edf3ee5959abcc2058440
6
+ metadata.gz: d2098aec27cdabce93e5dd144be10e6b090105970f415fd32e3e5d6a9b7f65decf7d1968563e0ecb7ea88a2d74895ad526dc0fd1f72a6d7e2a9029548884157f
7
+ data.tar.gz: f70007e030983216f7598f387c909cdb0de5c9192f9fe69049ef7da1f307357b9ae79dc2a533b0d2bd5bdbae60de9d1935162ab47b76d8af0c14fa788108e11f
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  For the best HTML e-mail delivery results, CSS should be inline. This is a
6
6
  huge pain and a simple newsletter becomes un-managable very quickly. This
7
- script is my solution.
7
+ gem is a solution.
8
8
 
9
9
  * CSS styles are converted to inline style attributes
10
10
  - Checks `style` and `link[rel=stylesheet]` tags and preserves existing inline attributes
@@ -12,35 +12,26 @@ script is my solution.
12
12
  - Checks links in `href`, `src` and CSS `url('')`
13
13
  * CSS properties are checked against e-mail client capabilities
14
14
  - Based on the Email Standards Project's guides
15
- * A [plain text version](https://premailer.github.io/premailer/HtmlToPlainText.html) is created (optional)
15
+ * A [plain text version](#plain-text-version) is created (optional)
16
16
 
17
17
  ## Installation
18
18
 
19
- Install the Premailer gem from RubyGems.
20
-
21
19
  ```bash
22
20
  gem install premailer
23
21
  ```
24
22
 
25
- or add it to your `Gemfile` and run `bundle`.
26
-
27
23
  ## Example
28
24
 
29
25
  ```ruby
30
26
  require 'premailer'
31
27
 
32
- premailer = Premailer.new('http://example.com/myfile.html', :warn_level => Premailer::Warnings::SAFE)
28
+ premailer = Premailer.new('http://example.com/myfile.html', warn_level: Premailer::Warnings::SAFE)
33
29
 
34
- # Write the plain-text output
35
- # This must come before to_inline_css (https://github.com/premailer/premailer/issues/201)
36
- File.open("output.txt", "w") do |fout|
37
- fout.puts premailer.to_plain_text
38
- end
30
+ # Write the plain-text output (must come before to_inline_css)
31
+ File.write "output.txt", premailer.to_plain_text
39
32
 
40
33
  # Write the HTML output
41
- File.open("output.html", "w") do |fout|
42
- fout.puts premailer.to_inline_css
43
- end
34
+ File.write "output.html", premailer.to_inline_css
44
35
 
45
36
  # Output any CSS warnings
46
37
  premailer.warnings.each do |w|
@@ -50,17 +41,13 @@ end
50
41
 
51
42
  ## Adapters
52
43
 
53
- Premailer's default adapter is nokogiri if both nokogiri and nokogumbo are included in the Gemfile list. However, if you want to use a different adapter, you can choose to.
54
-
55
- There are three adapters in total (as of premailer 1.10.0)
56
-
57
44
  1. nokogiri (default)
58
- 2. nokogiri_fast
45
+ 2. nokogiri_fast (20x speed, more memory)
59
46
  3. nokogumbo
60
47
 
61
- hpricot adapter removed due to its EOL, please use `~>1.9.0` version if You still need it..
48
+ (hpricot adapter removed, use `~>1.9.0` version if you need it)
62
49
 
63
- `NokogiriFast` adapter improves the Algorithmic complexity of the running time by 20x with a slight compensation on memory. To switch to any of these adapters, add the following line. For example, if you want to include the `NokogiriFast` adapter,
50
+ Picking an adapter:
64
51
 
65
52
  ```ruby
66
53
  Premailer::Adapter.use = :nokogiri_fast
@@ -97,22 +84,56 @@ will result in
97
84
  <table cellspacing='5' width='500'>
98
85
  ```
99
86
 
100
- ## Configuration options
87
+ ## Plain text version
88
+
89
+ Premailer can generate a plain text version of your HTML. Links and images will be inlined.
101
90
 
102
- The behavior of Premailer can be configured by passing options in the initializer.
91
+ For example
103
92
 
104
- For example, the following will accept HTML from a string and will exclude unmergeable css from being added to the `<head>` of the output document.
93
+ ```html
94
+ <a href="https://example.com" >
95
+ <img src="https://github.com/premailer.png" alt="Premailer Logo" />
96
+ </a>
97
+ ```
105
98
 
99
+ will become
100
+
101
+ ```text
102
+ Premailer Logo ( https://example.com )
103
+ ```
104
+
105
+ To ignore/omit a section of HTML content from the plain text version, wrap it with the following comments.
106
+
107
+ ```html
108
+ <!-- start text/html -->
109
+ <p>This will be omitted from the plain text version.</p>
110
+ <p>
111
+ This is extremely helpful for <strong>removing email headers and footers</strong>
112
+ that aren't needed in the text version.
113
+ </p>
114
+ <!-- end text/html -->
115
+ ```
116
+
117
+ ## Configuration options
118
+
119
+ For example:
106
120
  ```ruby
107
- premailer = Premailer.new(html_string, with_html_string: true, drop_unmergeable_css_rules: true)
121
+ Premailer.new(
122
+ html, # html as string
123
+ with_html_string: true,
124
+ drop_unmergeable_css_rules: true
125
+ )
108
126
  ```
109
127
 
110
- [See here for a full list of the available options](https://premailer.github.io/premailer/Premailer.html#initialize-instance_method).
128
+ [available options](https://premailer.github.io/premailer/Premailer.html#initialize-instance_method)
111
129
 
112
130
 
113
131
  ## Contributions
114
132
 
115
- Contributions are most welcome. Premailer was rotting away in a private SVN repository for too long and could use some TLC. Fork and patch to your heart's content. Please don't increment the version numbers, though.
133
+ Contributions are most welcome.
134
+ Premailer was rotting away in a private SVN repository for too long and could use some TLC.
135
+ Fork and patch to your heart's content.
136
+ Please don't increment the version numbers.
116
137
 
117
138
  A few areas that are particularly in need of love:
118
139
 
@@ -129,4 +150,3 @@ and to [Campaign Monitor](https://www.campaignmonitor.com/) for supporting the w
129
150
  The source code can be found on [GitHub](https://github.com/premailer/premailer).
130
151
 
131
152
  Copyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2017. See [LICENSE.md](https://github.com/premailer/premailer/blob/master/LICENSE.md) for license details.
132
-
@@ -235,6 +235,7 @@ class Premailer
235
235
 
236
236
  # Handle HTML entities
237
237
  if @options[:replace_html_entities] == true and thing.is_a?(String)
238
+ thing = +thing
238
239
  HTML_ENTITIES.map do |entity, replacement|
239
240
  thing.gsub! entity, replacement
240
241
  end
@@ -14,7 +14,7 @@ module HtmlToPlainText
14
14
  # TODO: add support for DL, OL
15
15
  # TODO: this is not safe and needs a real html parser to work
16
16
  def convert_to_text(html, line_length = 65, from_charset = 'UTF-8')
17
- txt = html
17
+ txt = +html
18
18
 
19
19
  # strip text ignored html. Useful for removing
20
20
  # headers and footers that aren't needed in the
@@ -15,7 +15,7 @@
15
15
  # fout.close
16
16
  #
17
17
  # # Write the plain-text output
18
- # fout = File.open("ouput.txt", "w")
18
+ # fout = File.open("output.txt", "w")
19
19
  # fout.puts premailer.to_plain_text
20
20
  # fout.close
21
21
  #
@@ -264,7 +264,7 @@ class Premailer
264
264
 
265
265
  protected
266
266
  def load_css_from_local_file!(path)
267
- css_block = ''
267
+ css_block = +''
268
268
  path.gsub!(/\Afile:/, '')
269
269
  begin
270
270
  File.open(path, "r") do |file|
@@ -358,6 +358,7 @@ public
358
358
  def append_query_string(doc, qs)
359
359
  return doc if qs.nil?
360
360
 
361
+ qs = +qs
361
362
  qs.to_s.gsub!(/^[\?]*/, '').strip!
362
363
  return doc if qs.empty?
363
364
 
@@ -473,6 +474,7 @@ public
473
474
 
474
475
  # @private
475
476
  def self.resolve_link(path, base_path) # :nodoc:
477
+ path = +path
476
478
  path.strip!
477
479
  resolved = nil
478
480
  if path =~ /\A(?:(https?|ftp|file):)\/\//i
@@ -1,4 +1,4 @@
1
1
  class Premailer
2
2
  # Premailer version.
3
- VERSION = '1.23.0'.freeze
3
+ VERSION = '1.24.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.23.0
4
+ version: 1.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-05 00:00:00.000000000 Z
11
+ date: 2024-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser