reusable, extendable tags
This commit is contained in:
parent
8e97ebe2ce
commit
e76305f71a
9 changed files with 85 additions and 76 deletions
|
@ -9,7 +9,7 @@ in with html; [
|
|||
expected = "p";
|
||||
}))
|
||||
|
||||
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
|
||||
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
|
||||
in {
|
||||
actual = p.attrs;
|
||||
expected = { class = ""; };
|
||||
|
@ -81,6 +81,12 @@ in with html; [
|
|||
expected = ''<p class="foobar"></p>'';
|
||||
}))
|
||||
|
||||
(it "can take many sets of props" (let p = tag "p";
|
||||
in {
|
||||
actual = toString (p { class = "foobar"; } { style = "a style"; });
|
||||
expected = ''<p class="foobar" style="a style"></p>'';
|
||||
}))
|
||||
|
||||
(it "works recursively" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
path:
|
||||
builtins.trace ( "testing " + builtins.baseNameOf path )
|
||||
''
|
||||
echo
|
||||
echo 'TEST: ${builtins.baseNameOf path}'
|
||||
|
|
|
@ -4,7 +4,7 @@ msg:
|
|||
let
|
||||
preProcess = v:
|
||||
if removeDunders then
|
||||
builtins.removeAttrs v [ "__toString" "__functor" ]
|
||||
undunder v
|
||||
else if asString then
|
||||
toString v
|
||||
else if asJSON then
|
||||
|
@ -15,11 +15,14 @@ let
|
|||
a = preProcess actual;
|
||||
e = preProcess expected;
|
||||
|
||||
undunder = v: if builtins.isAttrs v then builtins.removeAttrs v [ "__toString" "__functor" ] else v;
|
||||
|
||||
out = (if safeToPrint then builtins.toJSON (undunder actual) else ''{"msg": "refusing to print"}'');
|
||||
|
||||
in if (a == e) then ''
|
||||
echo 'it ${msg}'
|
||||
'' else
|
||||
builtins.trace "FAILED ${msg}" builtins.trace
|
||||
(if safeToPrint then builtins.toJSON actual else actual) builtins.trace
|
||||
(if safeToPrint then builtins.toJSON expected else expected) ''
|
||||
builtins.trace "FAILED ${msg}" ''
|
||||
echo FAILED ${msg}
|
||||
echo '${out}' | jq '.'
|
||||
''
|
||||
|
|
|
@ -85,13 +85,13 @@ in with site; [
|
|||
})
|
||||
|
||||
(it "gets all styles" {
|
||||
expected = {
|
||||
expected = {"p"={};"div"={};
|
||||
"p.class" = { color = "blue"; };
|
||||
"a.class2" = { color = "green"; };
|
||||
"div.class2" = { color = "green"; };
|
||||
};
|
||||
actual = getStyles (let
|
||||
p = style.tag "p" "class" { style = { color = "blue"; }; };
|
||||
g = style.tag "a" "class2" { style = { color = "green"; }; };
|
||||
p = style.component elems.p "class" { style = { color = "blue"; }; };
|
||||
g = style.component elems.div "class2" { style = { color = "green"; }; };
|
||||
in {
|
||||
"index.html" = p "";
|
||||
blog = { "index.html" = g ""; };
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
let
|
||||
style = import ../nixite/style.nix;
|
||||
elems = import ../nixite/elems.nix;
|
||||
it = import ./it.nix;
|
||||
|
||||
in [
|
||||
|
||||
(it "fetches empty style" (let para = (style.tag "p" "para" { });
|
||||
(it "fetches empty style" (let para = (style.component elems.p "para" { });
|
||||
in {
|
||||
expected = { "p.para" = { }; };
|
||||
expected = { "p" = {}; "p.para" = { }; };
|
||||
actual = style.getStyle (para "");
|
||||
}))
|
||||
|
||||
(it "fetches style" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (style.tag "p" "para" attrs);
|
||||
para = (style.component elems.p "para" attrs);
|
||||
in {
|
||||
expected = { "p.para" = attrs.style; };
|
||||
expected = {"p" = {}; "p.para" = attrs.style; };
|
||||
actual = style.getStyle (para "");
|
||||
}))
|
||||
|
||||
(it "appliess class" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (style.tag "p" "para" attrs);
|
||||
para = (style.component elems.p "para" attrs);
|
||||
in {
|
||||
expected = [ "para" ];
|
||||
actual = (para "").attrs.class;
|
||||
|
@ -31,7 +32,7 @@ in [
|
|||
style = { foo = "bar"; };
|
||||
class = [ "other" "class" ];
|
||||
};
|
||||
para = (style.tag "p" "para" attrs);
|
||||
para = (style.component elems.p "para" attrs);
|
||||
in {
|
||||
expected = [ "para" "other" "class" ];
|
||||
actual = (para "").attrs.class;
|
||||
|
@ -39,32 +40,32 @@ in [
|
|||
|
||||
(it "fetches style for class" (let
|
||||
s = { foo = "bar"; };
|
||||
para = (style.tag "p" "para" { style = s; });
|
||||
para = (style.component elems.p "para" { style = s; });
|
||||
in {
|
||||
expected = { "p.para" = s; };
|
||||
expected = { "p" = {}; "p.para" = s; };
|
||||
actual = style.getStyle (para "");
|
||||
}))
|
||||
|
||||
(it "fetches style recursively" (let
|
||||
s = {
|
||||
s = {"p" = {};"div" = {};
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
"div.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
a = (style.tag "a" "link" { style = s."a.link"; });
|
||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
||||
div = (style.component elems.div "link" { style = s."div.link"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para (a "hello"));
|
||||
actual = style.getStyles (para (div "hello"));
|
||||
removeDunders = true;
|
||||
}))
|
||||
|
||||
(it "fetches style recursively through lists" (let
|
||||
s = {
|
||||
s = {"p" = {};"div" = {};
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
"div.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
a = (style.tag "a" "link" { style = s."a.link"; });
|
||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
||||
a = (style.component elems.div "link" { style = s."div.link"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para [ (a "hello") ]);
|
||||
|
@ -72,12 +73,12 @@ in [
|
|||
}))
|
||||
|
||||
(it "fetches style recursively with repeats" (let
|
||||
s = {
|
||||
s = {"p" = {};"div" = {};
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
"div.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
a = (style.tag "a" "link" { style = s."a.link"; });
|
||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
||||
a = (style.component elems.div "link" { style = s."div.link"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para [ (a "hello") (a "hello") ]);
|
||||
|
@ -85,7 +86,7 @@ in [
|
|||
}))
|
||||
|
||||
(it "converts styles to string" (let
|
||||
s = {
|
||||
s = {"p" = {};
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
|
@ -104,10 +105,10 @@ in [
|
|||
(it "extends styled tags" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"p.para.oof" = { oof = "yes"; };
|
||||
"p.oof" = { oof = "yes"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
para2 = (style.extend para "oof" { style = s."p.para.oof"; });
|
||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
||||
para2 = (style.component para "oof" { style = s."p.oof"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para2 "");
|
||||
|
@ -115,12 +116,12 @@ in [
|
|||
}))
|
||||
|
||||
(it "extends styled tags classes" (let
|
||||
s = {
|
||||
s = {"p" = {}; "div" = {};
|
||||
"p.para" = { foo = "bar"; };
|
||||
"p.para.oof" = { oof = "yes"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
para2 = (style.extend para "oof" { style = s."p.para.oof"; });
|
||||
para = (style.component elems.p "para" { style = s."p.para"; });
|
||||
para2 = (style.component para "oof" { style = s."p.para.oof"; });
|
||||
in {
|
||||
expected = [ "para" "oof" ];
|
||||
actual = (para2 "").attrs.class;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue