ghostwriter 0.4.1 → 0.4.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
  SHA256:
3
- metadata.gz: 7851b6a60c2dc482938d9ea35844c9508384e508c6f20dc1bf73fcdeb91d4d15
4
- data.tar.gz: e35c2c30d5a523b07e05c73764c24b9e60eb361f72b48ece4f10bb254f856d67
3
+ metadata.gz: d48bada0259aa38eb1cf98bfbf101970dce0f979ffb7293a8c23b5d5ca393d7d
4
+ data.tar.gz: d1f4ac853988b75497b4c1ff7c4a16ba8cddd47be93e0112001fd5960a61a565
5
5
  SHA512:
6
- metadata.gz: fd0dc41dfb3f473eaa47ec5b6f148cf1984c358970382e508255342b320e67c83953c45e01a07a2dd4cf0feb286375608243f7c8550843b07f96a583c1fc415d
7
- data.tar.gz: 01d7a3b8728f17a131d3dd5aab5d20799b271a9c84fcc04ee2cb29bf38506a856043bfce32ff69db68f6ccd5a727cab685b259c03d26e4fd5e68e9d6c45c5dd7
6
+ metadata.gz: 5d85b5f1e5ef90c91fd03288012805c195c0a9c6ea8a3d7efb10b03b55443e060252f3f1e82f18f2854234174aa9daa80cc35a7b15f774798af5593a84b55881
7
+ data.tar.gz: afaf20dbb5876e667fc33d3ff35eff58d1cb076e5bec941863a4b54689ac99bbdf2716cd52145bc7e5cd99f64c0d5954023cf160e01240c24c6a16036fca2eee
data/README.md CHANGED
@@ -31,23 +31,114 @@ Or install it manually with:
31
31
  Create a `Ghostwriter::Writer` with the html you want modified, and call `#textify`:
32
32
 
33
33
  ```ruby
34
- html = '<html><body>This is some markup <a href="tenjin.ca">and a link</a><p>Other tags translate, too</p></body></html>'
34
+ html = '<html><body><p>This is some markup <a href="tenjin.ca">and a link</a></p><p>Other tags translate, too</p></body></html>'
35
35
 
36
36
  Ghostwriter::Writer.new(html).textify
37
+ ```
38
+ Produces:
39
+ ```
40
+ This is some markup and a link (tenjin.ca)
41
+
42
+ Other tags translate, too
43
+ ```
37
44
 
38
- => "This is some markup and a link (tenjin.ca)\nOther tags translate, too\n\n"
45
+ ### Links
46
+
47
+ Links are converted to the link text followed by the link target in brackets:
48
+
49
+ ```ruby
50
+ html = '<html><body>Visit our <a href="https://example.com">Website</a><body></html>'
51
+ Ghostwriter::Writer.new(html).textify
52
+ ```
39
53
 
54
+ Produces:
40
55
  ```
56
+ Visit our Website (https://example.com)
57
+ ```
58
+
59
+ #### Relative Links
60
+ Since emails are wholly distinct from your web address, relative links might break.
61
+
62
+ To avoid this problem, either use the `<base>` header tag:
63
+
64
+ ```ruby
65
+ html = <<~HTML
66
+ <html>
67
+ <head>
68
+ <base href="https://www.example.com/">
69
+ </head>
70
+ <body>
71
+ Relative links get <a href="/contact">expanded</a> using the head's base tag.
72
+ </body>
73
+ </html>
74
+ HTML
41
75
 
42
- `#textify` will use the `<base>` tag if found in the HTML source, or if one is provided explicitly:
76
+ Ghostwriter::Writer.new(html).textify
77
+ ```
78
+ Produces:
79
+ ```
80
+ Relative links get expanded (https://www.example.com//contact) using the head's base tag.
81
+ ```
43
82
 
83
+ Or you can use the `link_base` parameter:
44
84
  ```ruby
45
- html = '<html><body>Relative links <a href="/contact">Link</a></body></html>'
85
+ html = '<html><body>Relative links get <a href="/contact">expanded</a></body></html> using the link_base parmeter, too.'
46
86
 
47
87
  Ghostwriter::Writer.new(html).textify(link_base: 'tenjin.ca')
88
+ ```
89
+
90
+ Produces:
91
+ ```
92
+ "Relative links get expanded (tenjin.ca/contact) using the link_base parmeter, too."
93
+ ```
94
+
95
+ ### Tables
96
+ Tables are often used email structuring because support for more modern CSS is inconsistent.
48
97
 
49
- => "Relative links Link (tenjin.ca/contact)"
98
+ Ghostwriter tries to maintain table structure, but this will quickly devolve for complex structures.
99
+
100
+ ```ruby
101
+ html = <<~HTML
102
+ <html>
103
+ <head>
104
+ <base href="https://www.example.com/">
105
+ </head>
106
+ <body>
107
+ <table>
108
+ <thead>
109
+ <tr>
110
+ <th>Ship</th>
111
+ <th>Captain</th>
112
+ </tr>
113
+ </thead>
114
+ <tbody>
115
+ <tr>
116
+ <td>Enterprise</td>
117
+ <td>Jean-Luc Picard</td>
118
+ </tr>
119
+ <tr>
120
+ <td>TARDIS</td>
121
+ <td>The Doctor</td>
122
+ </tr>
123
+ <tr>
124
+ <td>Planet Express Ship</td>
125
+ <td>Turanga Leela</td>
126
+ </tr>
127
+ </tbody>
128
+ </table>
129
+ </body>
130
+ </html>
131
+ HTML
50
132
 
133
+ Ghostwriter::Writer.new(html).textify
134
+ ```
135
+ Produces:
136
+ ```
137
+ | Ship | Captain |
138
+ |---------------------|-----------------|
139
+ | Enterprise | Jean-Luc Picard |
140
+ | TARDIS | The Doctor |
141
+ | Planet Express Ship | Turanga Leela |
51
142
  ```
52
143
 
53
144
  ### Mail Gem Example
@@ -58,9 +149,9 @@ through Ghostwriter:
58
149
  ```ruby
59
150
  require 'mail'
60
151
 
61
- html = 'My email and a <a href="http://tenjin.ca">link</a>'
152
+ html = 'My email and a <a href="https://tenjin.ca">link</a>'
62
153
 
63
- mail = Mail.deliver do
154
+ Mail.deliver do
64
155
  to 'bob@example.com'
65
156
  from 'dot@example.com'
66
157
  subject 'Using Ghostwriter with Mail'
data/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Release Notes
2
2
 
3
+ ## 0.4.2 (2021-03-17)
4
+
5
+ ### Major
6
+
7
+ * none
8
+
9
+ ### Minor
10
+
11
+ * none
12
+
13
+ ### Bugfixes
14
+
15
+ * Works with links using `tel:` and `mailto:` schemas.
16
+
3
17
  ## 0.4.1 (2021-03-17)
4
18
 
5
19
  ### Major
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ghostwriter
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -43,8 +43,12 @@ module Ghostwriter
43
43
  base = get_link_base(doc, default: link_base)
44
44
 
45
45
  doc.search('a').each do |link_node|
46
- href = URI(link_node['href'])
47
- href = base + href.to_s unless href.absolute?
46
+ begin
47
+ href = URI(link_node['href'])
48
+ href = base + href.to_s unless href.absolute?
49
+ rescue URI::InvalidURIError
50
+ href = link_node['href'].gsub(/^(tel|mailto):/, '').strip
51
+ end
48
52
 
49
53
  link_node.inner_html = if link_matches(href, link_node.inner_html)
50
54
  href.to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghostwriter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Miller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-17 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri