component extending, add all html elems

also use nixfmt
This commit is contained in:
tristan 2023-12-31 21:33:42 +00:00
parent ccc6b53b91
commit cb6d9652f8
15 changed files with 548 additions and 604 deletions

View file

@ -2,83 +2,82 @@ let
elems = import ../nixite/elems.nix;
html = import ../nixite/html.nix;
it = import ./it.nix;
in
with elems; [
(it "makes a p tag" {
expected = html.tag "p" {class = ["p"];} "foobar";
actual = p {} "foobar";
asString = true;
})
(it "makes a div tag" {
expected = html.tag "div" {class = ["div"];} "foobar";
actual = div {} "foobar";
asString = true;
})
(it "makes a section tag" {
expected = html.tag "section" {class = ["section"];} "foobar";
actual = section {} "foobar";
asString = true;
})
(it "makes a span tag" {
expected = html.tag "span" {class = ["span"];} "foobar";
actual = span {} "foobar";
asString = true;
})
(it "makes a main tag" {
expected = html.tag "main" {class = ["main"];} ["yeet"];
actual = main {} ["yeet"];
asString = true;
})
(it "makes an h1 tag" {
expected = html.tag "h1" {} "foobar";
actual = h 1 "foobar";
asString = true;
})
(it "makes an h2 tag" {
expected = html.tag "h2" {} "foobar";
actual = h 2 "foobar";
asString = true;
})
(it "makes a title tag" {
expected = html.tag "title" {class = [];} "foobar";
actual = title {} "foobar";
asString = true;
})
(it "makes an a tag" {
expected = html.tag "a" {class = ["link"]; href = "https://example.com";} "example";
actual = link "https://example.com" "example";
asString = true;
})
(it "makes a stylesheet link" {
expected = html.tag "link" {
href = "/style";
rel = "stylesheet";
} "";
actual = stylesheet {href = "/style"; };
asString = true;
})
(it "makes a list" {
expected = (html.tag "ul" {
__ = "";
class = ["list"];
} [
(html.tag "li" {} "foo")
(html.tag "li" {} "bar")
(html.tag "li" {} "baz")
]);
actual = (list {} ["foo" "bar" "baz"]);
asString = true;
})
(it "makes an html doc" {
expected = (html.tag "html" {
__child = "";
class = [];
lang = "en";
} [
(html.tag "head" {} ["foo"])
(html.tag "body" {} "bar")
]);
actual = (doc {} [["foo"] "bar"]);
asString = true;
})
]
in with elems; [
(it "makes a p tag" {
expected = html.tag "p" { } "foobar";
actual = p { } "foobar";
asString = true;
})
(it "makes a div tag" {
expected = html.tag "div" { } "foobar";
actual = div { } "foobar";
asString = true;
})
(it "makes a section tag" {
expected = html.tag "section" { } "foobar";
actual = section { } "foobar";
asString = true;
})
(it "makes a span tag" {
expected = html.tag "span" { } "foobar";
actual = span { } "foobar";
asString = true;
})
(it "makes a main tag" {
expected = html.tag "main" { } [ "yeet" ];
actual = main { } [ "yeet" ];
asString = true;
})
(it "makes an h1 tag" {
expected = html.tag "h1" { } "foobar";
actual = H 1 "foobar";
asString = true;
})
(it "makes an h2 tag" {
expected = html.tag "h2" { } "foobar";
actual = H 2 "foobar";
asString = true;
})
(it "makes a title tag" {
expected = html.tag "title" { } "foobar";
actual = title { } "foobar";
asString = true;
})
(it "makes an a tag" {
expected = html.tag "a" {
class = [ "a" ];
href = "https://example.com";
} "example";
actual = a "https://example.com" "example";
asString = true;
})
(it "makes a stylesheet link" {
expected = html.tag "link" {
href = "/style";
rel = "stylesheet";
} "";
actual = Stylesheet { href = "/style"; };
asString = true;
})
(it "makes a list" {
expected = html.tag "ul" {
__ = "";
class = [ "List" ];
} [
(html.tag "li" { } "foo")
(html.tag "li" { } "bar")
(html.tag "li" { } "baz")
];
actual = List { } [ "foo" "bar" "baz" ];
asString = true;
})
(it "makes an html doc" {
expected = html.tag "html" {
__child = "";
class = [ ];
lang = "en";
} [ (html.tag "head" { } [ "foo" ]) (html.tag "body" { } "bar") ];
actual = Doc { } [ [ "foo" ] "bar" ];
asString = true;
})
]

