luci-base: fix rendering ucode templates from `template` target
authorJo-Philipp Wich <jo@mein.io>
Tue, 22 Nov 2022 08:41:31 +0000 (09:41 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 22 Nov 2022 08:41:31 +0000 (09:41 +0100)
A previous commit inadvertently broke support for rendering ucode templates
from the `template` dispatcher target.

Fixes: #6111
Fixes: fa17c1573f ("luci-base, luci-lua-runtime: adjust Lua template environment")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/ucode/dispatcher.uc
modules/luci-base/ucode/runtime.uc

index 0644a756c2c4423186946f9bbb604dfd463312c9..50201be0f4c75194c33a7952e9d11068fc2aa4cd 100644 (file)
@@ -774,9 +774,12 @@ function render_action(fn) {
 function run_action(request_path, lang, tree, resolved, action) {
        switch (action?.type) {
        case 'template':
-               render_action(() => {
-                       runtime.call('luci.dispatcher', 'render_lua_template', action.path);
-               });
+               if (runtime.is_ucode_template(action.path))
+                       runtime.render_ucode(action.path);
+               else
+                       render_action(() => {
+                               runtime.call('luci.dispatcher', 'render_lua_template', action.path);
+                       });
                break;
 
        case 'view':
index da73d13fe4a7a4cd018794cd8d01c34e2f6e82f1..89e396d468939b48f29b5d8f8e69e05cd48a1d59 100644 (file)
@@ -61,6 +61,10 @@ const Class = {
                return this.L;
        },
 
+       is_ucode_template: function(path) {
+               return access(`${template_directory}/${path}.ut`);
+       },
+
        render_ucode: function(path, scope) {
                let tmplfunc = loadfile(path, { raw_mode: false });