Template additions.

This commit is contained in:
Luka Vandervelden 2019-11-16 21:28:58 +01:00
parent 3a502f0415
commit 671bf44dc4

View File

@ -8,7 +8,7 @@ def sanitize_path(path)
end
class Service
alias CrinjaHash = Hash(String, Hash(String, Int32) | String | Nil)
alias CrinjaHash = Hash(String, Hash(String, Int32) | String | Crinja::Callable::Instance | Nil)
def to_genconfig
CrinjaHash.new.tap do |entry|
entry["name"] = name
@ -17,6 +17,18 @@ class Service
entry["root"] = root
entry["domain"] = domain
entry["ports"] = ports
entry["consumers"] = Crinja.function do
token = arguments.varargs[0].to_s
get_consumers(token).map &.id
end
entry["providers"] = Crinja.function do
token = arguments.varargs[0].to_s
providers.find(&.[0].==(token)).try &.[1]
end
end
end
end
@ -116,6 +128,10 @@ class GenConfig::Context
end
end
options["get_service"] = Crinja.function do
context.get_service_by_id(arguments.varargs[0].to_s).try &.to_genconfig
end
options["raise"] = Crinja.function do
message = arguments.varargs.join "\n"