In that example we will use simput to create vcard for our contact information and we will walk you through the model definition to its usage inside Simput.
Creation of new type
Model creation
Let’s create one View for which we can add and remove as many person
. A person
should have a firstName, lastName with some address information.
module.exports = { |
Convert function
Now that we have the piece of information we want from the user, let’s see how we can write each person
into a single file with its personal information using the vcard
format.
The funtion below will loop over each view data and will define a new file using a template that will allow us to respect the vcard format.
const vCardTemplate = require("./templates/vcard.hbs"); |
Template file
The following template is strait forward but looping and condition could be achieved inside a template.
Click to learn more about Handlebars
BEGIN:VCARD |
Compilation of new type
Make sure Simput
has been installed globally by running the following command line:
$ npm install -g simput |
If properly installed, you should be able to run Simput
and get the following command line help.
$ Simput |
Now, you should be able to build your new type define with the following file structure:
$ find . -type f |
Let’s create a new compiled type vcard
using the local directory for both input and output.
$ Simput -c . -o . -t vcard |
Now let’s see what we have
$ find . -type f |
In order to make that new type available, you will need to edit the index.html
by adding the following line in the last inline script section.
Simput.registerType('vcard', ['./types/vcard.js']); |
The content of that array can actually be several path/url to various scripts that you would need to load for your given new type.
Use Simput and your type to fill your address book
Let’s try to run it and enter a couple of persons
First of all, you will need to create an empty model as a file that would look like that
{ |
Then you can start Simput as follow
$ Simput -p 8080 |
Open http://localhost:8080 in your browser.
Then drag-and-drop the file you created into Simput.
At that point you can start editing the content.
Initial empty page / content
Start filling it…
Add a couple persons
Then press on Save & Convert
button
The vcard have been written along with the data model
If you restart Simput and drag-and-drop the last generated zip file, you will find all the persons you’ve entered
Add a couple persons