Extract example from the README to a runnable location.

This commit is contained in:
Jonathan Bernard 2023-04-16 03:22:46 -05:00
parent 47c62cce6d
commit 7b71cb2dfe
3 changed files with 36 additions and 27 deletions

View File

@ -22,30 +22,7 @@ TEL;TYPE=CELL:+1 (555) 123-4567
END:VCARD END:VCARD
``` ```
```nim https://github.com/jdbernard/nim-vcard/blob/4839ff64a8e6da1ad4803adbd71c0a53cae81c4e/examples/simple.nim#L1-L22
import vcard
# Reading in an existing vcard
let vcards = parseVCard3File("jack.vcf")
assert vcards.len == 1
let vcAllen = vcards[0]
assert vcAllen.email.len == 2
assert vcAllen.email[0].value == "allen@fosters.test"
assert vcAllen.n.first == "Jack"
# Creating a new VCard
var vcSusan: VCard3
vcSusan.add(
newVC3_N(given = "Susan", family = "Foster"),
newVC3_Email(value = "susan@fosters.test", emailType = @["PREF", $etInternet),
newVC3_Tel(
value = "+1 (555) 444-3889",
telType = @[$ttHome, $ttCell, $ttVoice, $ttMsg])
)
writeFile("susan.vcf", $vcSusan)
```
## Future Goals ## Future Goals
@ -55,9 +32,9 @@ writeFile("susan.vcf", $vcSusan)
*Need to clean up and organize* *Need to clean up and organize*
Run `tlexer` tests in gdb: Run `tvcard3` tests in gdb:
```sh ```sh
$ cd tests $ cd tests
$ nim --debuginfo --linedir:on c tlexer $ nim --debuginfo --linedir:on c tvcard3
$ gdb --tui tlexer $ gdb --tui tvcard3

10
examples/jack.vcf Normal file
View File

@ -0,0 +1,10 @@
BEGIN:VCARD
VERSION:3.0
UID: 5db6f100-e2d6-4e8d-951f-d920586bc069
N:Foster;Jack;Allen;;
FN:Allen Foster
REV:20230408T122102Z
EMAIL;TYPE=home;TYPE=pref:allen@fosters.test
EMAIL;TYPE=work:jack.foster@company.test
TEL;TYPE=CELL:+1 (555) 123-4567
END:VCARD

22
examples/simple.nim Normal file
View File

@ -0,0 +1,22 @@
import vcard
# Reading in an existing vcard
let vcards = parseVCard3File("jack.vcf")
assert vcards.len == 1
let vcAllen = vcards[0]
assert vcAllen.email.len == 2
assert vcAllen.email[0].value == "allen@fosters.test"
assert vcAllen.n.given[0] == "Jack"
# Creating a new VCard
var vcSusan: VCard3
vcSusan.add(@[
newVC3_N(given = @["Susan"], family = @["Foster"]),
newVC3_Email(value = "susan@fosters.test", emailType = @["PREF",
$etInternet]),
newVC3_Tel(
value = "+1 (555) 444-3889",
telType = @[$ttHome, $ttCell, $ttVoice, $ttMsg])
])
writeFile("susan.vcf", $vcSusan)