use styled components and improve error handling

This commit is contained in:
tristan 2023-12-31 04:27:09 +00:00
parent 9d0d54c2e4
commit 29f79c67d8
10 changed files with 117 additions and 86 deletions

View file

@ -6,23 +6,23 @@ in
with elems; [
(it "makes a p tag" {
expected = html.tag "p" {} "foobar";
actual = p "foobar";
actual = p {} "foobar";
})
(it "makes a div tag" {
expected = html.tag "div" {} "foobar";
actual = div "foobar";
actual = div {} "foobar";
})
(it "makes a section tag" {
expected = html.tag "section" {} "foobar";
actual = section "foobar";
actual = section {} "foobar";
})
(it "makes a span tag" {
expected = html.tag "span" {} "foobar";
actual = span "foobar";
actual = span {} "foobar";
})
(it "makes a main tag" {
expected = html.tag "main" {} ["yeet"];
actual = main ["yeet"];
actual = main {} ["yeet"];
})
(it "makes an h1 tag" {
expected = html.tag "h1" {} "foobar";
@ -34,7 +34,7 @@ in
})
(it "makes a title tag" {
expected = html.tag "title" {} "foobar";
actual = title "foobar";
actual = title {} "foobar";
})
(it "makes an a tag" {
expected = html.tag "a" {href = "https://example.com";} "example";
@ -48,18 +48,21 @@ in
actual = stylesheet "/style";
})
(it "makes a list" {
expected = html.tag "ul" {} [
expected = toString (html.tag "ul" {} [
(html.tag "li" {} "foo")
(html.tag "li" {} "bar")
(html.tag "li" {} "baz")
];
actual = list ["foo" "bar" "baz"];
]);
actual = toString (list {} ["foo" "bar" "baz"]);
})
(it "makes an html doc" {
expected = html.tag "html" {lang = "en";} [
(html.tag "head" {} ["foo"])
(html.tag "body" {} "bar")
];
actual = doc ["foo"] "bar";
expected = toString (html.tag "html" {
__child = "";
lang = "en";
} [
(html.tag "head" {} ["foo"])
(html.tag "body" {} "bar")
]);
actual = toString (doc {} [["foo"] "bar"]);
})
]

View file

@ -10,7 +10,7 @@ in
(assert mdBlock "# heading 1" == elems.h 1 "heading 1"; "makes h1 tag")
(assert mdBlock "## subheading" == elems.h 2 "subheading"; "makes h2 tag")
(assert mdBlock "some paragraph" == elems.p "some paragraph"; "makes p tag")
(assert mdBlock "some paragraph" == elems.p {} "some paragraph"; "makes p tag")
(it "processes md block" {
actual = readMd ''
@ -21,7 +21,7 @@ in
expected = [
(elems.h 1 "foo bar")
""
(elems.p "lorem ipsum\n")
(elems.p {} "lorem ipsum\n")
];
})
]

View file

@ -1,4 +1,5 @@
let
html = import ../nixite/html.nix;
elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix;
it = import ./it.nix;
@ -6,9 +7,15 @@ in
with site; [
(it "applies a style" {
expected = {
"index.html" = with elems; (doc [(title "foobar") (stylesheet "/style.css")] [(main "something")]);
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar") (elems.stylesheet "/style.css")])
(elems.main {} "something")
];
blog = {
"index.html" = with elems; (doc [(title "foobar") (stylesheet "/style.css")] [(main "blogy blog")]);
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar") (elems.stylesheet "/style.css")])
(elems.main {} "blogy blog")
];
};
"style.css" = ''
this is a stylesheet
@ -18,9 +25,15 @@ in
applyStyle ''
this is a stylesheet
'' {
"index.html" = with elems; (doc [(title "foobar")] [(main "something")]);
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
blog = {
"index.html" = with elems; (doc [(title "foobar")] [(main "blogy blog")]);
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar")])
(elems.main {} "blogy blog")
];
};
};
})

View file

@ -24,15 +24,17 @@ let
})
(style.styled "list" "ul" {
__child = child:
assert builtins.isList child;
(map (html.tag "li" {}) child);
} {})
;
assert builtins.isList child; (map (html.tag "li" {}) child);
} {});
in [
(it "makes a p component" {
expected = html.tag "p" {} "yes";
actual = my.p {} "yes";
})
(it "does not error without attrs" {
expected = html.tag "p" {} "yes";
actual = my.p "yes";
})
(it "makes a component" {
expected = html.tag "div" {class = ["something"];} "foobar";
actual = my.div {} "foobar";
@ -53,7 +55,7 @@ in [
(html.tag "li" {} "1")
(html.tag "li" {} "2")
]);
actual = toString ( my.list {} ["1" "2"] );
actual = toString (my.list {} ["1" "2"]);
})
(it "combines attrs" {
expected = html.tag "div" {