ghostwriter 0.4.1 → 0.4.2
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/README.md +98 -7
- data/RELEASE_NOTES.md +14 -0
- data/lib/ghostwriter/version.rb +1 -1
- data/lib/ghostwriter/writer.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d48bada0259aa38eb1cf98bfbf101970dce0f979ffb7293a8c23b5d5ca393d7d
|
4
|
+
data.tar.gz: d1f4ac853988b75497b4c1ff7c4a16ba8cddd47be93e0112001fd5960a61a565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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">
|
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
|
-
|
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="
|
152
|
+
html = 'My email and a <a href="https://tenjin.ca">link</a>'
|
62
153
|
|
63
|
-
|
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
data/lib/ghostwriter/version.rb
CHANGED
data/lib/ghostwriter/writer.rb
CHANGED
@@ -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
|
-
|
47
|
-
|
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.
|
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-
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|