blob: fac6a03fc8dddb652903af100a2340700bebb2d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
const Minifier = @import("Minifier.zig");
pub fn File(comptime tag: ?[]const u8, comptime minifier: Minifier) type {
const opening = if (tag) |t| "<" ++ t ++ ">" else "";
const closing = if (tag) |t| "</" ++ t ++ ">" else "";
return struct {
file: []const u8,
do_minify: bool,
pub fn path(comptime p: []const u8) @This() {
return .{
.file = p,
.do_minify = false,
};
}
pub fn minify(comptime p: []const u8) @This() {
return .{
.file = p,
.do_minify = true,
};
}
pub fn to_html_string(comptime self: @This()) []const u8 {
return opening ++ (if (self.do_minify)
minifier.minify(@embedFile(self.file))
else
@embedFile(self.file)) ++ closing;
}
};
}
/// When using regex in Javascript the spaces
/// might get trimmed since /re/ is a awful syntax
/// I don't what to add a rule for it currently,
/// Since a single `/` is a operator but if there are two on one line
/// it is a regex.
pub const Script = File("script", .js);
pub const Style = File("style", .css);
pub const Html = File(null, .html);
|