UNPKG

xweb-templating

Version:

A cli tool for converting 'tags' to regular html, php or some other format

160 lines (139 loc) 4.53 kB
# xweb A cli tool for converting 'tags' to regular html, php or some other format. ## description The xweb cli can scan for files to convert, add what are called 'tagsets' (kindof like a library for custom tags) and convert the source code into an output using those tagsets ## installation Before you install the cli, make sure you have NodeJS and NPM installed. To actually install xweb run ```console npm install -g xweb-templating ``` ## usage You can always view the help using 'xweb --help', but I'll also give you a description of all the posible commands right here ### default/run You can run the following ```console xweb ``` or ``` xweb run ``` to scan the source folder (defined in the config file or using the default, 'src') and search for any .xweb file (or some other file extension defined in the config file) and convert it to the desired output. ### init This is a command to setup a basic xweb project. It asks you for your preferences and sets up the rest automaticly. ```console xweb init ``` If you add the --yes or simply -y flag to the end it will not prompt you, but just use the defaults ```console xweb init --yes ``` ### install This command checks wich tagsets are inside the tagsets folder (also defined in config file) and compares them with the list defined in the config file. If it notices there is a tagset defined inside the config file that is not inside the tagset folder it will attempt to fetch it from [this repo](https://github.com/CodeBoy124/xweb-tagsets) ```console xweb install ``` ### update This command is similar to the install command, but doesn't compare the list defined in the config file against the tagsets folder. Instead it fetches all tagsets defined in the config and adds them to the tagsets folder or overwrites them ```console xweb update ``` ### add This command adds a tagset to the config and also fetches it ```console xweb add my-package ``` or ```console xweb add my-package other-package ``` ## remove This command does the opposite from the add command, because it removes a tagset from the config and also deletes it's file from the tagset folder ```console xweb remove my-package ``` or ```console xweb remove my-package other-package ``` ## writing stuff using xweb There are 3 important things in xweb at the moment: tags, inline xweb and ignoring tags and inline xweb ### tags A 'tag' is kindof like calling a function. Every tag starts with a '@' symbol followed by it's name and (optionally) it's arguments inside '(' and ')' and seperated by a ',' Say you have a greet tag which shows a welcome message and a day of the week. You could write the following 'tag' (if there would be a tagset with the definition for 'greet') ``` <html> <body> ...some html <div> @greet("username12", "monday") </div> ...some html </body> </html> ``` This could be converted to ``` <html> <body> ...some html <div> <h1>Welcome, @username12</h1> <p> Today it is monday </p> </div> ...some html </body> </html> ``` ### inline xweb Inline xweb was primarely made for usage with php. This allows you to use '{{' and '}}' instead of '<?=' and '?>'. This can be customized in the config file. Here is an example (with php) when you want to show a list of usernames ``` <ul> @foreach($users as $user) <li> username: {{ $user->name }} </li> @end </ul> ``` is converted to ``` <ul> <?php foreach($users as $user) { ?> <li> username: <?= $user->name ?> </li> <?php } ?> </ul> ``` ### ignoring tags and inline xweb If you want to show a '@' character you'll have to do some extra work, because it is recognised as a tag start by default. If you put a '\' directly before the '@' it will be ignored and will therefor will remain a '@' symbol. If you still want to show the '\@' combination you have to write it like '\\\@', because the first '\' ignores the second '\' and the third '\' ignores the '@' symbol This also works with inline xweb. Here is an example: ``` User \@user12 Here is some ignored inline xweb \{{ content }} Some weird combination \\\@ ``` This example is converted to ``` User @user12 Here is some ignored inline xweb {{ content }} Some weird combinatin \@ ``` ## contributing Thank you for considering to contribute to this project. Feel free to clone, improve and send a pull request. Please be clear about what the goal of your improvement is in your pull request