simplevpim 0.4.1 → 0.5.3

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
- SHA1:
3
- metadata.gz: 88a4ecaf25cd2da91062608edeb5d707740f3b99
4
- data.tar.gz: 0a8ff1910d5ba683478653bb73f5cdfe4ec09a25
2
+ SHA256:
3
+ metadata.gz: abcb417a8b4f478d5f5211fce1be561fba04587f7ac4f302ea13bd1476b750dd
4
+ data.tar.gz: 8a44c2cb449a7262b83f7e18675e681e958195640ac874efc3a152c72d8c307a
5
5
  SHA512:
6
- metadata.gz: 958f5b2413c2708e6e89b1ccc36f784f6d9af8351e02cbda3ff778e77bd4f56b00875cb4ae9d9852261591bf57516ecd5012485e420765f3727a40f3f8f203e5
7
- data.tar.gz: c268adf5375878c81a29cb16b8e523a831f072beceabcd14cbaaea50999f5eb7b405927b6eb5f0fd4bea1c4737a4177418e9557290022672c588928f72b481f3
6
+ metadata.gz: 4f6b06dc9ba29c72d525ea6db7d57227b289b051913143dc3d8d28c7c973388ce89ba87df6675b964563dd0e0a04bd2e10ce6e9506e6c9af486f0744d13bd6f4
7
+ data.tar.gz: 88b4928b454d51c1c8e49299fad325f376616ebcea0704ca93f87308d39b35226df2e457badd3aee807e683aa81f7123f8d2a654ef5b97ee795cdb6220019997
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/simplevpim.rb CHANGED
@@ -6,20 +6,62 @@ require 'hlt'
6
6
  require 'nokogiri'
7
7
  require 'vpim/vcard'
8
8
  require 'rexle-builder'
9
- require 'simple-config'
9
+ require 'kvx'
10
+ require 'unichron'
10
11
 
11
12
 
12
13
  class SimpleVpim
14
+ using ColouredText
13
15
 
14
- attr_reader :to_vcard, :to_xml
16
+ attr_reader :to_vcard, :to_vevent, :to_xml
17
+
18
+ a = %i(firstname lastname name tel addr email)
19
+ Contact = Struct.new(*a)
20
+ Event = Struct.new(*%i(title summary start end location description))
21
+
22
+ def initialize(rawobj, debug: false)
23
+
24
+ @debug = debug
15
25
 
16
- def initialize(s)
26
+ obj = if block_given? then
27
+
28
+ if rawobj == :event then
29
+
30
+ e = Event.new
31
+ yield e
32
+ e.to_h
33
+
34
+ elsif rawobj == :contact then
17
35
 
18
- @h = SimpleConfig.new(s).to_h
36
+ puts 'inside contact' if @debug
37
+ c = Contact.new
38
+ yield c
39
+ c.to_h
40
+
41
+ end
42
+
43
+ else
44
+
45
+ rawobj
46
+
47
+ end
48
+
49
+ puts 'obj: ' + obj.inspect if @debug
50
+
51
+ kvx = Kvx.new(obj, debug: false)
52
+
53
+ @h = kvx.to_h
19
54
 
20
- if @h[:name] then
55
+ if @h[:name] or @h[:firstname] or @h[:lastname] then
56
+
21
57
  @to_vcard = make_vcard @h
22
58
  @to_xml = vcard_xml @h
59
+
60
+ elsif @h[:start]
61
+
62
+ @to_vevent = make_vevent @h
63
+ @to_xml = vevent_xml kvx.to_xml
64
+
23
65
  end
24
66
 
25
67
  end
@@ -61,6 +103,11 @@ class SimpleVpim
61
103
  end
62
104
 
63
105
  def make_vcard(h)
106
+
107
+ if @debug then
108
+ puts 'inside make_vcard'.info
109
+ puts 'h: ' + h.inspect
110
+ end
64
111
 
65
112
  card = Vpim::Vcard::Maker.make2 do |maker|
66
113
 
@@ -73,8 +120,23 @@ class SimpleVpim
73
120
 
74
121
  prefix = h[:prefix]
75
122
  suffix = h[:suffix]
