aboutsummaryrefslogtreecommitdiff

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:

-- 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:

# 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.