2023-12-31 03:08:05 +00:00
|
|
|
let
|
|
|
|
style = import ../nixite/style.nix;
|
|
|
|
html = import ../nixite/html.nix;
|
|
|
|
it = import ./it.nix;
|
|
|
|
|
|
|
|
my =
|
2023-12-31 17:51:21 +00:00
|
|
|
(style.styled "p" "p" {style = {
|
2023-12-31 03:08:05 +00:00
|
|
|
some-style = "some value";
|
2023-12-31 17:51:21 +00:00
|
|
|
};})
|
|
|
|
(style.styled "div" "div" {class = ["something"]; style = {
|
2023-12-31 03:08:05 +00:00
|
|
|
this = "that";
|
2023-12-31 17:51:21 +00:00
|
|
|
};})
|
2023-12-31 03:08:41 +00:00
|
|
|
(style.styled "s" "div" {
|
|
|
|
id = "s";
|
|
|
|
class = ["something"];
|
2023-12-31 17:51:21 +00:00
|
|
|
style = {
|
|
|
|
s = "yes";
|
|
|
|
};})
|
|
|
|
(style.styled "foobar" "div" {
|
|
|
|
class = ["foo" "bar"];
|
|
|
|
style = {
|
|
|
|
something = "something";
|
|
|
|
};
|
|
|
|
} )
|
2023-12-31 03:08:05 +00:00
|
|
|
(style.style "body" {
|
|
|
|
foo = "bar";
|
2023-12-31 03:41:46 +00:00
|
|
|
})
|
|
|
|
(style.styled "list" "ul" {
|
|
|
|
__child = child:
|
2023-12-31 04:27:09 +00:00
|
|
|
assert builtins.isList child; (map (html.tag "li" {}) child);
|
2023-12-31 17:51:21 +00:00
|
|
|
});
|
2023-12-31 03:08:05 +00:00
|
|
|
in [
|
2023-12-31 03:08:41 +00:00
|
|
|
(it "makes a p component" {
|
2023-12-31 06:59:23 +00:00
|
|
|
expected = html.tag "p" {class = ["p"];} "yes";
|
2023-12-31 03:08:41 +00:00
|
|
|
actual = my.p {} "yes";
|
2023-12-31 17:51:21 +00:00
|
|
|
asString = true;
|
2023-12-31 03:08:41 +00:00
|
|
|
})
|
2023-12-31 04:27:09 +00:00
|
|
|
(it "does not error without attrs" {
|
2023-12-31 06:59:23 +00:00
|
|
|
expected = html.tag "p" {class = ["p"];} "yes";
|
2023-12-31 04:27:09 +00:00
|
|
|
actual = my.p "yes";
|
2023-12-31 17:51:21 +00:00
|
|
|
asString = true;
|
2023-12-31 04:27:09 +00:00
|
|
|
})
|
2023-12-31 03:08:41 +00:00
|
|
|
(it "makes a component" {
|
|
|
|
expected = html.tag "div" {class = ["something"];} "foobar";
|
|
|
|
actual = my.div {} "foobar";
|
2023-12-31 17:51:21 +00:00
|
|
|
asString = true;
|
2023-12-31 03:08:41 +00:00
|
|
|
})
|
|
|
|
(it "makes special components" {
|
|
|
|
expected = html.tag "div" {
|
|
|
|
id = "s";
|
|
|
|
class = ["something"];
|
|
|
|
} "foobar";
|
|
|
|
actual = my.s {} "foobar";
|
2023-12-31 17:51:21 +00:00
|
|
|
asString = true;
|
2023-12-31 03:08:41 +00:00
|
|
|
})
|
|
|
|
(it "works on many classes" {
|
|
|
|
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
|
|
|
|
actual = my.foobar {} "foobar";
|
2023-12-31 17:51:21 +00:00
|
|
|
asString = true;
|
2023-12-31 03:08:41 +00:00
|
|
|
})
|
2023-12-31 03:41:46 +00:00
|
|
|
(it "does custom behavour" {
|
2023-12-31 17:51:21 +00:00
|
|
|
expected = (html.tag "ul" {
|
2023-12-31 06:59:23 +00:00
|
|
|
__ = "";
|
|
|
|
class = ["list"];
|
|
|
|
} [
|
|
|
|
(html.tag "li" {} "1")
|
|
|
|
(html.tag "li" {} "2")
|
|
|
|
]);
|
2023-12-31 17:51:21 +00:00
|
|
|
actual = (my.list {} ["1" "2"]);
|
|
|
|
asString = true;
|
2023-12-31 03:41:46 +00:00
|
|
|
})
|
2023-12-31 03:08:41 +00:00
|
|
|
(it "combines attrs" {
|
|
|
|
expected = html.tag "div" {
|
|
|
|
id = "foo";
|
|
|
|
class = ["something"];
|
|
|
|
} "foobar";
|
|
|
|
actual = my.div {id = "foo";} "foobar";
|
2023-12-31 17:51:21 +00:00
|
|
|
asString = true;
|
2023-12-31 03:08:41 +00:00
|
|
|
})
|
|
|
|
(it "makes a style" {
|
|
|
|
expected = ''
|
2023-12-31 06:59:23 +00:00
|
|
|
p.p {
|
2023-12-31 03:08:41 +00:00
|
|
|
some-style: some value;
|
|
|
|
}
|
|
|
|
div.something {
|
|
|
|
this: that;
|
|
|
|
}
|
|
|
|
div.something#s {
|
|
|
|
s: yes;
|
|
|
|
}
|
|
|
|
div.foo.bar {
|
|
|
|
something: something;
|
|
|
|
}
|
|
|
|
body {
|
|
|
|
foo: bar;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
actual = my.style;
|
|
|
|
})
|
|
|
|
]
|