76
-
77
- firstname, middlename, surname, fullname = extract_names(h[:name])
123
+
124
+ if h[:name] then
125
+
126
+ firstname, middlename, surname, fullname = extract_names(h[:name])
127
+
128
+ elsif h[:firstname] or h[:lastname]
129
+
130
+ firstname = h[:firstname] if h[:firstname]
131
+ surname = h[:lastname] if h[:lastname]
132
+
133
+ fullname = if h[:fullname] then
134
+ h[:fullname]
135
+ else
136
+ [firstname, surname].compact.join(' ')
137
+ end
138
+
139
+ end
78
140
 
79
141
  maker.add_name do |name|
80
142
  name.prefix = prefix if prefix
@@ -99,6 +161,17 @@ class SimpleVpim
99
161
  maker.add_email(eh) { |e| e.location = 'home' } if eh
100
162
  end
101
163
  end
164
+
165
+
166
+ # -- address ------------------------------
167
+
168
+ adr = h[:addr]
169
+ puts ('adr: ' + adr.inspect).debug if @debug
170
+ if adr then
171
+ maker.add_addr do |addr|
172
+ addr.street = adr
173
+ end
174
+ end
102
175
 
103
176
  # -- urls ---------------------------------
104
177
 
@@ -156,6 +229,24 @@ class SimpleVpim
156
229
 
157
230
  end
158
231
  end
232
+
233
+ def make_vevent(h)
234
+
235
+ dstart, dend = %i(start end).map do |x|
236
+ Unichron.new(h[x]).to_date.strftime("%Y%m%d")
237
+ end
238
+
239
+ s = "BEGIN:VEVENT
240
+ SUMMARY:#{h[:title] || h[:summary]}
241
+ DTSTART;VALUE=DATE:#{dstart}
242
+ DTEND;VALUE=DATE:#{dend}
243
+ "
244
+
245
+ s += 'LOCATION:' + h[:location] + "\n" if h[:location]
246
+ s += 'DESCRIPTION:' + h[:description] + "\n" if h[:description]
247
+ s += 'END:VEVENT'
248
+
249
+ end
159
250
 
160
251
  def make_hcard(raw_s, h)
161
252
 
@@ -293,11 +384,10 @@ EOF
293
384
  end
294
385
 
295
386
  def make_xcard(xml)
296
-
297
- lib = File.dirname(__FILE__)
387
+ #lib = File.dirname(__FILE__)
388
+ lib = 'http://a0.jamesrobertson.me.uk/rorb/r/ruby/simplevpim'
298
389
  xsl = open(lib + '/xcard.xsl','UserAgent' => 'SimplevPim').read
299
390
  doc = Nokogiri::XML(xml)
300
-
301
391
  xslt = Nokogiri::XSLT(xsl)
302
392
  xslt.transform(doc).to_s
303
393
  end
@@ -307,7 +397,22 @@ EOF
307
397
  prefix = h[:prefix]
308
398
  suffix = h[:suffix]
309
399
 
310
- firstname, middlename, surname, fullname = extract_names(h[:name])
400
+ if h[:name] then
401
+
402
+ firstname, middlename, surname, fullname = extract_names(h[:name])
403
+
404
+ elsif h[:firstname] or h[:lastname]
405
+
406
+ firstname = h[:firstname] if h[:firstname]
407
+ surname = h[:lastname] if h[:lastname]
408
+
409
+ fullname = if h[:fullname] then
410
+ h[:fullname]
411
+ else
412
+ [firstname, surname].compact.join(' ')
413
+ end
414
+
415
+ end
311
416
 
312
417
  xml = RexleBuilder.new
313
418
 
@@ -398,5 +503,13 @@ EOF
398
503
 
399
504
  Rexle.new(a)
400
505
  end
506
+
507
+ def vevent_xml(xml)
508
+
509
+ doc = Rexle.new(xml)
510
+ doc.root.name = 'vevent'
511
+ doc.root.xml
512
+
513
+ end
401
514
 
402
515
  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.1
