2017-10-18 09:20:27 +00:00
|
|
|
//
|
|
|
|
// imag - the personal information management suite for the commandline
|
2018-02-07 01:48:53 +00:00
|
|
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
2017-10-18 09:20:27 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; version
|
|
|
|
// 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
//
|
|
|
|
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
2018-04-25 11:34:46 +00:00
|
|
|
use libimagcontact::deser::DeserVcard;
|
2017-10-18 09:20:27 +00:00
|
|
|
|
2018-04-25 11:34:46 +00:00
|
|
|
pub fn build_data_object_for_handlebars<'a>(i: usize, vcard: &DeserVcard) -> BTreeMap<&'static str, String> {
|
|
|
|
let mut data = BTreeMap::new();
|
2017-10-18 09:20:27 +00:00
|
|
|
|
2018-04-25 11:34:46 +00:00
|
|
|
let process_list = |list: &Vec<String>| {
|
|
|
|
list.iter()
|
|
|
|
.map(String::clone)
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", ")
|
|
|
|
};
|
2017-10-18 09:20:27 +00:00
|
|
|
|
2018-04-25 11:34:46 +00:00
|
|
|
let process_opt = |opt: Option<&String>| {
|
|
|
|
opt.map(String::clone).unwrap_or_else(String::new)
|
|
|
|
};
|
2017-10-18 09:20:27 +00:00
|
|
|
|
2018-04-25 11:34:46 +00:00
|
|
|
{
|
|
|
|
data.insert("i" , format!("{}", i));
|
2017-10-18 09:20:27 +00:00
|
|
|
|
2018-04-25 11:34:46 +00:00
|
|
|
// The hash (as in libimagentryref) of the contact
|
|
|
|
data.insert("id" , process_opt(vcard.uid()));
|
|
|
|
data.insert("ADR" , process_list(vcard.adr()));
|
|
|
|
data.insert("ANNIVERSARY" , process_opt(vcard.anniversary()));
|
|
|
|
data.insert("BDAY" , process_opt(vcard.bday()));
|
|
|
|
data.insert("CATEGORIES" , process_list(vcard.categories()));
|
|
|
|
data.insert("CLIENTPIDMAP" , process_opt(vcard.clientpidmap()));
|
2018-04-27 11:48:18 +00:00
|
|
|
data.insert("EMAIL" , process_list(&vcard.email().iter().map(|a| a.address.clone()).collect()));
|
2018-04-25 11:34:46 +00:00
|
|
|
data.insert("FN" , process_list(vcard.fullname()));
|
|
|
|
data.insert("GENDER" , process_opt(vcard.gender()));
|
|
|
|
data.insert("GEO" , process_list(vcard.geo()));
|
|
|
|
data.insert("IMPP" , process_list(vcard.impp()));
|
|
|
|
data.insert("KEY" , process_list(vcard.key()));
|
|
|
|
data.insert("LANG" , process_list(vcard.lang()));
|
|
|
|
data.insert("LOGO" , process_list(vcard.logo()));
|
|
|
|
data.insert("MEMBER" , process_list(vcard.member()));
|
|
|
|
data.insert("N" , process_opt(vcard.name()));
|
|
|
|
data.insert("NICKNAME" , process_list(vcard.nickname()));
|
|
|
|
data.insert("NOTE" , process_list(vcard.note()));
|
|
|
|
data.insert("ORG" , process_list(vcard.org()));
|
|
|
|
data.insert("PHOTO" , process_list(vcard.photo()));
|
|
|
|
data.insert("PRIOD" , process_opt(vcard.proid()));
|
|
|
|
data.insert("RELATED" , process_list(vcard.related()));
|
|
|
|
data.insert("REV" , process_opt(vcard.rev()));
|
|
|
|
data.insert("ROLE" , process_list(vcard.role()));
|
|
|
|
data.insert("SOUND" , process_list(vcard.sound()));
|
|
|
|
data.insert("TEL" , process_list(vcard.tel()));
|
|
|
|
data.insert("TITLE" , process_list(vcard.title()));
|
|
|
|
data.insert("TZ" , process_list(vcard.tz()));
|
|
|
|
data.insert("UID" , process_opt(vcard.uid()));
|
|
|
|
data.insert("URL" , process_list(vcard.url()));
|
|
|
|
data.insert("VERSION" , process_opt(vcard.version()));
|
2017-10-18 09:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data
|
|
|
|
}
|
|
|
|
|