View file

@ -1,32 +1,30 @@
let
html = import ../nixite/html.nix;
it = import ./it.nix;
in
with html; [
(it "makes a p tag" {
actual = tag "p" {} "Hello";
expected = {
tag = "p";
attrs = {};
child = "Hello";
__toString = toHTML;
};
})
in with html; [
(it "makes a p tag" {
actual = tag "p" { } "Hello";
expected = {
tag = "p";
attrs = { };
child = "Hello";
__toString = toHTML;
};
})
(it "concatinates classes" {
actual = toString (tag "p" {class = ["class1" "class2"];} "Hello");
expected = ''<p class="class1 class2">Hello</p>'';
})
(it "concatinates classes" {
actual = toString (tag "p" { class = [ "class1" "class2" ]; } "Hello");
expected = ''<p class="class1 class2">Hello</p>'';
})
(it "applies style" (let
page = tag "html" {} [(tag "head" {} ["foo"])];
in {
actual = addToHead page ["bar"];
expected = {
tag = "html";
attrs = {};
child = [(tag "head" {} ["foo" "bar"])];
__toString = toHTML;
};
}))
]
(it "applies style" (let page = tag "html" { } [ (tag "head" { } [ "foo" ]) ];
in {
actual = addToHead page [ "bar" ];
expected = {
tag = "html";
attrs = { };
child = [ (tag "head" { } [ "foo" "bar" ]) ];
__toString = toHTML;
};
}))
]

View file

@ -3,5 +3,4 @@ path:
echo
echo 'TEST: ${builtins.baseNameOf path}'
echo
''
+ builtins.concatStringsSep "\n" (import path)
'' + builtins.concatStringsSep "\n" (import path)

View file

@ -1,16 +1,14 @@
msg: {
actual,
expected,
asString ? false,
}:
if (
if asString then toString actual == toString expected
else actual == expected )
then ''
echo 'it ${msg}'
''
else ''
echo 'FAILED: ${msg}'
echo '${builtins.toJSON expected}'
echo '${builtins.toJSON actual}'
''
msg:
{ actual, expected, asString ? false, asJSON ? false, }:
if (if asString then
toString actual == toString expected
else if asJSON then
builtins.toJSON actual == builtins.toJSON expected
else
actual == expected) then ''
echo 'it ${msg}'
'' else ''
echo 'FAILED: ${msg}'
echo '${builtins.toJSON expected}'
echo '${builtins.toJSON actual}'
''

View file

@ -2,66 +2,62 @@ let
md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix;
it = import ./it.nix;
in
with md; [
(assert heading "# heading 1" == ["#" "heading 1"]; "echo gets heading 1")
(assert heading "## subheading" == ["##" "subheading"]; "echo gets heading 2")
(assert heading "some paragraph" == null; "echo paragraph is heading 0")
in with md; [
(assert heading "# heading 1" == [ "#" "heading 1" ]; "echo gets heading 1")
(assert heading "## subheading" == [ "##" "subheading" ];
"echo gets heading 2")
(assert heading "some paragraph" == null; "echo paragraph is heading 0")
(assert mdBlock "# heading 1" == elems.h 1 "heading 1"; "echo makes h1 tag")
(assert mdBlock "## subheading" == elems.h 2 "subheading"; "echo makes h2 tag")
(assert mdBlock "some paragraph" == elems.p {} "some paragraph"; "echo makes p tag")
#(assert mdBlock "# heading 1" == elems.h 1 "heading 1"; "echo makes h1 tag")
#(assert mdBlock "## subheading" == elems.h 2 "subheading"; "echo makes h2 tag")
#(assert mdBlock "some paragraph" == elems.p {} "some paragraph"; "echo makes p tag")
(it "processes md block" {
actual = readMd ''
# foo bar
(it "processes md block" {
actual = readMd ''
# foo bar
lorem ipsum
'';
expected = [
(elems.H 1 "foo bar")
""
(elems.p { } ''
lorem ipsum
'';
expected = [
(elems.h 1 "foo bar")
""
(elems.p {} "lorem ipsum\n")
];
})
'')
];
asString = true;
})
(it "can fix file appendixes" {
actual = fixAppendix "index.md";
expected = "index.html";
})
(it "can fix file appendixes" {
actual = fixAppendix "index.md";
expected = "index.html";
})
(it "recursively reads dir" {
actual = recReadMd ./blog;
expected = {
"index.md" = mdToPage ./blog/index.md;
"dir" = {
"index.md" = mdToPage ./blog/dir/index.md;
};
};
})
(it "recursively reads dir" {
actual = recReadMd ./blog;
expected = {
"index.md" = mdToPage ./blog/index.md;
"dir" = { "index.md" = mdToPage ./blog/dir/index.md; };
};
asJSON = true;
})
(it "recursively fixes filename" {
actual = recFixAppendix {
"index.md" = "something";
dir = {
"index.md" = "something else";
};
};
expected = {
"index.html" = "something";
dir = {
"index.html" = "something else";
};
};
})
(it "recursively fixes filename" {
actual = recFixAppendix {
"index.md" = "something";
dir = { "index.md" = "something else"; };
};
expected = {
"index.html" = "something";
dir = { "index.html" = "something else"; };
};
})
(it "recursively translates md to html" {
actual = builtins.toJSON ( readDir ./blog );
expected = builtins.toJSON {
"index.html" = mdToPage ./blog/index.md;
"dir" = {
"index.html" = mdToPage ./blog/dir/index.md;
};
};
})
]
(it "recursively translates md to html" {
actual = builtins.toJSON (readDir ./blog);
expected = builtins.toJSON {
"index.html" = mdToPage ./blog/index.md;
"dir" = { "index.html" = mdToPage ./blog/dir/index.md; };
};
})
]