4
+ version: 0.5.3
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
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE0MTEwNDE4MDQxNVoXDTE1MTEwNDE4MDQxNVowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAOIxezQlow3Mc2hiMUYKNfXS0aeuDaDshlHayqGprhcjcC26JheR6fw5LC5q
19
- O2cLSN2X4/y1Ejpl3rDCaEQ2uTM+0oQdlEdOZaMDiPAYmkNHOursxMQ/ztylpgmZ
20
- hKYDn5NYhlh/HDAWgE4OJCsyTxR8/tUMQ2JsTNbh7iq2T2e9ruZK6+WO1uBxV299
21
- W9XJYLNQ+TNX1UyTlISTPz46ZHrW0jl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P
33
+ nH2NGMAKFKRnV1ckoSFcvhYYzJGpYYGFlGGMrAPtzAW8NyHDOwwA/koYXY1oh9kB
34
+ iOeNjtxEJvb/5Qnz8M8K2CBXRfktT6ZghoJMc12q2bM3XE71RF3yJ/E250/Xp3+Z
35
+ dBpGyLXPFeCV5Z8rWY+S891OLL3UPvcmIiolU7aaNSwvXBGLesCCH6TrIdhw4q2z
36
+ pM4lNlA3G8w+xUHw/9AE8V6p
33
37
  -----END CERTIFICATE-----
34
- date: 2014-11-22 00:00:00.000000000 Z
38
+ date: 2021-06-27 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
- name: simple-config
41
+ name: hlt
38
42
  requirement: !ruby/object:Gem::Requirement
39
43
  requirements:
40
44
  - - "~>"
41
45
  - !ruby/object:Gem::Version
42
- version: '0.1'
46
+ version: '0.6'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 0.1.13
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.1'
56
+ version: '0.6'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 0.1.13
59
+ version: 0.6.3
56
60
  - !ruby/object:Gem::Dependency
57
61
  name: vpim
58
62
  requirement: !ruby/object:Gem::Requirement
@@ -74,74 +78,52 @@ dependencies:
74
78
  - !ruby/object:Gem::Version
75
79
  version: 13.11.11
76
80
  - !ruby/object:Gem::Dependency
77
- name: rexle-builder
81
+ name: unichron
78
82
  requirement: !ruby/object:Gem::Requirement
79
83
  requirements:
80
84
  - - "~>"
81
85
  - !ruby/object:Gem::Version
82
- version: '0.1'
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: 0.1.10
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: '0.1'
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: 0.1.10
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'
86
+ version: '0.3'
103
87
  - - ">="
104
88
  - !ruby/object:Gem::Version
105
- version: 1.6.2.1
89
+ version: 0.3.7
106
90
  type: :runtime
107
91
  prerelease: false
108
92
  version_requirements: !ruby/object:Gem::Requirement
109
93
  requirements:
110
94
  - - "~>"
111
95
  - !ruby/object:Gem::Version
112
- version: '1.6'
96
+ version: '0.3'
113
97
  - - ">="
114
98
  - !ruby/object:Gem::Version
115
- version: 1.6.2.1
99
+ version: 0.3.7
116
100
  - !ruby/object:Gem::Dependency
117
- name: hlt
101
+ name: rexle-builder
118
102
  requirement: !ruby/object:Gem::Requirement
119
103
  requirements:
120
104
  - - "~>"
121
105
  - !ruby/object:Gem::Version
122
- version: '0.3'
106
+ version: '1.0'
123
107
  - - ">="
124
108
  - !ruby/object:Gem::Version
125
- version: 0.3.2
109
+ version: 1.0.3
126
110
  type: :runtime
127
111
  prerelease: false
128
112
  version_requirements: !ruby/object:Gem::Requirement
129
113
  requirements:
130
114
  - - "~>"
131
115
  - !ruby/object:Gem::Version
132
- version: '0.3'
116
+ version: '1.0'
133
117
  - - ">="
134
118
  - !ruby/object:Gem::Version
135
- version: 0.3.2
119
+ version: 1.0.3
136
120
  description:
137
- email: james@r0bertson.co.uk
121
+ email: digital.robertson@gmail.com
138
122
  executables: []
139
123
  extensions: []
140
124
  extra_rdoc_files: []
141
125
  files:
142
126
  - lib/simplevpim.rb
143
- - lib/simplevpim.rb~
144
- - lib/xdata.xsl
145
127
  homepage: https://github.com/jrobertson/simplevpim
