Repository navigation
Template tutorial
Each template is a folde with the project template and makemake config file.
The config file a special file that is readed by makemake when loading templates.
The config file is always name makemake.json. If there is no config file makemake will
just copy the folder.
In here I will be showing makemake on C project template, but you can do any language you want. Or it can be just random set of files that you often need to create.
To create a new template create a new folder e.g. hello-makemake (this folder will be reffered to as template folder). In the folder
create a source file main.c:
#include <stdio.h>
int main(void) {
printf("Hello World!");
}now in terminal (cwd in the directory) you can run:
makemake -c hello-makemakeCongratulations! You have just created your first template!
You can load it by going into a different folder (not in the fodlder with the template) (this folder will be refered to as test fodler) and typing:
makemake hello-makemakeAs you can see your main.c file just appeared.
If you would now run the program you would realise that you forgot to put a newline after the Hello World! message.
You can edit the main.c file (in the template folder) to have the newline:
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
}If you try to load the template now in the test folder by typing:
makemake hello-makemakemakemake will ask you if you really wan't to load the template. It is because in the current folder there is a file and makemake will rather ask you than overwriting it. You can type 'y' to overwrite any conflicting files or 'n' to not load the template. If you know that makemake will ask you and you would just type 'y', you can add the '-py' flag:
makemake hello-makemake -pyThis is same as if you would always answer with 'y'.
When you load the template you realise that the newline is still not there. That is because when creating template makemake copies it to its configuration folder (so all the templates are in one place) so when you want to update template you must 'create' it again:
makemake -c hello-makemake -pyNow when you load the template the newline will be there. This is great but it is nothing more than just
fancy way to copy files. If you want to do something more than just copy files you need to create the
file makemake.json (in the template folder).
Lets say you wan't to be able to choose who/what will the program greet when creating the template.
In the file makemake.json type the following:
{
"$schema": "https://raw.githubusercontent.com/BonnyAD9/makemake-rs/master/useful_stuff/json-schema/makemake-schema.json",
"files": {
"makemake.json": "Ignore",
"main.c": "Make"
},
"vars": {
"greet": "World"
}
}and edit main.c:
#include <stdio.h>
int main(void) {
printf("Hello ${greet}!\n");
}In the makemake.json the $schema just allows your editor to check whether you have valid file.
Id doesn't have to be there. The 'files' is a dictionary that specifies what to do with files in the
template. The basic options for each file are
- 'Copy': the default if you don't write anything about the file in the
makemake.json, it just copies the file - 'Ignore': the file will not be created when loading template
- 'Make': the file will contain some expressions that makemake should expand
The vars field is where you can declare variables for the template. In this case we create variable with name
greet and value World.
Than if you want to use variable in file you can enclose it in a ${ and }.
If you now try the template the result is the same as before. But now you can esily change the value of the variable
when loading the template symply by adding -Dgreet=new_value:
makemake hello-makemake -Dgreet=makemake
Lets say that you now want to be able to also choose whether you want the main function to take arguments or not.
You can edit the main.c:
#include <stdio.h>
int main(${args ? 'int argc, char **argv' : 'void'}) {
printf("Hello ${greet}!\n");
}The <q> ? <v1> : <v2> operator works in a simillar way as in C. Here if variable args is defined makemake
will insert the string after the ?, otherwise it will insert the string after :. And theese doesn't have to be
strings, they can also be variables or other ? : operators.
When you now load the template as
makemake hello-makemake -DargsThe main will take arguments, but when you call it wihtout the -Dargs it won't.
If you want to know more see the section The template format