make tests pass
This commit is contained in:
parent
29f79c67d8
commit
77f70490df
|
@ -8,7 +8,7 @@ in
|
|||
(s.styled "span" "span" {} {})
|
||||
(s.styled "main" "main" {} {})
|
||||
(s.styled "article" "article" {} {})
|
||||
(s.styled "title" "title" {} {})
|
||||
(s.styled "title" "title" {class = [];} {})
|
||||
(s.styled "h1" "h1" {} {})
|
||||
(s.styled "h2" "h2" {} {})
|
||||
(s.styled "h3" "h3" {} {})
|
||||
|
@ -25,6 +25,7 @@ in
|
|||
(html.tag "body" {} (builtins.elemAt child 1))
|
||||
];
|
||||
lang = "en";
|
||||
class = [];
|
||||
} {})
|
||||
// {
|
||||
h = v: child:
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
rec {
|
||||
let
|
||||
keyvalue = key: value: ''${key}="${toString value}"'';
|
||||
in rec {
|
||||
toHTML = elem:
|
||||
if builtins.typeOf elem == "string"
|
||||
then elem
|
||||
|
@ -9,9 +11,11 @@ rec {
|
|||
writeAttrs = attrs:
|
||||
toString (builtins.attrValues (
|
||||
builtins.mapAttrs (key: value:
|
||||
if (builtins.substring 0 2 key) == "__"
|
||||
if (builtins.isPath value)
|
||||
then keyvalue key (baseNameOf value)
|
||||
else if (builtins.substring 0 2 key) == "__"
|
||||
then ""
|
||||
else ''${key}="${toString value}"'')
|
||||
else keyvalue key value)
|
||||
attrs
|
||||
));
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ in rec {
|
|||
''
|
||||
else if builtins.isPath content
|
||||
then ''
|
||||
cp ${content} ${prefix}/${name}
|
||||
cp -r ${content} ${prefix}/${name}
|
||||
''
|
||||
else if builtins.isAttrs content && content ? "__toString"
|
||||
then ''
|
||||
|
|
|
@ -22,8 +22,8 @@ let
|
|||
}
|
||||
'';
|
||||
|
||||
mkIdentifier = tag: {
|
||||
class ? [],
|
||||
mkIdentifier = name: tag: {
|
||||
class ? [name],
|
||||
id ? "",
|
||||
...
|
||||
}:
|
||||
|
@ -42,12 +42,12 @@ in {
|
|||
{
|
||||
${name} = props:
|
||||
if builtins.isAttrs props
|
||||
then (child: (html.tag tag (props // cprops) (custom child)))
|
||||
then (child: (html.tag tag (props // {class = [name];} // cprops) (custom child)))
|
||||
else if builtins.isString props || builtins.isList props
|
||||
then (html.tag tag cprops (custom props))
|
||||
then (html.tag tag ({class = [name];} // cprops) (custom props))
|
||||
else throw "Call element with attributes and child.";
|
||||
|
||||
style = mkStyle (mkIdentifier tag cprops) styles;
|
||||
style = mkStyle (mkIdentifier name tag cprops) styles;
|
||||
}
|
||||
// join;
|
||||
|
||||
|
|
|
@ -5,23 +5,23 @@ let
|
|||
in
|
||||
with elems; [
|
||||
(it "makes a p tag" {
|
||||
expected = html.tag "p" {} "foobar";
|
||||
expected = html.tag "p" {class = ["p"];} "foobar";
|
||||
actual = p {} "foobar";
|
||||
})
|
||||
(it "makes a div tag" {
|
||||
expected = html.tag "div" {} "foobar";
|
||||
expected = html.tag "div" {class = ["div"];} "foobar";
|
||||
actual = div {} "foobar";
|
||||
})
|
||||
(it "makes a section tag" {
|
||||
expected = html.tag "section" {} "foobar";
|
||||
expected = html.tag "section" {class = ["section"];} "foobar";
|
||||
actual = section {} "foobar";
|
||||
})
|
||||
(it "makes a span tag" {
|
||||
expected = html.tag "span" {} "foobar";
|
||||
expected = html.tag "span" {class = ["span"];} "foobar";
|
||||
actual = span {} "foobar";
|
||||
})
|
||||
(it "makes a main tag" {
|
||||
expected = html.tag "main" {} ["yeet"];
|
||||
expected = html.tag "main" {class = ["main"];} ["yeet"];
|
||||
actual = main {} ["yeet"];
|
||||
})
|
||||
(it "makes an h1 tag" {
|
||||
|
@ -33,7 +33,7 @@ in
|
|||
actual = h 2 "foobar";
|
||||
})
|
||||
(it "makes a title tag" {
|
||||
expected = html.tag "title" {} "foobar";
|
||||
expected = html.tag "title" {class = [];} "foobar";
|
||||
actual = title {} "foobar";
|
||||
})
|
||||
(it "makes an a tag" {
|
||||
|
@ -48,16 +48,20 @@ in
|
|||
actual = stylesheet "/style";
|
||||
})
|
||||
(it "makes a list" {
|
||||
expected = toString (html.tag "ul" {} [
|
||||
(html.tag "li" {} "foo")
|
||||
(html.tag "li" {} "bar")
|
||||
(html.tag "li" {} "baz")
|
||||
]);
|
||||
expected = toString (html.tag "ul" {
|
||||
__ = "";
|
||||
class = ["list"];
|
||||
} [
|
||||
(html.tag "li" {} "foo")
|
||||
(html.tag "li" {} "bar")
|
||||
(html.tag "li" {} "baz")
|
||||
]);
|
||||
actual = toString (list {} ["foo" "bar" "baz"]);
|
||||
})
|
||||
(it "makes an html doc" {
|
||||
expected = toString (html.tag "html" {
|
||||
__child = "";
|
||||
class = [];
|
||||
lang = "en";
|
||||
} [
|
||||
(html.tag "head" {} ["foo"])
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
path:
|
||||
toString (map (v: ''
|
||||
echo '${builtins.baseNameOf path} :: ${v}'
|
||||
'')
|
||||
(import path))
|
||||
''
|
||||
echo
|
||||
echo 'TEST: ${builtins.baseNameOf path}'
|
||||
echo
|
||||
''
|
||||
+ builtins.concatStringsSep "\n" (import path)
|
||||
|
|
|
@ -3,9 +3,11 @@ msg: {
|
|||
expected,
|
||||
}:
|
||||
if actual == expected
|
||||
then msg
|
||||
else
|
||||
throw
|
||||
(builtins.toJSON {
|
||||
inherit actual expected msg;
|
||||
})
|
||||
then ''
|
||||
echo 'it ${msg}'
|
||||
''
|
||||
else ''
|
||||
echo 'FAILED: ${msg}'
|
||||
echo '${builtins.toJSON expected}'
|
||||
echo '${builtins.toJSON actual}'
|
||||
''
|
||||
|
|
|
@ -4,13 +4,13 @@ let
|
|||
it = import ./it.nix;
|
||||
in
|
||||
with md; [
|
||||
(assert heading "# heading 1" == ["#" "heading 1"]; "gets heading 1")
|
||||
(assert heading "## subheading" == ["##" "subheading"]; "gets heading 2")
|
||||
(assert heading "some paragraph" == null; "paragraph is heading 0")
|
||||
(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"; "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 "# 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 ''
|
||||
|
|
|
@ -28,11 +28,11 @@ let
|
|||
} {});
|
||||
in [
|
||||
(it "makes a p component" {
|
||||
expected = html.tag "p" {} "yes";
|
||||
expected = html.tag "p" {class = ["p"];} "yes";
|
||||
actual = my.p {} "yes";
|
||||
})
|
||||
(it "does not error without attrs" {
|
||||
expected = html.tag "p" {} "yes";
|
||||
expected = html.tag "p" {class = ["p"];} "yes";
|
||||
actual = my.p "yes";
|
||||
})
|
||||
(it "makes a component" {
|
||||
|
@ -51,10 +51,13 @@ in [
|
|||
actual = my.foobar {} "foobar";
|
||||
})
|
||||
(it "does custom behavour" {
|
||||
expected = toString (html.tag "ul" {} [
|
||||
(html.tag "li" {} "1")
|
||||
(html.tag "li" {} "2")
|
||||
]);
|
||||
expected = toString (html.tag "ul" {
|
||||
__ = "";
|
||||
class = ["list"];
|
||||
} [
|
||||
(html.tag "li" {} "1")
|
||||
(html.tag "li" {} "2")
|
||||
]);
|
||||
actual = toString (my.list {} ["1" "2"]);
|
||||
})
|
||||
(it "combines attrs" {
|
||||
|
@ -66,7 +69,7 @@ in [
|
|||
})
|
||||
(it "makes a style" {
|
||||
expected = ''
|
||||
p {
|
||||
p.p {
|
||||
some-style: some value;
|
||||
}
|
||||
div.something {
|
||||
|
|
Loading…
Reference in a new issue