146
128
  licenses:
147
129
  - MIT
@@ -161,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
143
  - !ruby/object:Gem::Version
162
144
  version: '0'
163
145
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.2.2
146
+ rubygems_version: 3.1.2
166
147
  signing_key:
167
148
  specification_version: 4
168
149
  summary: A simple wrapper for the vPim gem
metadata.gz.sig CHANGED
Binary file
data/lib/simplevpim.rb~ DELETED
@@ -1,374 +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 = SimpleConfig.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
- doc.at_css('.photo').delete unless h[:photo]
252
- doc.css('.tel').each(&:delete) unless h[:tel]
253
- doc.css('.adr').each(&:delete) unless h[:adr]
254
- doc.css('.label').each(&:delete) unless h[:label]
255
-
256
- if h[:email].is_a? String then
257
- e = doc.at_css '.email'
258
- e.text = 'Email:'
259
- alink = Rexle::Element.new('a')
260
- alink.attributes[:class] = 'value'
261
- alink.attributes[:href] = 'mailto:' + h[:email]
262
- alink.text = h[:email]
263
- e.add_element alink
264
- end
265
- [doc, h]
266
-
267
- end
268
-
269
- def make_xcard(xml)
270
- lib = File.dirname(__FILE__)
271
- xsl = open(lib + '/xcard.xsl','UserAgent' => 'SimplevPim').read
272
- doc = Nokogiri::XML(xml)
273
- xslt = Nokogiri::XSLT(xsl)
274
- xslt.transform(doc).to_s
275
- end
276
-
277
- def vcard_xml(h)
278
-
279
- prefix = h[:prefix]
280
- suffix = h[:suffix]
281
-
282
- firstname, middlename, surname, fullname = extract_names(h[:name])
283
-
284
- xml = RexleBuilder.new
285
-
286
- a = xml.vcard do
287
-
288
- xml.name do
289
-
290
- xml.prefix prefix if prefix
291
- xml.given firstname
292
- xml.family surname
293
- xml.suffix suffix if suffix
294
- xml.fullname fullname if fullname
295
- end
296
-
297
- # -- email -----------------------------
298
-
299
- e = h[:email]
300
-
301
- if e then
302
-
303
- if e.is_a? String then
304
-
305
- xml.email e
306
-
307
- else
308
- eh = h[:email][:home]
309
- ew = h[:email][:work]
310
- xml.email({location: 'work'}, ew) if ew
311
- xml.email({location: 'home'}, eh) if eh
312
- end
313
- end
314
-
315
- # -- urls ---------------------------------
316
-
317
- h[:url] ||= h[:urls]
318
-
319
- if h[:url] then
320
-
321
- if h[:url].is_a? String then
322
- xml.url h[:url]
323
- else
324
-
325
- # unfortunately vPim doesn't use a block with the add_url method
326
- #maker.add_url (h[:url][:work]){|e| e.location = 'work'} if h[:url][:work]
327
-
328
- h[:url][:items].each {|url| xml.url url }
329
-
330
- end
331
-
332
- end
333
-
334
- # -- photos
335
-
336
- xml.photo link: h[:photo] if h[:photo]
337
-
338
- # -- telephone
339
-
340
- tel = h[:tel]
341
-
342
- if tel then
343
-
344
- if tel.is_a? String then
345
-
346
- xml.tel tel
347
-
348
- else
349
- th = h[:tel][:home]
350
- tw = h[:tel][:work]
351
- xml.tel({location: 'work'}, tw) if tw
352
- xml.tel({location: 'home'}, th) if th
353
- end
354
- end
355
-
356
- # -- categories ------------
357
- xml.categories h[:categories].split(/\s*,\s*/) if h[:categories]
358
-
359
- # -- source ------------
360
- xml.source h[:source] if h[:source]
361
-
362
- # -- Twitter ------------
363
- xml.x_twitter h[:twitter] if h[:twitter]
364
-
365
- # -- XMPP
366
- xmpp = h[:jabber] || h[:xmpp]
367
- xml.x_jabber({type: 'im'}, xmpp) if xmpp
368
-
369
- end
370
-
371
- Rexle.new(a)
372
- end
373
-
374
- 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>