aboutsummaryrefslogtreecommitdiff
path: root/src/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/Component.zig30
-rw-r--r--src/frontend/Document.zig46
-rw-r--r--src/frontend/File.zig91
-rw-r--r--src/frontend/Head.zig58
-rw-r--r--src/frontend/root.zig12
-rw-r--r--src/frontend/web/hello-world/index.css7
-rw-r--r--src/frontend/web/hello-world/index.html3
-rw-r--r--src/frontend/web/hello-world/index.js3
-rw-r--r--src/frontend/web/index.css4
-rw-r--r--src/frontend/web/index.html1
-rw-r--r--src/frontend/z-component.js17
11 files changed, 0 insertions, 272 deletions
diff --git a/src/frontend/Component.zig b/src/frontend/Component.zig
deleted file mode 100644
index d90ed3b..0000000
--- a/src/frontend/Component.zig
+++ /dev/null
@@ -1,30 +0,0 @@
-const std = @import("std");
-
-const File = @import("File.zig");
-
-const Self = @This();
-
-name: []const u8,
-parent_dir: []const u8,
-
-pub fn path(p: []const u8) Self {
- const name = p[if (std.mem.lastIndexOfScalar(
- u8,
- std.mem.trim(u8, p, "/"),
- '/',
- )) |index| index + 1 else 0..];
-
- return .{
- .name = name,
- .parent_dir = p,
- };
-}
-
-pub fn to_html_string(comptime self: Self) []const u8 {
- const html: File.Html = .minify(self.parent_dir ++ "/index.html");
- const js: File.Script = .minify(self.parent_dir ++ "/index.js");
- const css: File.Style = .minify(self.parent_dir ++ "/index.css");
- return "<template id=\"--" ++ self.name ++ "\">" ++ css.to_html_string() ++ html.to_html_string() ++ js.to_html_string() ++ "</template>";
-}
-
-test {}
diff --git a/src/frontend/Document.zig b/src/frontend/Document.zig
deleted file mode 100644
index 0ba46b1..0000000
--- a/src/frontend/Document.zig
+++ /dev/null
@@ -1,46 +0,0 @@
-const std = @import("std");
-
-const Component = @import("Component.zig");
-const Head = @import("Head.zig");
-const File = @import("File.zig");
-
-const Self = @This();
-
-components: []const Component,
-head: Head,
-styles: []const File.Style,
-contents: []const File.Html,
-
-pub const empty: Self = .{
- .head = .empty,
- .components = &.{},
- .styles = &.{},
- .contents = &.{},
-};
-
-pub fn to_string(comptime self: Self) []const u8 {
- comptime var content: []const u8 = "<!DOCTYPE html><html>";
- content = content ++ comptime self.head.to_html_string(self.components, self.styles);
- content = content ++ "<body>";
-
- inline for (self.contents) |c| {
- content = content ++ comptime c.to_html_string();
- }
-
- content = content ++ "</body></html>";
-
- return content;
-}
-
-test {
- const document: Self = comptime .{
- .head = .default("test"),
- .components = &.{
- .path("./web/hello-world"),
- },
- .styles = &.{},
- .contents = &.{.minify("./web/index.html")},
- };
-
- std.debug.print("{s}", .{document.to_string()});
-}
diff --git a/src/frontend/File.zig b/src/frontend/File.zig
deleted file mode 100644
index e7c3b6d..0000000
--- a/src/frontend/File.zig
+++ /dev/null
@@ -1,91 +0,0 @@
-const std = @import("std");
-
-pub fn File(comptime tag: ?[]const u8, Iterator: type) 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,
- };
- }
-
- fn content(comptime self: @This()) []const u8 {
- return opening ++ @embedFile(self.file) ++ closing;
- }
-
- fn content_minified(comptime self: @This()) []const u8 {
- var minified: []const u8 = "";
- var iterator: Iterator = .init(@embedFile(self.file));
-
- while (iterator.next()) |segment| {
- minified = minified ++ segment;
- }
-
- return opening ++ minified ++ closing;
- }
-
- pub fn to_html_string(comptime self: @This()) []const u8 {
- return if (self.do_minify) self.content_minified() else self.content();
- }
- };
-}
-
-fn StringIterator(comptime quotes: []const u8) type {
- return struct {
- content: []const u8,
-
- pub fn init(content: []const u8) @This() {
- return .{ .content = content };
- }
-
- pub fn next(self: *@This()) ?[]const u8 {
- @setEvalBranchQuota(self.content.len * 20);
-
- self.content = std.mem.trimStart(u8, self.content, &std.ascii.whitespace);
-
- if (self.content.len == 0) return null;
-
- var index: usize = 0;
-
- while (self.content.len > index) {
- const char = self.content[index];
-
- if (std.mem.indexOfScalar(u8, quotes, char) != null) {
- index += 1;
- while (self.content.len > index) {
- if (self.content[index] == char) {
- index += 1;
- break;
- }
- index += 1;
- }
- } else if (std.ascii.isWhitespace(char)) {
- break;
- }
- index += 1;
- }
-
- const block = self.content[0..index];
- self.content = self.content[index..];
-
- return block ++ " ";
- }
- };
-}
-
-pub const Style = File("style", StringIterator("\"'"));
-pub const Script = File("script", StringIterator("\"'`"));
-pub const Html = File(null, StringIterator("\"'"));
diff --git a/src/frontend/Head.zig b/src/frontend/Head.zig
deleted file mode 100644
index 0eb090f..0000000
--- a/src/frontend/Head.zig
+++ /dev/null
@@ -1,58 +0,0 @@
-const File = @import("File.zig");
-const Component = @import("Component.zig");
-
-const z_component_code: File.Script = .minify("z-component.js");
-
-pub const Meta = struct {
- name: []const u8,
- content: []const u8,
-
- pub fn to_html_string(comptime self: @This()) []const u8 {
- return "<meta name=\"" ++ self.name ++ "\" content=\"" ++ self.content ++ "\">";
- }
-};
-
-title: []const u8,
-meta: []const Meta,
-
-pub const empty: @This() = .{
- .title = "",
- .meta = &.{},
-};
-
-pub fn default(comptime title: []const u8) @This() {
- return .{
- .title = title,
- .meta = &.{
- .{
- .name = "viewport",
- .content = "width=device-width, initial-scale=1.0",
- },
- },
- };
-}
-
-pub fn to_html_string(
- comptime self: @This(),
- comptime components: []const Component,
- comptime styles: []const File.Style,
-) []const u8 {
- var content: []const u8 = "<head>" ++ z_component_code.to_html_string();
-
- content = content ++ "<title>" ++ self.title ++ "</title>";
-
- inline for (components) |component| {
- content = content ++ comptime component.to_html_string();
- }
-
- inline for (styles) |style| {
- content = content ++ comptime style.to_html_string();
- }
-
- inline for (self.meta) |meta| {
- content = content ++ comptime meta.to_html_string();
- }
-
- content = content ++ "</head>";
- return content;
-}
diff --git a/src/frontend/root.zig b/src/frontend/root.zig
deleted file mode 100644
index 39908b5..0000000
--- a/src/frontend/root.zig
+++ /dev/null
@@ -1,12 +0,0 @@
-//! Implementation of the frontend contains mainly javascript files
-//! which will be embedded right into the ELF file to improve deployment.
-
-const std = @import("std");
-pub const Component = @import("Component.zig");
-pub const Document = @import("Document.zig");
-pub const File = @import("File.zig");
-pub const Head = @import("File.zig");
-
-test {
- _ = std.testing.refAllDecls(@This());
-}
diff --git a/src/frontend/web/hello-world/index.css b/src/frontend/web/hello-world/index.css
deleted file mode 100644
index 41b0b29..0000000
--- a/src/frontend/web/hello-world/index.css
+++ /dev/null
@@ -1,7 +0,0 @@
-#container {
- background: #efefef;
- padding: 10px;
- border-radius: 4px;
- user-select: none;
- cursor: pointer;
-}
diff --git a/src/frontend/web/hello-world/index.html b/src/frontend/web/hello-world/index.html
deleted file mode 100644
index a9b0be7..0000000
--- a/src/frontend/web/hello-world/index.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<div id="container" onclick="clicked()">
- Click Me!
-</div>
diff --git a/src/frontend/web/hello-world/index.js b/src/frontend/web/hello-world/index.js
deleted file mode 100644
index 8e55c52..0000000
--- a/src/frontend/web/hello-world/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-function clicked() {
- console.log('clicked');
-}
diff --git a/src/frontend/web/index.css b/src/frontend/web/index.css
deleted file mode 100644
index a93ea47..0000000
--- a/src/frontend/web/index.css
+++ /dev/null
@@ -1,4 +0,0 @@
-body {
- padding: 0;
- margin: 0;
-}
diff --git a/src/frontend/web/index.html b/src/frontend/web/index.html
deleted file mode 100644
index 885f2c5..0000000
--- a/src/frontend/web/index.html
+++ /dev/null
@@ -1 +0,0 @@
-<z-component type="hello-world"></z-component>
diff --git a/src/frontend/z-component.js b/src/frontend/z-component.js
deleted file mode 100644
index e9b63ff..0000000
--- a/src/frontend/z-component.js
+++ /dev/null
@@ -1,17 +0,0 @@
-customElements.define(
- "z-component",
- class extends HTMLElement {
- constructor() {
- super();
- this.attachShadow({ mode: 'open' })
- }
-
- connectedCallback() {
- const type = this.getAttribute('type');
- const template = document.getElementById(`--${type}`);
- const node = document.importNode(template.content, true);
- this.shadowRoot.id = 'root';
- this.shadowRoot.appendChild(node);
- }
- }
-);