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