simplevpim 0.4.2 → 0.5.0
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/simplevpim.rb +40 -5
- metadata +37 -76
- metadata.gz.sig +0 -0
- data/lib/simplevpim.rb~ +0 -401
- data/lib/xdata.xsl +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 837294bf422fd83d5713759e1983df1d04b6843557790a89f041c1aea5e81469
|
4
|
+
data.tar.gz: ce99d263776326cdac99f6831b1c8ce4bcc7f54d25d828175c215bfd9ba263ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b412cde4385b238ad9073e93d8be7346f2bd600b9d44d90297250f34ba670209fefbb97915dc8b7dfa55114a0c47e95213f0355494c11eb82409994be6191900
|
7
|
+
data.tar.gz: 97ef6fedf467824363b642147202d6cacaea03700d0492bd15969483ebf690891480da634cf8eea859676d9d6252bb7d9d8b2456bd4aa9ea4c6d800c7103ea97
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/simplevpim.rb
CHANGED
@@ -7,19 +7,28 @@ require 'nokogiri'
|
|
7
7
|
require 'vpim/vcard'
|
8
8
|
require 'rexle-builder'
|
9
9
|
require 'kvx'
|
10
|
+
require 'unichron'
|
10
11
|
|
11
12
|
|
12
13
|
class SimpleVpim
|
13
14
|
|
14
|
-
attr_reader :to_vcard, :to_xml
|
15
|
+
attr_reader :to_vcard, :to_vevent, :to_xml
|
15
16
|
|
16
17
|
def initialize(s)
|
17
18
|
|
18
|
-
|
19
|
+
kvx = Kvx.new(s)
|
20
|
+
@h = kvx.to_h
|
19
21
|
|
20
|
-
if @h[:name] then
|
22
|
+
if s.lstrip =~ /# vcard/ and @h[:name] then
|
23
|
+
|
21
24
|
@to_vcard = make_vcard @h
|
22
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
|
+
|
23
32
|
end
|
24
33
|
|
25
34
|
end
|
@@ -156,6 +165,24 @@ class SimpleVpim
|
|
156
165
|
|
157
166
|
end
|
158
167
|
end
|
168
|
+
|
169
|
+
def make_vevent(h)
|
170
|
+
|
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
|
159
186
|
|
160
187
|
def make_hcard(raw_s, h)
|
161
188
|
|
@@ -294,7 +321,7 @@ EOF
|
|
294
321
|
|
295
322
|
def make_xcard(xml)
|
296
323
|
#lib = File.dirname(__FILE__)
|
297
|
-
lib = 'http://
|
324
|
+
lib = 'http://a0.jamesrobertson.me.uk/rorb/r/ruby/simplevpim'
|
298
325
|
xsl = open(lib + '/xcard.xsl','UserAgent' => 'SimplevPim').read
|
299
326
|
doc = Nokogiri::XML(xml)
|
300
327
|
xslt = Nokogiri::XSLT(xsl)
|
@@ -397,5 +424,13 @@ EOF
|
|
397
424
|
|
398
425
|
Rexle.new(a)
|
399
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
|
400
435
|
|
401
|
-
end
|
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.0
|
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
|
+
MjIwNjIxMjI1NjEzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC2HXPE
|
17
|
+
oxEBJSUeAX4qfaY1qkifPWhiR5H3rPYQwCFzPwsnUV98vv7RWWwJ/W7kkw1fuRTW
|
18
|
+
gk+6G23OtSToucs9J+V6BSaNa+I2OXldvDd/nyL32BnwbzaOgAxlYcAXSnnXtrFR
|
19
|
+
q7GBlpUtYnqBDR4PYtPfynRETWD8aFtTFba38Xbcwi7bph/7f6NA/YGw5o5pjuEa
|
20
|
+
2tSoHKgyZV0XP5urGHpMU7J2Snt3sBrr+ZlETDHUtkpOUfzbsXEFwsi0Xhtvv9Et
|
21
|
+
ksoJk541l1IA63M/rAtXGYoN7cJUel4o1Yc6NSZ3YbBTksoTVdKBZb3D76i9wKzj
|
22
|
+
lBAvbt9H7slYmShcSKG1bSQ+OHHr621FEBKyjP9r0BnVF0fFIGG++LFSH1wxO8mI
|
23
|
+
UxnzaESfyoc2YcnPkzOPs9XgSZfDV08m8Zg7CM7n/BbL35Se8DpoOIE1uzWV9r3Q
|
24
|
+
bqT6PEpiB+lhAvf+NpNTeXpzahoVG+8NA7v8vOrHezuDEzTsTL1fJ2jrW78CAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUm2477cZF
|
26
|
+
MIo69AMIHSjJV5Li5fMwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
|
+
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAXAjV1qgT+80h3KNCJfbCT1AlAL+Fd6UBS/9BBGWB
|
29
|
+
okJjZnG12AWn3hTkrtbcfPpL6HnC3jDa7bVmsh79nEXbCzAAtAG5wckmOyFQvVTr
|
30
|
+
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
|
@@ -79,69 +83,27 @@ dependencies:
|
|
79
83
|
requirements:
|
80
84
|
- - "~>"
|
81
85
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
83
|
-
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 0.2.1
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- - "~>"
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '0.2'
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 0.2.1
|
96
|
-
- !ruby/object:Gem::Dependency
|
97
|
-
name: nokogiri
|
98
|
-
requirement: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '1.6'
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: 1.6.2.1
|
106
|
-
type: :runtime
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - "~>"
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '1.6'
|
113
|
-
- - ">="
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version: 1.6.2.1
|
116
|
-
- !ruby/object:Gem::Dependency
|
117
|
-
name: hlt
|
118
|
-
requirement: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - "~>"
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: '0.4'
|
86
|
+
version: '1.0'
|
123
87
|
- - ">="
|
124
88
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.
|
89
|
+
version: 1.0.3
|
126
90
|
type: :runtime
|
127
91
|
prerelease: false
|
128
92
|
version_requirements: !ruby/object:Gem::Requirement
|
129
93
|
requirements:
|
130
94
|
- - "~>"
|
131
95
|
- !ruby/object:Gem::Version
|
132
|
-
version: '0
|
96
|
+
version: '1.0'
|
133
97
|
- - ">="
|
134
98
|
- !ruby/object:Gem::Version
|
135
|
-
version: 0.
|
99
|
+
version: 1.0.3
|
136
100
|
description:
|
137
|
-
email:
|
101
|
+
email: digital.robertson@gmail.com
|
138
102
|
executables: []
|
139
103
|
extensions: []
|
140
104
|
extra_rdoc_files: []
|
141
105
|
files:
|
142
106
|
- lib/simplevpim.rb
|
143
|
-
- lib/simplevpim.rb~
|
144
|
-
- lib/xdata.xsl
|
145
107
|
homepage: https://github.com/jrobertson/simplevpim
|
146
108
|
licenses:
|
147
109
|
- MIT
|
@@ -161,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
123
|
- !ruby/object:Gem::Version
|
162
124
|
version: '0'
|
163
125
|
requirements: []
|
164
|
-
|
165
|
-
rubygems_version: 2.4.6
|
126
|
+
rubygems_version: 3.1.2
|
166
127
|
signing_key:
|
167
128
|
specification_version: 4
|
168
129
|
summary: A simple wrapper for the vPim gem
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/simplevpim.rb~
DELETED
@@ -1,401 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# file: simplevpim.rb
|
4
|
-
|
5
|
-
require 'hlt'
|
6
|
-
require 'nokogiri'
|
7
|
-
require 'vpim/vcard'
|
8
|
-
require 'rexle-builder'
|
9
|
-
require 'simple-config'
|
10
|
-
|
11
|
-
|
12
|
-
class SimpleVpim
|
13
|
-
|
14
|
-
attr_reader :to_vcard, :to_xml
|
15
|
-
|
16
|
-
def initialize(s)
|
17
|
-
|
18
|
-
@h = Kvx.new(s).to_h
|
19
|
-
|
20
|
-
if @h[:name] then
|
21
|
-
@to_vcard = make_vcard @h
|
22
|
-
@to_xml = vcard_xml @h
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
alias to_vcf to_vcard
|
28
|
-
|
29
|
-
def to_hcard(layout=nil)
|
30
|
-
make_hcard layout, @h
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_xcard()
|
34
|
-
make_xcard @to_xml
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def extract_names(name)
|
41
|
-
|
42
|
-
a = name.split
|
43
|
-
|
44
|
-
if a.length == 2 then
|
45
|
-
|
46
|
-
firstname, surname = a[0],nil,a[-1], name
|
47
|
-
|
48
|
-
elsif a[0][/^Mrs?|Ms|Miss|Dr/] then
|
49
|
-
|
50
|
-
prefix = a.shift
|
51
|
-
|
52
|
-
if a.length == 2 then
|
53
|
-
firstname, surname = a[0],nil,a[-1], name
|
54
|
-
else
|
55
|
-
[*a, a.join(' ')]
|
56
|
-
end
|
57
|
-
|
58
|
-
else
|
59
|
-
[*a, a.join(' ')]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def make_vcard(h)
|
64
|
-
|
65
|
-
card = Vpim::Vcard::Maker.make2 do |maker|
|
66
|
-
|
67
|
-
def maker.add(field_name, value, params={})
|
68
|
-
|
69
|
-
field = Vpim::DirectoryInfo::Field.create field_name, value, params
|
70
|
-
add_field field
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
prefix = h[:prefix]
|
75
|
-
suffix = h[:suffix]
|
76
|
-
|
77
|
-
firstname, middlename, surname, fullname = extract_names(h[:name])
|
78
|
-
|
79
|
-
maker.add_name do |name|
|
80
|
-
name.prefix = prefix if prefix
|
81
|
-
name.given = firstname
|
82
|
-
name.family = surname
|
83
|
-
name.suffix = suffix if suffix
|
84
|
-
name.fullname = fullname if fullname
|
85
|
-
end
|
86
|
-
|
87
|
-
# -- email -----------------------------
|
88
|
-
|
89
|
-
e = h[:email]
|
90
|
-
|
91
|
-
if e then
|
92
|
-
|
93
|
-
if e.is_a? String then
|
94
|
-
maker.add_email e
|
95
|
-
else
|
96
|
-
eh = h[:email][:home]
|
97
|
-
ew = h[:email][:work]
|
98
|
-
maker.add_email(ew) { |e| e.location = 'work' } if ew
|
99
|
-
maker.add_email(eh) { |e| e.location = 'home' } if eh
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# -- urls ---------------------------------
|
104
|
-
|
105
|
-
h[:url] ||= h[:urls]
|
106
|
-
|
107
|
-
if h[:url] then
|
108
|
-
|
109
|
-
if h[:url].is_a? String then
|
110
|
-
maker.add_url h[:url]
|
111
|
-
else
|
112
|
-
|
113
|
-
# unfortunately vPim doesn't use a block with the add_url method
|
114
|
-
#maker.add_url (h[:url][:work]){|e| e.location = 'work'} if h[:url][:work]
|
115
|
-
|
116
|
-
h[:url][:items].each {|url| maker.add_url url }
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
# -- photos
|
123
|
-
|
124
|
-
maker.add_photo {|photo| photo.link = h[:photo] } if h[:photo]
|
125
|
-
|
126
|
-
# -- telephone
|
127
|
-
|
128
|
-
tel = h[:tel]
|
129
|
-
|
130
|
-
if tel then
|
131
|
-
|
132
|
-
if tel.is_a? String then
|
133
|
-
|
134
|
-
maker.add_tel tel
|
135
|
-
|
136
|
-
else
|
137
|
-
th = h[:tel][:home]
|
138
|
-
tw = h[:tel][:work]
|
139
|
-
maker.add_tel(tw) { |e| e.location = 'work' } if tw
|
140
|
-
maker.add_tel(th) { |e| e.location = 'home' } if th
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# -- categories ------------
|
145
|
-
maker.add 'CATEGORIES', h[:categories].split(/\s*,\s*/) if h[:categories]
|
146
|
-
|
147
|
-
# -- source ------------
|
148
|
-
maker.add 'SOURCE', h[:source] if h[:source]
|
149
|
-
|
150
|
-
# -- Twitter ------------
|
151
|
-
maker.add 'X-TWITTER', h[:twitter] if h[:twitter]
|
152
|
-
|
153
|
-
# -- XMPP
|
154
|
-
xmpp = h[:jabber] || h[:xmpp]
|
155
|
-
maker.add 'X-JABBER', xmpp, 'TYPE' => 'im' if xmpp
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def make_hcard(raw_s, h)
|
161
|
-
|
162
|
-
raw_s ||= %q(
|
163
|
-
# hcard
|
164
|
-
|
165
|
-
img.photo
|
166
|
-
h1.fn
|
167
|
-
.email
|
168
|
-
.n
|
169
|
-
|
170
|
-
home:
|
171
|
-
.label
|
172
|
-
.adr
|
173
|
-
.tel
|
174
|
-
|
175
|
-
work:
|
176
|
-
.label
|
177
|
-
.adr
|
178
|
-
.tel
|
179
|
-
)
|
180
|
-
|
181
|
-
s = raw_s.split(/\n(?=\w+:?)/).inject('') do |r, x|
|
182
|
-
|
183
|
-
x.sub!(/^\s*#\s+.*/,'') # ignore comments
|
184
|
-
|
185
|
-
lines = x.lines
|
186
|
-
type = lines[0][/^(\w+):/,1]
|
187
|
-
|
188
|
-
if type then
|
189
|
-
|
190
|
-
lines.shift
|
191
|
-
|
192
|
-
r << lines.map do |line|
|
193
|
-
|
194
|
-
if line[/\s*\.\w+/] then
|
195
|
-
indent = line[/^ +/].to_s
|
196
|
-
"%s%sspan.type %s" % [line.sub(/^ {2}/,''), indent, type]
|
197
|
-
else
|
198
|
-
line
|
199
|
-
end
|
200
|
-
|
201
|
-
end.join("\n") + "\n"
|
202
|
-
|
203
|
-
else
|
204
|
-
|
205
|
-
r << x + "\n"
|
206
|
-
end
|
207
|
-
|
208
|
-
r
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
html_string = Hlt.new(s).to_html
|
213
|
-
html_template = <<EOF
|
214
|
-
<html>
|
215
|
-
<head>
|
216
|
-
<link rel="profile" href="http://microformats.org/profile/hcard" />
|
217
|
-
</head>
|
218
|
-
<body>
|
219
|
-
<div class='vcard'>#{html_string}</div>
|
220
|
-
</body>
|
221
|
-
</html>
|
222
|
-
EOF
|
223
|
-
doc = Rexle.new(html_template)
|
224
|
-
|
225
|
-
def doc.set(selector, val=nil)
|
226
|
-
|
227
|
-
e = self.at_css selector
|
228
|
-
return unless e
|
229
|
-
block_given? ? yield(e) : e.text = val
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
firstname, middlename, surname, fullname = extract_names(h[:name])
|
234
|
-
doc.set '.fn', fullname
|
235
|
-
|
236
|
-
#-- name ---------
|
237
|
-
|
238
|
-
e = doc.at_css '.n'
|
239
|
-
e.text = 'First Name:'
|
240
|
-
fname = Rexle::Element.new('span')
|
241
|
-
fname.attributes[:class] = 'given-name'
|
242
|
-
fname.text = firstname
|
243
|
-
e.add_element fname
|
244
|
-
e.add_element Rexle::Element.new('br')
|
245
|
-
e.add_text 'Last Name:'
|
246
|
-
lname = Rexle::Element.new('span')
|
247
|
-
lname.attributes[:class] = 'family-name'
|
248
|
-
lname.text = surname
|
249
|
-
e.add_element lname
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
doc.at_css('.photo').delete unless h[:photo]
|
254
|
-
doc.css('.tel').each(&:delete) unless h[:tel]
|
255
|
-
doc.css('.adr').each(&:delete) unless h[:adr]
|
256
|
-
doc.css('.label').each(&:delete) unless h[:label]
|
257
|
-
|
258
|
-
if h[:email].is_a? String then
|
259
|
-
|
260
|
-
e = doc.at_css '.email'
|
261
|
-
e.text = 'Email:'
|
262
|
-
alink = Rexle::Element.new('a')
|
263
|
-
alink.attributes[:class] = 'value'
|
264
|
-
alink.attributes[:href] = 'mailto:' + h[:email]
|
265
|
-
alink.text = h[:email]
|
266
|
-
e.add_element alink
|
267
|
-
|
268
|
-
elsif h[:email].is_a? Hash then
|
269
|
-
|
270
|
-
node = doc.at_css('.email')
|
271
|
-
|
272
|
-
h[:email].reverse_each do |k,v|
|
273
|
-
e = node.clone
|
274
|
-
type = Rexle::Element.new('span')
|
275
|
-
type.attributes[:class] = 'type'
|
276
|
-
type.text = k.capitalize
|
277
|
-
e.add_element type
|
278
|
-
e.add_text ' Email:'
|
279
|
-
alink = Rexle::Element.new('a')
|
280
|
-
alink.attributes[:class] = 'value'
|
281
|
-
alink.attributes[:href] = 'mailto:' + v
|
282
|
-
alink.text = v
|
283
|
-
e.add_element alink
|
284
|
-
|
285
|
-
node.insert_after e
|
286
|
-
end
|
287
|
-
node.delete
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
doc.xml pretty: true, declaration: false
|
292
|
-
|
293
|
-
end
|
294
|
-
|
295
|
-
def make_xcard(xml)
|
296
|
-
#lib = File.dirname(__FILE__)
|
297
|
-
lib = 'http://rorbuilder.info/r/ruby/simplevpim'
|
298
|
-
xsl = open(lib + '/xcard.xsl','UserAgent' => 'SimplevPim').read
|
299
|
-
doc = Nokogiri::XML(xml)
|
300
|
-
xslt = Nokogiri::XSLT(xsl)
|
301
|
-
xslt.transform(doc).to_s
|
302
|
-
end
|
303
|
-
|
304
|
-
def vcard_xml(h)
|
305
|
-
|
306
|
-
prefix = h[:prefix]
|
307
|
-
suffix = h[:suffix]
|
308
|
-
|
309
|
-
firstname, middlename, surname, fullname = extract_names(h[:name])
|
310
|
-
|
311
|
-
xml = RexleBuilder.new
|
312
|
-
|
313
|
-
a = xml.vcard do
|
314
|
-
|
315
|
-
xml.name do
|
316
|
-
|
317
|
-
xml.prefix prefix if prefix
|
318
|
-
xml.given firstname
|
319
|
-
xml.family surname
|
320
|
-
xml.suffix suffix if suffix
|
321
|
-
xml.fullname fullname if fullname
|
322
|
-
end
|
323
|
-
|
324
|
-
# -- email -----------------------------
|
325
|
-
|
326
|
-
e = h[:email]
|
327
|
-
|
328
|
-
if e then
|
329
|
-
|
330
|
-
if e.is_a? String then
|
331
|
-
|
332
|
-
xml.email e
|
333
|
-
|
334
|
-
else
|
335
|
-
eh = h[:email][:home]
|
336
|
-
ew = h[:email][:work]
|
337
|
-
xml.email({location: 'work'}, ew) if ew
|
338
|
-
xml.email({location: 'home'}, eh) if eh
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
# -- urls ---------------------------------
|
343
|
-
|
344
|
-
h[:url] ||= h[:urls]
|
345
|
-
|
346
|
-
if h[:url] then
|
347
|
-
|
348
|
-
if h[:url].is_a? String then
|
349
|
-
xml.url h[:url]
|
350
|
-
else
|
351
|
-
|
352
|
-
# unfortunately vPim doesn't use a block with the add_url method
|
353
|
-
#maker.add_url (h[:url][:work]){|e| e.location = 'work'} if h[:url][:work]
|
354
|
-
|
355
|
-
h[:url][:items].each {|url| xml.url url }
|
356
|
-
|
357
|
-
end
|
358
|
-
|
359
|
-
end
|
360
|
-
|
361
|
-
# -- photos
|
362
|
-
|
363
|
-
xml.photo link: h[:photo] if h[:photo]
|
364
|
-
|
365
|
-
# -- telephone
|
366
|
-
|
367
|
-
tel = h[:tel]
|
368
|
-
|
369
|
-
if tel then
|
370
|
-
|
371
|
-
if tel.is_a? String then
|
372
|
-
|
373
|
-
xml.tel tel
|
374
|
-
|
375
|
-
else
|
376
|
-
th = h[:tel][:home]
|
377
|
-
tw = h[:tel][:work]
|
378
|
-
xml.tel({location: 'work'}, tw) if tw
|
379
|
-
xml.tel({location: 'home'}, th) if th
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
# -- categories ------------
|
384
|
-
xml.categories h[:categories].split(/\s*,\s*/) if h[:categories]
|
385
|
-
|
386
|
-
# -- source ------------
|
387
|
-
xml.source h[:source] if h[:source]
|
388
|
-
|
389
|
-
# -- Twitter ------------
|
390
|
-
xml.x_twitter h[:twitter] if h[:twitter]
|
391
|
-
|
392
|
-
# -- XMPP
|
393
|
-
xmpp = h[:jabber] || h[:xmpp]
|
394
|
-
xml.x_jabber({type: 'im'}, xmpp) if xmpp
|
395
|
-
|
396
|
-
end
|
397
|
-
|
398
|
-
Rexle.new(a)
|
399
|
-
end
|
400
|
-
|
401
|
-
end
|
data/lib/xdata.xsl
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
|
2
|
-
<xsl:output method='xml' indent='yes'/>
|
3
|
-
|
4
|
-
|
5
|
-
<xsl:template match='vcard'>
|
6
|
-
<xsl:element name='vcards'>
|
7
|
-
<xsl:attribute name='xmlns'>urn:ietf:params:xml:ns:vcard-4.0</xsl:attribute>
|
8
|
-
<xsl:element name='vcard'>
|
9
|
-
|
10
|
-
<xsl:apply-templates select='name' />
|
11
|
-
<xsl:apply-templates select='email' />
|
12
|
-
</xsl:element>
|
13
|
-
</xsl:element>
|
14
|
-
|
15
|
-
</xsl:template>
|
16
|
-
|
17
|
-
<xsl:template match='name'>
|
18
|
-
<xsl:element name='fn'>
|
19
|
-
<xsl:element name='text'><xsl:value-of select='fullname'/></xsl:element></xsl:element>
|
20
|
-
<xsl:element name='n'>
|
21
|
-
<xsl:element name="surname"><xsl:value-of select='family' /></xsl:element>
|
22
|
-
<xsl:element name="given"><xsl:value-of select='given' /></xsl:element>
|
23
|
-
<xsl:element name="additional"><xsl:value-of select='middlename' /></xsl:element>
|
24
|
-
<xsl:element name="prefix"><xsl:value-of select='prefix' /></xsl:element>
|
25
|
-
<xsl:element name="suffix"><xsl:value-of select='suffix' /></xsl:element>
|
26
|
-
</xsl:element>
|
27
|
-
|
28
|
-
</xsl:template>
|
29
|
-
|
30
|
-
|
31
|
-
<xsl:template match='email'>
|
32
|
-
|
33
|
-
<xsl:element name='email'>
|
34
|
-
<xsl:element name="parameters">
|
35
|
-
<xsl:element name='type'>
|
36
|
-
<xsl:element name='text'>
|
37
|
-
<xsl:value-of select='@location'/>
|
38
|
-
</xsl:element>
|
39
|
-
</xsl:element>
|
40
|
-
</xsl:element>
|
41
|
-
<xsl:element name='text'>
|
42
|
-
<xsl:value-of select='.' />
|
43
|
-
</xsl:element>
|
44
|
-
|
45
|
-
</xsl:element>
|
46
|
-
|
47
|
-
</xsl:template>
|
48
|
-
|
49
|
-
</xsl:stylesheet>
|