diff --git a/src/gen-config.cr b/src/gen-config.cr index 6ba2adf..3168153 100644 --- a/src/gen-config.cr +++ b/src/gen-config.cr @@ -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"