View file

@ -3,104 +3,89 @@ let
elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix;
it = import ./it.nix;
in
with site; [
(it "applies a style" {
expected = {
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar") (elems.stylesheet "/style.css")])
(elems.main {} "something")
];
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
'';
};
actual =
applyStyle ''
this is a stylesheet
'' {
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
blog = {
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar")])
(elems.main {} "blogy blog")
];
};
};
})
(it "extracts top level paths" {
actual = getPaths {
something = "";
src = ./src/index.md;
};
expected = {
"index.md" = ./src/index.md;
};
})
(it "extracts lower level paths" {
actual = getPaths {
something = "yes";
a-list = [
{thingy = ./src/index.md;}
[(html.tag "img" {src = ./src/favicon.png;} "")]
in with site; [
(it "applies a style" {
expected = {
"index.html" = html.tag "html" { } [
(html.tag "head" { } [
(elems.title { } "foobar")
(elems.Stylesheet "/style.css")
])
(elems.main { } "something")
];
blog = {
"index.html" = html.tag "html" { } [
(html.tag "head" { } [
(elems.title { } "foobar")
(elems.Stylesheet "/style.css")
])
(elems.main { } "blogy blog")
];
};
expected = {
"index.md" = ./src/index.md;
"favicon.png" = ./src/favicon.png;
};
})
(it "switches paths" {
actual = switchPaths {
something = "";
a-thing = {
src = ./src/index.md;
};
a-list = [
{thingy = ./src/index.md;}
"style.css" = ''
this is a stylesheet
'';
};
actual = applyStyle ''
this is a stylesheet
'' {
"index.html" = html.tag "html" { } [
(html.tag "head" { } [ (elems.title { } "foobar") ])
(elems.main { } "something")
];
blog = {
"index.html" = html.tag "html" { } [
(html.tag "head" { } [ (elems.title { } "foobar") ])
(elems.main { } "blogy blog")
];
};
expected = {
something = "";
a-thing = {
src = "/static/index.md";
};
a-list = [
{thingy = "/static/index.md";}
];
};
})
};
asJSON = true;
})
(it "extracts top level paths" {
actual = getPaths {
something = "";
src = ./src/index.md;
};
expected = { "index.md" = ./src/index.md; };
})
(it "extracts lower level paths" {
actual = getPaths {
something = "yes";
a-list = [
{ thingy = ./src/index.md; }
[ (html.tag "img" { src = ./src/favicon.png; } "") ]
];
};
expected = {
"index.md" = ./src/index.md;
"favicon.png" = ./src/favicon.png;
};
})
(it "switches paths" {
actual = switchPaths {
something = "";
a-thing = { src = ./src/index.md; };
a-list = [{ thingy = ./src/index.md; }];
};
expected = {
something = "";
a-thing = { src = "/static/index.md"; };
a-list = [{ thingy = "/static/index.md"; }];
};
})
(it "extracts paths" {
actual = extractPaths {
something = "";
a-thing = {
src = ./src/index.md;
};
a-list = [
{thingy = ./src/index.md;}
];
};
expected = {
something = "";
a-thing = {
src = "/static/index.md";
};
a-list = [
{thingy = "/static/index.md";}
];
static = {
"index.md" = ./src/index.md;
};
};
})
]
(it "extracts paths" {
actual = extractPaths {
something = "";
a-thing = { src = ./src/index.md; };
a-list = [{ thingy = ./src/index.md; }];
};
expected = {
something = "";
a-thing = { src = "/static/index.md"; };
a-list = [{ thingy = "/static/index.md"; }];
static = { "index.md" = ./src/index.md; };
};
})
]

View file

@ -3,78 +3,89 @@ let
html = import ../nixite/html.nix;
it = import ./it.nix;
my =
(style.styled "p" "p" {style = {
some-style = "some value";
};})
(style.styled "div" "div" {class = ["something"]; style = {
this = "that";
};})
(style.styled "s" "div" {
id = "s";
class = ["something"];
style = {
s = "yes";
};})
(style.styled "foobar" "div" {
class = ["foo" "bar"];
style = {
something = "something";
};
} )
(style.style "body" {
foo = "bar";
})
(style.styled "list" "ul" {
p = style.styled "generic" "p" {
foo = "bar";
forgetme = "nothing";
};
my = (style.styled "p" "p" { style = { some-style = "some value"; }; })
(style.styled "classless" "div" { class = [ ]; })
(style.styled "quote" p.generic {
baz = "baz";
forgetme = "forgotten";
}) (style.styled "div" "div" {
class = [ "something" ];
style = { this = "that"; };
}) (style.styled "s" "div" {
id = "s";
class = [ "something" ];
style = { s = "yes"; };
}) (style.styled "foobar" "div" {
class = [ "foo" "bar" ];
style = { something = "something"; };
}) (style.style "body" { foo = "bar"; }) (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 "extends existing components" {
expected = html.tag "p" {
forgetme = "forgotten";
baz = "baz";
foo = "bar";
class = [ "generic" "quote" ];
} "yes";
actual = my.quote { } "yes";
asString = true;
})
(it "makes a p component" {
expected = html.tag "p" {class = ["p"];} "yes";
actual = my.p {} "yes";
expected = html.tag "p" { class = [ "p" ]; } "yes";
actual = my.p { } "yes";
asString = true;
})
(it "makes a component with no class" {
expected = html.tag "div" { class = [ ]; } "yes";
actual = my.classless { } "yes";
asString = true;
})
(it "does not error without attrs" {
expected = html.tag "p" {class = ["p"];} "yes";
expected = html.tag "p" { class = [ "p" ]; } "yes";
actual = my.p "yes";
asString = true;
})
(it "makes a component" {
expected = html.tag "div" {class = ["something"];} "foobar";
actual = my.div {} "foobar";
expected = html.tag "div" { class = [ "div" "something" ]; } "foobar";
actual = my.div { } "foobar";
asString = true;
})
(it "makes special components" {
expected = html.tag "div" {
id = "s";
class = ["something"];
class = [ "s" "something" ];
} "foobar";
actual = my.s {} "foobar";
actual = my.s { } "foobar";
asString = true;
})
(it "works on many classes" {
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
actual = my.foobar {} "foobar";
expected = html.tag "div" { class = [ "foobar" "foo" "bar" ]; } "foobar";
actual = my.foobar { } "foobar";
asString = true;
})
(it "does custom behavour" {
expected = (html.tag "ul" {
__ = "";
class = ["list"];
} [
(html.tag "li" {} "1")
(html.tag "li" {} "2")
]);
actual = (my.list {} ["1" "2"]);
expected = html.tag "ul" {
__ = "";
class = [ "list" ];
} [ (html.tag "li" { } "1") (html.tag "li" { } "2") ];
actual = my.list { } [ "1" "2" ];
asString = true;
})
(it "combines attrs" {
expected = html.tag "div" {
id = "foo";
class = ["something"];
class = [ "div" "something" ];
} "foobar";
actual = my.div {id = "foo";} "foobar";
actual = my.div { id = "foo"; } "foobar";
asString = true;
})
(it "makes a style" {