simplevpim 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/simplevpim.rb +185 -11
- metadata +43 -40
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23b8411e8323eb6df94ad8219a0789d71be6cb187fc0ac271c3cc3fe8bece742
|
4
|
+
data.tar.gz: 784fcd0808daa9bcef34deb53c4295235f82ea8777ae54548b3f59932330f3f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf3c0f93a8b533b12b6529736c6c31a336c12d52d41b3ed8ac288f03d55c05ff41b47ba7b5993506548b970fedfb067c8875d28e8049df7180811a6c9ac32e46
|
7
|
+
data.tar.gz: dc942fd4b16ed70e20f9f75faf121019d09c79f52cf5782b4bbf7c66143fe737a5e287431daaaf6c20012ae87f552653700763be604a4328310981cc8554c17e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/simplevpim.rb
CHANGED
@@ -2,32 +2,47 @@
|
|
2
2
|
|
3
3
|
# file: simplevpim.rb
|
4
4
|
|
5
|
+
require 'hlt'
|
5
6
|
require 'nokogiri'
|
6
7
|
require 'vpim/vcard'
|
7
8
|
require 'rexle-builder'
|
8
|
-
require '
|
9
|
+
require 'kvx'
|
10
|
+
require 'unichron'
|
9
11
|
|
10
12
|
|
11
13
|
class SimpleVpim
|
12
14
|
|
13
|
-
attr_reader :to_vcard, :to_xml
|
15
|
+
attr_reader :to_vcard, :to_vevent, :to_xml
|
14
16
|
|
15
17
|
def initialize(s)
|
16
18
|
|
17
|
-
|
19
|
+
kvx = Kvx.new(s)
|
20
|
+
@h = kvx.to_h
|
18
21
|
|
19
|
-
if h[:name] then
|
20
|
-
|
21
|
-
@
|
22
|
+
if s.lstrip =~ /# vcard/ and @h[:name] then
|
23
|
+
|
24
|
+
@to_vcard = make_vcard @h
|
25
|
+
@to_xml = vcard_xml @h
|
26
|
+
|
27
|
+
elsif @h[:title] or @h[:summary]
|
28
|
+
|
29
|
+
@to_vevent = make_vevent @h
|
30
|
+
@to_xml = vevent_xml kvx.to_xml
|
31
|
+
|
22
32
|
end
|
23
33
|
|
24
34
|
end
|
25
35
|
|
26
36
|
alias to_vcf to_vcard
|
27
37
|
|
38
|
+
def to_hcard(layout=nil)
|
39
|
+
make_hcard layout, @h
|
40
|
+
end
|
41
|
+
|
28
42
|
def to_xcard()
|
29
43
|
make_xcard @to_xml
|
30
44
|
end
|
45
|
+
|
31
46
|
|
32
47
|
private
|
33
48
|
|
@@ -151,15 +166,166 @@ class SimpleVpim
|
|
151
166
|
end
|
152
167
|
end
|
153
168
|
|
154
|
-
def
|
169
|
+
def make_vevent(h)
|
155
170
|
|
156
|
-
|
157
|
-
|
158
|
-
|
171
|
+
dstart, dend = %i(start end).map do |x|
|
172
|
+
Unichron.new(h[x]).to_date.strftime("%Y%m%d")
|
173
|
+
end
|
174
|
+
|
175
|
+
s = "BEGIN:VEVENT
|
176
|
+
SUMMARY:#{h[:title] || h[:summary]}
|
177
|
+
DTSTART;VALUE=DATE:#{dstart}
|
178
|
+
DTEND;VALUE=DATE:#{dend}
|
179
|
+
"
|
180
|
+
|
181
|
+
s += 'LOCATION:' + h[:location] + "\n" if h[:location]
|
182
|
+
s += 'DESCRIPTION:' + h[:description] + "\n" if h[:description]
|
183
|
+
s += 'END:VEVENT'
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
def make_hcard(raw_s, h)
|
188
|
+
|
189
|
+
raw_s ||= %q(
|
190
|
+
# hcard
|
191
|
+
|
192
|
+
img.photo
|
193
|
+
h1.fn
|
194
|
+
.email
|
195
|
+
.n
|
196
|
+
|
197
|
+
home:
|
198
|
+
.label
|
199
|
+
.adr
|
200
|
+
.tel
|
201
|
+
|
202
|
+
work:
|
203
|
+
.label
|
204
|
+
.adr
|
205
|
+
.tel
|
206
|
+
)
|
207
|
+
|
208
|
+
s = raw_s.split(/\n(?=\w+:?)/).inject('') do |r, x|
|
209
|
+
|
210
|
+
x.sub!(/^\s*#\s+.*/,'') # ignore comments
|
211
|
+
|
212
|
+
lines = x.lines
|
213
|
+
type = lines[0][/^(\w+):/,1]
|
214
|
+
|
215
|
+
if type then
|
216
|
+
|
217
|
+
lines.shift
|
218
|
+
|
219
|
+
r << lines.map do |line|
|
220
|
+
|
221
|
+
if line[/\s*\.\w+/] then
|
222
|
+
indent = line[/^ +/].to_s
|
223
|
+
"%s%sspan.type %s" % [line.sub(/^ {2}/,''), indent, type]
|
224
|
+
else
|
225
|
+
line
|
226
|
+
end
|
227
|
+
|
228
|
+
end.join("\n") + "\n"
|
229
|
+
|
230
|
+
else
|
231
|
+
|
232
|
+
r << x + "\n"
|
233
|
+
end
|
234
|
+
|
235
|
+
r
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
html_string = Hlt.new(s).to_html
|
240
|
+
html_template = <<EOF
|
241
|
+
<html>
|
242
|
+
<head>
|
243
|
+
<link rel="profile" href="http://microformats.org/profile/hcard" />
|
244
|
+
</head>
|
245
|
+
<body>
|
246
|
+
<div class='vcard'>#{html_string}</div>
|
247
|
+
</body>
|
248
|
+
</html>
|
249
|
+
EOF
|
250
|
+
doc = Rexle.new(html_template)
|
251
|
+
|
252
|
+
def doc.set(selector, val=nil)
|
253
|
+
|
254
|
+
e = self.at_css selector
|
255
|
+
return unless e
|
256
|
+
block_given? ? yield(e) : e.text = val
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
firstname, middlename, surname, fullname = extract_names(h[:name])
|
261
|
+
doc.set '.fn', fullname
|
262
|
+
|
263
|
+
#-- name ---------
|
264
|
+
|
265
|
+
e = doc.at_css '.n'
|
266
|
+
e.text = 'First Name:'
|
267
|
+
fname = Rexle::Element.new('span')
|
268
|
+
fname.attributes[:class] = 'given-name'
|
269
|
+
fname.text = firstname
|
270
|
+
e.add_element fname
|
271
|
+
e.add_element Rexle::Element.new('br')
|
272
|
+
e.add_text 'Last Name:'
|
273
|
+
lname = Rexle::Element.new('span')
|
274
|
+
lname.attributes[:class] = 'family-name'
|
275
|
+
lname.text = surname
|
276
|
+
e.add_element lname
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
doc.at_css('.photo').delete unless h[:photo]
|
281
|
+
doc.css('.tel').each(&:delete) unless h[:tel]
|
282
|
+
doc.css('.adr').each(&:delete) unless h[:adr]
|
283
|
+
doc.css('.label').each(&:delete) unless h[:label]
|
159
284
|
|
285
|
+
if h[:email].is_a? String then
|
286
|
+
|
287
|
+
e = doc.at_css '.email'
|
288
|
+
e.text = 'Email:'
|
289
|
+
alink = Rexle::Element.new('a')
|
290
|
+
alink.attributes[:class] = 'value'
|
291
|
+
alink.attributes[:href] = 'mailto:' + h[:email]
|
292
|
+
alink.text = h[:email]
|
293
|
+
e.add_element alink
|
294
|
+
|
295
|
+
elsif h[:email].is_a? Hash then
|
296
|
+
|
297
|
+
node = doc.at_css('.email')
|
298
|
+
|
299
|
+
h[:email].reverse_each do |k,v|
|
300
|
+
e = node.clone
|
301
|
+
type = Rexle::Element.new('span')
|
302
|
+
type.attributes[:class] = 'type'
|
303
|
+
type.text = k.capitalize
|
304
|
+
e.add_element type
|
305
|
+
e.add_text ' Email:'
|
306
|
+
alink = Rexle::Element.new('a')
|
307
|
+
alink.attributes[:class] = 'value'
|
308
|
+
alink.attributes[:href] = 'mailto:' + v
|
309
|
+
alink.text = v
|
310
|
+
e.add_element alink
|
311
|
+
|
312
|
+
node.insert_after e
|
313
|
+
end
|
314
|
+
node.delete
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
doc.xml pretty: true, declaration: false
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
def make_xcard(xml)
|
323
|
+
#lib = File.dirname(__FILE__)
|
324
|
+
lib = 'http://a0.jamesrobertson.me.uk/rorb/r/ruby/simplevpim'
|
325
|
+
xsl = open(lib + '/xcard.xsl','UserAgent' => 'SimplevPim').read
|
326
|
+
doc = Nokogiri::XML(xml)
|
160
327
|
xslt = Nokogiri::XSLT(xsl)
|
161
328
|
xslt.transform(doc).to_s
|
162
|
-
|
163
329
|
end
|
164
330
|
|
165
331
|
def vcard_xml(h)
|
@@ -258,5 +424,13 @@ class SimpleVpim
|
|
258
424
|
|
259
425
|
Rexle.new(a)
|
260
426
|
end
|
427
|
+
|
428
|
+
def vevent_xml(xml)
|
429
|
+
|
430
|
+
doc = Rexle.new(xml)
|
431
|
+
doc.root.name = 'vevent'
|
432
|
+
doc.root.xml
|
433
|
+
|
434
|
+
end
|
261
435
|
|
262
436
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplevpim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,49 +10,53 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNjIxMjI1NjEzWhcN
|
15
|
+
MjIwNjIxMjI1NjEzWjAsMSowKAYDVQQDDCFn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+
Zv0+gw5uwt3v2ac4xdwCRcte/8vZtd7malj2UL2YHjSG0Y9iVbMbIQoeMQFrUTLQ
|
31
|
+
SNdUvlE6jDatAHLajoOel0P4qV6i98pYRZVD+jH7mG1n5D2xyDnov8OoK7cAYPvB
|
32
|
+
hKS+vGsPMK6D70pa3cSiOF6kYE94pgFL2OdoxpEpaKQukTzZnfODDSUx/IPud4OP
|
33
|
+
nH2NGMAKFKRnV1ckoSFcvhYYzJGpYYGFlGGMrAPtzAW8NyHDOwwA/koYXY1oh9kB
|
34
|
+
iOeNjtxEJvb/5Qnz8M8K2CBXRfktT6ZghoJMc12q2bM3XE71RF3yJ/E250/Xp3+Z
|
35
|
+
dBpGyLXPFeCV5Z8rWY+S891OLL3UPvcmIiolU7aaNSwvXBGLesCCH6TrIdhw4q2z
|
36
|
+
pM4lNlA3G8w+xUHw/9AE8V6p
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
41
|
+
name: hlt
|
38
42
|
requirement: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
44
|
- - "~>"
|
41
45
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
46
|
+
version: '0.6'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
49
|
+
version: 0.6.3
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
49
53
|
requirements:
|
50
54
|
- - "~>"
|
51
55
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0.
|
56
|
+
version: '0.6'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
59
|
+
version: 0.6.3
|
56
60
|
- !ruby/object:Gem::Dependency
|
57
61
|
name: vpim
|
58
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,47 +78,47 @@ dependencies:
|
|
74
78
|
- !ruby/object:Gem::Version
|
75
79
|
version: 13.11.11
|
76
80
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
81
|
+
name: unichron
|
78
82
|
requirement: !ruby/object:Gem::Requirement
|
79
83
|
requirements:
|
80
84
|
- - "~>"
|
81
85
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
86
|
+
version: '0.3'
|
83
87
|
- - ">="
|
84
88
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
89
|
+
version: 0.3.7
|
86
90
|
type: :runtime
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
93
|
requirements:
|
90
94
|
- - "~>"
|
91
95
|
- !ruby/object:Gem::Version
|
92
|
-
version: '0.
|
96
|
+
version: '0.3'
|
93
97
|
- - ">="
|
94
98
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
99
|
+
version: 0.3.7
|
96
100
|
- !ruby/object:Gem::Dependency
|
97
|
-
name:
|
101
|
+
name: rexle-builder
|
98
102
|
requirement: !ruby/object:Gem::Requirement
|
99
103
|
requirements:
|
100
104
|
- - "~>"
|
101
105
|
- !ruby/object:Gem::Version
|
102
|
-
version: '1.
|
106
|
+
version: '1.0'
|
103
107
|
- - ">="
|
104
108
|
- !ruby/object:Gem::Version
|
105
|
-
version: 1.
|
109
|
+
version: 1.0.3
|
106
110
|
type: :runtime
|
107
111
|
prerelease: false
|
108
112
|
version_requirements: !ruby/object:Gem::Requirement
|
109
113
|
requirements:
|
110
114
|
- - "~>"
|
111
115
|
- !ruby/object:Gem::Version
|
112
|
-
version: '1.
|
116
|
+
version: '1.0'
|
113
117
|
- - ">="
|
114
118
|
- !ruby/object:Gem::Version
|
115
|
-
version: 1.
|
119
|
+
version: 1.0.3
|
116
120
|
description:
|
117
|
-
email:
|
121
|
+
email: digital.robertson@gmail.com
|
118
122
|
executables: []
|
119
123
|
extensions: []
|
120
124
|
extra_rdoc_files: []
|
@@ -139,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
143
|
- !ruby/object:Gem::Version
|
140
144
|
version: '0'
|
141
145
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.2.2
|
146
|
+
rubygems_version: 3.1.2
|
144
147
|
signing_key:
|
145
148
|
specification_version: 4
|
146
149
|
summary: A simple wrapper for the vPim gem
|
metadata.gz.sig
CHANGED
Binary file
|