aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 1318adbcbfad1266ffa6a044da8c2d766ad1b07b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Blueprint

Write your project templates using lua.

## Creating your own templates

A _template_ is just a directory containing at least one `build.lua` file
which describes to structure of the template. Then you can add files and directories
that should be created when creating a instance of the template.

Here is a simple example:

```lua
-- build.lua
local template = Template:new()

template:add_file("./test.py", {
	module = "a_module_that_is_different",
	name = template:option('name')
})

return template
```

Then the same directory will contain the `test.py` we added in the template:

```py
# test.py
#!/usr/bin/env python3

# This module is called @{name()}

import @{module}

print("@{function()
  return "Hello World"
end}")

print("@{function()
  local a = { "asdf", "1234" }
  return a[1]
end}")

print(@{function()
  local a = { "asdf", "1234" } -- {
  return a[2]
end})

print("@{function()
  local a = "asdf{asdf"
  return a:sub(1)
end}")

print("@{function()
  local a = "asdf"
  --[[
      some comment }
  --]]
  return a
end}")

print("@{function()
  local a = [[
      some comment }
  ]]
  return a:sub(2, 8)
end}")
```

As you can see you can now run lua-code inside of the `@{...}` sections.
The last table argument of the `add_file` function are functions or values you want to bind to the global scope of the macros and you want to use inside of the template file.

### Creating additional options

You can create additional command line arguments by calling `template:option('<name of your argument>')`. This returns a function which you can bind to the scripting environment like we did in the example above with the _name_ option.

If you want to set a default value for an option, make it not required or add a description you can do that with the `template:set_option('<name of your argument>', '<description>', '<default value>', '<required>')` function.