diff --git a/build.zig.zon b/build.zig.zon index 97a0eab..b40c5f8 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .pugz, - .version = "0.1.5", + .version = "0.1.6", .fingerprint = 0x822db0790e17621d, // Changing this has security and trust implications. .minimum_zig_version = "0.15.2", .dependencies = .{}, diff --git a/examples/demo/views/mixins/alert.pug b/examples/demo/views/mixins/alert.pug new file mode 100644 index 0000000..3d86db2 --- /dev/null +++ b/examples/demo/views/mixins/alert.pug @@ -0,0 +1,5 @@ +mixin alert(message) + div.alert(role="alert" class!=attributes.class) + svg(xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 shrink-0 stroke-current" fill="none" viewBox="0 0 24 24") + path(stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z") + span= message diff --git a/examples/demo/views/mixins/alert_error.pug b/examples/demo/views/mixins/alert_error.pug new file mode 100644 index 0000000..60061c5 --- /dev/null +++ b/examples/demo/views/mixins/alert_error.pug @@ -0,0 +1,2 @@ +mixin alert_error(message) + +alert(message)(class="alert-error") diff --git a/examples/demo/views/page-a.pug b/examples/demo/views/page-a.pug index c12ee23..12dd0f0 100644 --- a/examples/demo/views/page-a.pug +++ b/examples/demo/views/page-a.pug @@ -24,3 +24,5 @@ block content br +input_text("lastName", "Last Name", "last name") submit sumit + if error + +alert_error(error) diff --git a/src/build_templates.zig b/src/build_templates.zig index 142f82d..f276ed7 100644 --- a/src/build_templates.zig +++ b/src/build_templates.zig @@ -1336,21 +1336,26 @@ const Compiler = struct { var ident_buf: [64]u8 = undefined; const safe_param = escapeIdent(param, &ident_buf); - try self.writeIndent(); if (i < call.args.len) { // Argument provided const arg = call.args[i]; // Check if it's a string literal if (arg.len >= 2 and (arg[0] == '"' or arg[0] == '\'')) { + try self.writeIndent(); try self.writer.print("const {s} = {s};\n", .{ safe_param, arg }); } else { // It's a variable reference var accessor_buf: [512]u8 = undefined; const accessor = self.buildAccessor(arg, &accessor_buf); - try self.writer.print("const {s} = {s};\n", .{ safe_param, accessor }); + // Skip declaration if accessor equals param name (already in scope) + if (!std.mem.eql(u8, accessor, safe_param)) { + try self.writeIndent(); + try self.writer.print("const {s} = {s};\n", .{ safe_param, accessor }); + } } } else if (i < mixin_def.defaults.len) { // Use default value + try self.writeIndent(); if (mixin_def.defaults[i]) |default| { try self.writer.print("const {s} = {s};\n", .{ safe_param, default }); } else { @@ -1358,6 +1363,7 @@ const Compiler = struct { } } else { // No value - use empty string + try self.writeIndent(); try self.writer.print("const {s} = \"\";\n", .{safe_param}); } }