update tix and add html document

This commit is contained in:
tristan 2024-01-03 13:19:41 +00:00
parent baa5b6854e
commit 93799cac12
9 changed files with 759 additions and 699 deletions

View file

@ -37,11 +37,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1704267472, "lastModified": 1704284214,
"narHash": "sha256-2QfrGFhkXEXRFVL6Lp14rOxNOH17fnZlY/NEqXUp26s=", "narHash": "sha256-YOKyHDSf6XUYJgdy8CrTGN+kPk9JGePksGENxn/gXPI=",
"ref": "refs/heads/master", "ref": "refs/heads/master",
"rev": "6f4955581b37d2ae079941104df486fd390abd95", "rev": "cc834eda99ecaff5466bc826ac5b99f36b69c537",
"revCount": 15, "revCount": 19,
"type": "git", "type": "git",
"url": "https://git.tristans.cloud/tristan/tix" "url": "https://git.tristans.cloud/tristan/tix"
}, },

View file

@ -14,6 +14,7 @@
in in
nixite nixite
// { // {
formatter.${system} = pkgs.alejandra;
packages.${system} = { packages.${system} = {
raw = nixite.mkSite (let raw = nixite.mkSite (let
readme = { readme = {
@ -60,6 +61,10 @@
./testing/style.test.nix ./testing/style.test.nix
]; ];
watch = tix.packages.${system}.watch;
watchpipe = tix.packages.${system}.watchpipe;
results = tix.packages.${system}.results;
dev = tix.watch { dev = tix.watch {
cmd = "nix run .# --show-trace"; cmd = "nix run .# --show-trace";
stop = "pkill caddy"; stop = "pkill caddy";

View file

@ -64,15 +64,24 @@ in rec {
|| builtins.isList tag || builtins.isList tag
|| (tag ? __toString && builtins.isFunction tag.__toString)); || (tag ? __toString && builtins.isFunction tag.__toString));
addToHead = page: heads: addToHead = doc: heads:
page doc
// { // {
child = head = doc.head ++ heads;
map
(e:
if e.tag == "head"
then e // {child = e.child ++ heads;}
else e)
page.child;
}; };
document = {
head ? [],
body ? [],
attrs ? {},
}: {
inherit head body attrs;
__toString = self: ''
<!DOCTYPE html>
${(tag "html" [
(tag "head" self.head)
(tag "body" self.body)
])}
'';
};
} }

View file

@ -27,11 +27,11 @@ in rec {
then flatten page then flatten page
else page) (builtins.attrValues site); else page) (builtins.attrValues site);
applyStyle = style: site: ((linkStyle site) // {"style.css" = style;}); applyStyle = style: site: ((linkStyle "/style.css" site) // {"style.css" = style;});
linkStyle = site: linkStyle = path: site:
eachPage site eachPage site
(content: html.addToHead content [(elems.Stylesheet "/style.css")]); (content: html.addToHead content [(elems.Stylesheet path)]);
eachPage = site: callback: (builtins.mapAttrs (name: content: eachPage = site: callback: (builtins.mapAttrs (name: content:
if builtins.isAttrs content && content ? "__toString" if builtins.isAttrs content && content ? "__toString"

View file

@ -6,86 +6,89 @@
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
html = import ../nixite/html.nix; html = import ../nixite/html.nix;
in in
with elems; with elems; [
describe "html tag" [ (
(it "makes a p tag" { describe "html tag" [
expected = html.tag "p" {} "foobar"; (it "makes a p tag" {
actual = p {} "foobar"; expected = html.tag "p" {} "foobar";
asString = true; actual = p {} "foobar";
}) asString = true;
(it "makes a div tag" { })
expected = html.tag "div" {} "foobar"; (it "makes a div tag" {
actual = div {} "foobar"; expected = html.tag "div" {} "foobar";
asString = true; actual = div {} "foobar";
}) asString = true;
(it "makes a section tag" { })
expected = html.tag "section" {} "foobar"; (it "makes a section tag" {
actual = section {} "foobar"; expected = html.tag "section" {} "foobar";
asString = true; actual = section {} "foobar";
}) asString = true;
(it "makes a span tag" { })
expected = html.tag "span" {} "foobar"; (it "makes a span tag" {
actual = span {} "foobar"; expected = html.tag "span" {} "foobar";
asString = true; actual = span {} "foobar";
}) asString = true;
(it "makes a main tag" { })
expected = html.tag "main" {} ["yeet"]; (it "makes a main tag" {
actual = main {} ["yeet"]; expected = html.tag "main" {} ["yeet"];
asString = true; actual = main {} ["yeet"];
}) asString = true;
(it "makes a title tag" { })
expected = html.tag "title" {} "foobar"; (it "makes a title tag" {
actual = title {} "foobar"; expected = html.tag "title" {} "foobar";
asString = true; actual = title {} "foobar";
}) asString = true;
})
(it "makes an a tag" { (it "makes an a tag" {
expected = html.tag "a" {href = "https://example.com";} "example"; expected = html.tag "a" {href = "https://example.com";} "example";
actual = a {href = "https://example.com";} "example"; actual = a {href = "https://example.com";} "example";
asString = true; asString = true;
}) })
(it "lets the a tag drop the props" { (it "lets the a tag drop the props" {
expected = html.tag "a" {href = "https://example.com";} "example"; expected = html.tag "a" {href = "https://example.com";} "example";
actual = a "https://example.com" "example"; actual = a "https://example.com" "example";
asString = true; asString = true;
}) })
(it "lets you extend the a tag" (let (it "lets you extend the a tag" (let
extA = a {class = ["linky"];}; extA = a {class = ["linky"];};
in { in {
expected = ["linky"]; expected = ["linky"];
actual = actual =
(extA "https://example.com" "example") (extA "https://example.com" "example")
.attrs .attrs
.class; .class;
asString = true; asString = true;
})) }))
(it "makes a stylesheet link" { (it "makes a stylesheet link" {
expected = html.tag "link" { expected = html.tag "link" {
href = "/style"; href = "/style";
rel = "stylesheet"; rel = "stylesheet";
} ""; } "";
actual = Stylesheet {href = "/style";}; actual = Stylesheet {href = "/style";};
asString = true; asString = true;
}) })
(it "makes a list" { (it "makes a list" {
expected = html.tag "ul" {__ = "";} [ expected = html.tag "ul" {__ = "";} [
(html.tag "li" {} "foo") (html.tag "li" {} "foo")
(html.tag "li" {} "bar") (html.tag "li" {} "bar")
(html.tag "li" {} "baz") (html.tag "li" {} "baz")
]; ];
actual = List {} ["foo" "bar" "baz"]; actual = List {} ["foo" "bar" "baz"];
asString = true; asString = true;
}) })
(it "makes an html doc" { (it "makes an html doc" {
expected = html.tag "html" { expected = html.tag "html" {
__child = ""; __child = "";
class = []; class = [];
lang = "en"; lang = "en";
} [(html.tag "head" {} ["foo"]) (html.tag "body" {} "bar")]; } [(html.tag "head" {} ["foo"]) (html.tag "body" {} "bar")];
actual = Doc {} [["foo"] "bar"]; actual = Doc {} [["foo"] "bar"];
asString = true; asString = true;
}) })
] ]
)
]

View file

@ -5,151 +5,190 @@
}: let }: let
html = import ../nixite/html.nix; html = import ../nixite/html.nix;
in in
with html; with html; [
describe "tag" [ (
(it "keeps info in the tag" (let describe "tag" [
p = tag "p"; (it "keeps info in the tag" (let
in { p = tag "p";
actual = p.tag; in {
expected = "p"; actual = p.tag;
})) expected = "p";
}))
(it "keeps attr info in the tag" (let (it "keeps attr info in the tag" (let
p = tag "p" {class = "";}; p = tag "p" {class = "";};
in { in {
actual = p.attrs; actual = p.attrs;
expected = {class = "";}; expected = {class = "";};
})) }))
(it "keeps tag after setting attrs" (let (it "keeps tag after setting attrs" (let
p = tag "p" {class = "";}; p = tag "p" {class = "";};
in { in {
actual = p.tag; actual = p.tag;
expected = "p"; expected = "p";
})) }))
(it "makes a p tag" { (it "makes a p tag" {
actual = tag "p" {} "Hello"; actual = tag "p" {} "Hello";
expected = { expected = {
tag = "p"; tag = "p";
attrs = {}; attrs = {};
child = "Hello"; child = "Hello";
}; };
removeDunders = true; removeDunders = true;
}) })
(it "makes element" (let (it "makes element" (let
para = tag "p" {}; para = tag "p" {};
in { in {
expected = "p"; expected = "p";
actual = para.tag; actual = para.tag;
})) }))
(it "keeps attrs on element" (let (it "keeps attrs on element" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = attrs; expected = attrs;
actual = para.attrs; actual = para.attrs;
})) }))
(it "makes renderable element" (let (it "makes renderable element" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = "<p ></p>"; expected = "<p ></p>";
actual = toString (para ""); actual = toString (para "");
})) }))
(it "keeps tag" (let (it "keeps tag" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = "p"; expected = "p";
actual = (para "").tag; actual = (para "").tag;
})) }))
(it "keeps style" (let (it "keeps style" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = {foo = "bar";}; expected = {foo = "bar";};
actual = (para "").attrs.style; actual = (para "").attrs.style;
})) }))
(it "needs no args to make string" (let (it "needs no args to make string" (let
p = tag "p"; p = tag "p";
in { in {
actual = toString p; actual = toString p;
expected = "<p ></p>"; expected = "<p ></p>";
})) }))
(it "needs no content to make string" (let (it "needs no content to make string" (let
p = tag "p"; p = tag "p";
in { in {
actual = toString (p {class = "foobar";}); actual = toString (p {class = "foobar";});
expected = ''<p class="foobar"></p>''; expected = ''<p class="foobar"></p>'';
})) }))
(it "can take many sets of props" (let (it "can take many sets of props" (let
p = tag "p"; p = tag "p";
in { in {
actual = toString (p {class = "foobar";} {style = "a style";}); actual = toString (p {class = "foobar";} {style = "a style";});
expected = ''<p class="foobar" style="a style"></p>''; expected = ''<p class="foobar" style="a style"></p>'';
})) }))
(it "works recursively" (let (it "works recursively" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
a = tag "a" {}; a = tag "a" {};
in { in {
expected = "<p ><a >hello</a></p>"; expected = "<p ><a >hello</a></p>";
actual = toString (para (a "hello")); actual = toString (para (a "hello"));
})) }))
(it "throws with function child" { (it "throws with function child" {
actual = toString (tag "p" (i: "")); actual = toString (tag "p" (i: ""));
throws = true; throws = true;
}) })
(it "throws with a number" { (it "throws with a number" {
actual = toString (tag "p" 5); actual = toString (tag "p" 5);
throws = true; throws = true;
}) })
(it "throws with a bool" { (it "throws with a bool" {
actual = toString (tag "p" true); actual = toString (tag "p" true);
throws = true; throws = true;
}) })
(it "throws with a null" { (it "throws with a null" {
actual = toString (tag "p" null); actual = toString (tag "p" null);
throws = true; throws = true;
}) })
(it "concatinates classes" { (it "concatinates classes" {
actual = toString (tag "p" {class = ["class1" "class2"];} "Hello"); actual = toString (tag "p" {class = ["class1" "class2"];} "Hello");
expected = ''<p class="class1 class2">Hello</p>''; expected = ''<p class="class1 class2">Hello</p>'';
}) })
(it "renders on / off attrs" { (it "renders on / off attrs" {
actual = toString (tag "p" { actual = toString (tag "p" {
on = true; on = true;
off = false; off = false;
}); });
expected = "<p on></p>"; expected = "<p on></p>";
}) })
] ]
++ describe "addToHead" [ )
(it "applies style" (let (
page = tag "html" {} [(tag "head" {} ["foo"])]; describe "addToHead" [
in { (it "adds a string to the head" (let
actual = addToHead page ["bar"]; page = html.document {
expected = { head = ["foo"];
tag = "html"; };
attrs = {}; in {
child = [(tag "head" {} ["foo" "bar"])]; actual = addToHead page ["bar"];
}; expected = html.document {
removeDunders = true; head = ["foo" "bar"];
})) };
] asJSON = true;
}))
]
)
(
describe "document" [
(it "has a head and body" {
actual =
(document {
head = [];
})
.head;
expected = [];
})
(it "has a head and body" {
actual =
(document {
body = [];
})
.body;
expected = [];
})
(it "produces a valid html document" {
actual = document {
head = [];
body = [];
};
expected = ''
<!DOCTYPE html>
${(tag "html" [
(tag "head" [])
(tag "body" [])
])}
'';
asString = true;
})
]
)
]

View file

@ -6,145 +6,160 @@
md = import ../nixite/md.nix; md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
in in
with md; with md; [
describe "list" [ (
(it "matches a list of one element" { describe "list" [
actual = list [ (it "matches a list of one element" {
'' actual = list [
- something ''
'' - something
]; ''
expected = [(elems.List ["something"])]; ];
}) expected = [(elems.List ["something"])];
})
(it "makes a list of many elements" { (it "makes a list of many elements" {
actual = list [ actual = list [
'' ''
- something - something
- something else - something else
'' ''
]; ];
expected = [(elems.List ["something" "something else"])]; expected = [(elems.List ["something" "something else"])];
}) })
(it "makes a list of many checkboxes" { (it "makes a list of many checkboxes" {
actual = list [ actual = list [
'' ''
- [ ] something - [ ] something
- [X] something else - [X] something else
'' ''
]; ];
expected = [ expected = [
(elems.List [ (elems.List [
[ [
(elems.input { (elems.input {
type = "checkbox"; type = "checkbox";
disabled = true; disabled = true;
checked = false; checked = false;
} "") } "")
"something" "something"
] ]
[ [
(elems.input { (elems.input {
type = "checkbox"; type = "checkbox";
disabled = true; disabled = true;
checked = true; checked = true;
} "") } "")
"something else" "something else"
] ]
]) ])
]; ];
}) })
(it "matches a list with no whitespace around" { (it "matches a list with no whitespace around" {
actual = list [ actual = list [
'' ''
- something - something
- something else'' - something else''
]; ];
expected = [(elems.List ["something" "something else"])]; expected = [(elems.List ["something" "something else"])];
}) })
(it "doesnt match not a list" (let (it "doesnt match not a list" (let
str = "blah blah"; str = "blah blah";
in { in {
actual = list [str]; actual = list [str];
expected = [str]; expected = [str];
})) }))
] ]
++ describe "process string" [ )
(it "processes whole string with all rules" { (
actual = processStr '' describe "process string" [
this text **may** *or may not* contain **bold** words *inside* it. (it "processes whole string with all rules" {
''; actual = processStr ''
expected = elems.p [ this text **may** *or may not* contain **bold** words *inside* it.
"this text" '';
(elems.strong "may") expected = elems.p [
(elems.em "or may not") "this text"
"contain" (elems.strong "may")
(elems.strong "bold") (elems.em "or may not")
"words" "contain"
(elems.em "inside") (elems.strong "bold")
"it." "words"
]; (elems.em "inside")
asString = true; "it."
}) ];
asString = true;
})
(it "makes paragraphs" { (it "makes paragraphs" {
actual = processStr '' actual = processStr ''
lorem ipsum lorem ipsum
dolor sit dolor sit
foo bar foo bar
''; '';
expected = '' expected = ''
<p >lorem ipsum <p >lorem ipsum
dolor sit dolor sit
</p><p >foo bar</p>''; </p><p >foo bar</p>'';
asString = true; asString = true;
}) })
] ]
++ describe "fix appendix" [ )
(it "can fix file appendixes" { (
actual = fixAppendix "index.md"; describe "fix appendix" [
expected = "index.html"; (it "can fix file appendixes" {
}) actual = fixAppendix "index.md";
] expected = "index.html";
++ describe "mdToPage" [ })
(it "converts markdown to a page" { ]
actual = toString (mdToPage ./blog/index.md) + "\n\n"; # inflation )
expected = builtins.readFile ./out/index.html; (
asString = true; describe "mdToPage" [
}) (it "converts markdown to a page" {
] actual = toString (mdToPage ./blog/index.md) + "\n\n"; # inflation
++ describe "recReadMd" [ expected = builtins.readFile ./out/index.html;
(it "recursively reads dir" { asString = true;
actual = recReadMd ./blog; })
expected = { ]
"index.md" = mdToPage ./blog/index.md; )
"dir" = {"index.md" = mdToPage ./blog/dir/index.md;}; (
}; describe "recReadMd" [
asJSON = true; (it "recursively reads dir" {
}) actual = recReadMd ./blog;
] expected = {
++ describe "recFixAppendix" [ "index.md" = mdToPage ./blog/index.md;
(it "recursively fixes filename" { "dir" = {"index.md" = mdToPage ./blog/dir/index.md;};
actual = recFixAppendix { };
"index.md" = "something"; asJSON = true;
dir = {"index.md" = "something else";}; })
}; ]
expected = { )
"index.html" = "something"; (
dir = {"index.html" = "something else";}; describe "recFixAppendix" [
}; (it "recursively fixes filename" {
}) actual = recFixAppendix {
] "index.md" = "something";
++ describe "readDir" [ dir = {"index.md" = "something else";};
(it "recursively translates md to html" { };
actual = builtins.toJSON (readDir ./blog); expected = {
expected = builtins.toJSON { "index.html" = "something";
"index.html" = mdToPage ./blog/index.md; dir = {"index.html" = "something else";};
"dir" = {"index.html" = mdToPage ./blog/dir/index.md;}; };
}; })
}) ]
] )
(
describe "readDir" [
(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

@ -7,160 +7,163 @@
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix; site = import ../nixite/site.nix;
style = import ../nixite/style.nix; style = import ../nixite/style.nix;
my-site = {
"index.html" = html.document {
head = [(elems.title {} "foobar")];
body = [(elems.main {} "something")];
};
blog = {
"index.html" = html.document {
head = [(elems.title {} "foobar")];
body = elems.main {} "blogy blog";
};
};
};
in in
with site; with site; [
describe "applyStyle" [ (
(it "applies a style" { describe "linkStyle" [
expected = { (it "links a stylesheet" {
"index.html" = html.tag "html" {} [ actual = linkStyle "my-styles.css" my-site;
(html.tag "head" {} [ expected = {
(elems.title {} "foobar") "index.html" = html.addToHead my-site."index.html" [(elems.Stylesheet "my-styles.css")];
(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 = { blog = {
"index.html" = html.tag "html" {} [ "index.html" = html.addToHead my-site.blog."index.html" [(elems.Stylesheet "my-styles.css")];
(html.tag "head" {} [(elems.title {} "foobar")])
(elems.main {} "blogy blog")
];
}; };
}; };
asJSON = true; asJSON = true;
}) })
] ]
++ describe "applyFavicon" [ )
(it "applies a favicon" { (
expected = { describe "applyStyle" [
"index.html" = elems.html {} [ (it "applies a style" {
(elems.head {} [ expected = {
(elems.title {} "foobar") "index.html" = html.addToHead my-site."index.html" [(elems.Stylesheet "/style.css")];
(elems.link { blog = {
rel = "shortcut icon"; "index.html" = html.addToHead my-site.blog."index.html" [(elems.Stylesheet "/style.css")];
href = ./src/favicon.png; };
}) "style.css" = ''
]) this is a stylesheet
(elems.main {} "something") '';
]; };
blog = { actual =
"index.html" = elems.html {} [ applyStyle ''
(elems.head {} [ this is a stylesheet
(elems.title {} "foobar") ''
(elems.link { my-site;
rel = "shortcut icon"; asJSON = true;
href = ./src/favicon.png; })
}) ]
]) )
(elems.main {} "something") (
describe "applyFavicon" [
(it "applies a favicon" (
let
href = "my-favicon.ico";
favicon-link = elems.link {
rel = "shortcut icon";
inherit href;
};
in {
expected = {
"index.html" =
my-site."index.html"
// {
head = my-site."index.html".head ++ [favicon-link];
};
blog = {
"index.html" =
my-site.blog."index.html"
// {
head = my-site.blog."index.html".head ++ [favicon-link];
};
};
};
actual =
applyFavicon href my-site;
}
))
]
)
(
describe "getStyles" [
(it "gets all styles" {
expected = {
"p" = {};
"div" = {};
"p.class" = {color = "blue";};
"div.class2" = {color = "green";};
};
actual = getStyles (let
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 "";};
});
removeDunders = true;
})
]
)
(
describe "getPaths" [
(it "gets top level paths" {
actual = getPaths {
something = "";
src = ./src/index.md;
};
expected = {"index.md" = ./src/index.md;};
})
(it "gets lower level paths" {
actual = getPaths {
something = "yes";
a-list = [
{thingy = ./src/index.md;}
[(html.tag "img" {src = ./src/favicon.png;} "")]
]; ];
}; };
}; expected = {
actual = applyFavicon ./src/favicon.png { "index.md" = ./src/index.md;
"index.html" = elems.html {} [ "favicon.png" = ./src/favicon.png;
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
blog = {
"index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
}; };
}; })
asJSON = true; ]
}) )
] (
++ describe "getStyles" [ describe "switchPaths" [
(it "gets all styles" { (it "switches paths" {
expected = { actual = switchPaths {
"p" = {}; something = "";
"div" = {}; a-thing = {src = ./src/index.md;};
"p.class" = {color = "blue";}; a-list = [{thingy = ./src/index.md;}];
"div.class2" = {color = "green";}; };
}; expected = {
actual = getStyles (let something = "";
p = style.component elems.p "class" {style = {color = "blue";};}; a-thing = {src = "/static/index.md";};
g = style.component elems.div "class2" {style = {color = "green";};}; a-list = [{thingy = "/static/index.md";}];
in { };
"index.html" = p ""; })
blog = {"index.html" = g "";}; ]
}); )
removeDunders = true; (
}) describe "extractPaths" [
] (it "extracts paths" {
++ describe "getPaths" [ actual = extractPaths {
(it "gets top level paths" { something = "";
actual = getPaths { a-thing = {src = ./src/index.md;};
something = ""; a-list = [{thingy = ./src/index.md;}];
src = ./src/index.md; };
}; expected = {
expected = {"index.md" = ./src/index.md;}; something = "";
}) a-thing = {src = "/static/index.md";};
(it "gets lower level paths" { a-list = [{thingy = "/static/index.md";}];
actual = getPaths { static = {"index.md" = ./src/index.md;};
something = "yes"; };
a-list = [ })
{thingy = ./src/index.md;} ]
[(html.tag "img" {src = ./src/favicon.png;} "")] )
]; (describe "switchLinks" [
};
expected = {
"index.md" = ./src/index.md;
"favicon.png" = ./src/favicon.png;
};
})
]
++ describe "switchPaths" [
(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";}];
};
})
]
++ describe "extractPaths" [
(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;};
};
})
]
++ describe "switchLinks" [
(it "switches links" (let (it "switches links" (let
coolPage = { coolPage = {
type = "link"; type = "link";
@ -179,8 +182,8 @@ in
a-list = [{thingy = "/static/cool-page";}]; a-list = [{thingy = "/static/cool-page";}];
}; };
})) }))
] ])
++ describe "getLinks" [ (describe "getLinks" [
(it "gets links" (let (it "gets links" (let
coolPage = { coolPage = {
type = "link"; type = "link";
@ -202,8 +205,8 @@ in
"page2" = "stuff"; "page2" = "stuff";
}; };
})) }))
] ])
++ describe "extractLinks" [ (describe "extractLinks" [
(it "extracts links" (let (it "extracts links" (let
coolPage = { coolPage = {
type = "link"; type = "link";
@ -231,8 +234,8 @@ in
}; };
}; };
})) }))
] ])
++ describe "copyTo" [ (describe "copyTo" [
(it "copies all the files" { (it "copies all the files" {
actual = copyTo "." { actual = copyTo "." {
page = "this is a page"; page = "this is a page";
@ -269,60 +272,37 @@ in
actual = copyTo "." {page = 5;}; actual = copyTo "." {page = 5;};
throws = true; throws = true;
}) })
] ])
++ describe "prepare" [ (describe "prepare" [
(it "prepares the site" { (it "prepares the site" {
actual = prepare {favicon = ./src/favicon.png;} { actual = prepare {favicon = ./src/favicon.png;} my-site;
"index.html" = elems.html {} [ expected = let
(elems.head {} [(elems.title {} "foobar")]) my-favicon-link = elems.link {
(elems.main {} [ rel = "shortcut icon";
(elems.a { href = "/static/favicon.png";
href = { };
type = "link"; my-style = elems.Stylesheet "/style.css";
name = "a-page"; in {
content = "this is another page"; "index.html" = html.document {
}; head =
} "A Page") my-site."index.html".head
]) ++ [my-favicon-link my-style];
]; body = my-site."index.html".body;
blog = {
"index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
}; };
};
expected = {
"index.html" = elems.html {} [
(elems.head {} [
(elems.title {} "foobar")
(elems.link {
rel = "shortcut icon";
href = "/static/favicon.png";
})
(elems.Stylesheet "/style.css")
])
(elems.main {} [(elems.a {href = "/static/a-page";} "A Page")])
];
blog = { blog = {
"index.html" = elems.html {} [ "index.html" = html.document {
(elems.head {} [ body = my-site.blog."index.html".body;
(elems.title {} "foobar") head =
(elems.link { my-site.blog."index.html".head
rel = "shortcut icon"; ++ [my-favicon-link my-style];
href = "/static/favicon.png"; };
})
(elems.Stylesheet "/style.css")
])
(elems.main {} "something")
];
}; };
static = { static = {
"favicon.png" = ./src/favicon.png; "favicon.png" = ./src/favicon.png;
"a-page" = "this is another page";
}; };
"style.css" = ""; "style.css" = "";
}; };
asJSON = true; asJSON = true;
}) })
] ])
]

View file

@ -5,149 +5,158 @@
}: let }: let
style = import ../nixite/style.nix; style = import ../nixite/style.nix;
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
in in [
describe "getStyle" [ (
(it "fetches empty style" (let describe "getStyle" [
para = style.component elems.p "para" {}; (it "fetches empty style" (let
in { para = style.component elems.p "para" {};
expected = { in {
"p" = {}; expected = {
"p.para" = {}; "p" = {};
}; "p.para" = {};
actual = style.getStyle (para ""); };
})) actual = style.getStyle (para "");
}))
(it "fetches style" (let (it "fetches style" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs; para = style.component elems.p "para" attrs;
in { in {
expected = { expected = {
"p" = {}; "p" = {};
"p.para" = attrs.style; "p.para" = attrs.style;
}; };
actual = style.getStyle (para ""); actual = style.getStyle (para "");
})) }))
(it "fetches style for class" (let (it "fetches style for class" (let
s = {foo = "bar";}; s = {foo = "bar";};
para = style.component elems.p "para" {style = s;}; para = style.component elems.p "para" {style = s;};
in { in {
expected = { expected = {
"p" = {}; "p" = {};
"p.para" = s; "p.para" = s;
}; };
actual = style.getStyle (para ""); actual = style.getStyle (para "");
})) }))
] ]
++ describe "component" [ )
(it "applies class" (let (
attrs = {style = {foo = "bar";};}; describe "component" [
para = style.component elems.p "para" attrs; (it "applies class" (let
in { attrs = {style = {foo = "bar";};};
expected = ["para"]; para = style.component elems.p "para" attrs;
actual = (para "").attrs.class; in {
})) expected = ["para"];
actual = (para "").attrs.class;
}))
(it "applies classes from props" (let (it "applies classes from props" (let
attrs = { attrs = {
style = {foo = "bar";}; style = {foo = "bar";};
class = ["other" "class"]; class = ["other" "class"];
}; };
para = style.component elems.p "para" attrs; para = style.component elems.p "para" attrs;
in { in {
expected = ["para" "other" "class"]; expected = ["para" "other" "class"];
actual = (para "").attrs.class; actual = (para "").attrs.class;
})) }))
(it "extends styled tags classes" (let (it "extends styled tags classes" (let
s = { s = {
"p" = {}; "p" = {};
"div" = {}; "div" = {};
"p.para" = {foo = "bar";}; "p.para" = {foo = "bar";};
"p.para.oof" = {oof = "yes";}; "p.para.oof" = {oof = "yes";};
}; };
para = style.component elems.p "para" {style = s."p.para";}; para = style.component elems.p "para" {style = s."p.para";};
para2 = style.component para "oof" {style = s."p.para.oof";}; para2 = style.component para "oof" {style = s."p.para.oof";};
in { in {
expected = ["para" "oof"]; expected = ["para" "oof"];
actual = (para2 "").attrs.class; actual = (para2 "").attrs.class;
})) }))
] ]
++ describe "getStyles" [ )
(it "fetches style recursively" (let (
s = { describe "getStyles" [
"p" = {}; (it "fetches style recursively" (let
"div" = {}; s = {
"p.para" = {foo = "bar";}; "p" = {};
"div.link" = {this = "that";}; "div" = {};
}; "p.para" = {foo = "bar";};
para = style.component elems.p "para" {style = s."p.para";}; "div.link" = {this = "that";};
div = style.component elems.div "link" {style = s."div.link";}; };
in { para = style.component elems.p "para" {style = s."p.para";};
expected = s; div = style.component elems.div "link" {style = s."div.link";};
actual = style.getStyles (para (div "hello")); in {
removeDunders = true; expected = s;
})) actual = style.getStyles (para (div "hello"));
removeDunders = true;
}))
(it "fetches style recursively through lists" (let (it "fetches style recursively through lists" (let
s = { s = {
"p" = {}; "p" = {};
"div" = {}; "div" = {};
"p.para" = {foo = "bar";}; "p.para" = {foo = "bar";};
"div.link" = {this = "that";}; "div.link" = {this = "that";};
}; };
para = style.component elems.p "para" {style = s."p.para";}; para = style.component elems.p "para" {style = s."p.para";};
a = style.component elems.div "link" {style = s."div.link";}; a = style.component elems.div "link" {style = s."div.link";};
in { in {
expected = s; expected = s;
actual = style.getStyles (para [(a "hello")]); actual = style.getStyles (para [(a "hello")]);
removeDunders = true; removeDunders = true;
})) }))
(it "fetches style recursively with repeats" (let (it "fetches style recursively with repeats" (let
s = { s = {
"p" = {}; "p" = {};
"div" = {}; "div" = {};
"p.para" = {foo = "bar";}; "p.para" = {foo = "bar";};
"div.link" = {this = "that";}; "div.link" = {this = "that";};
}; };
para = style.component elems.p "para" {style = s."p.para";}; para = style.component elems.p "para" {style = s."p.para";};
a = style.component elems.div "link" {style = s."div.link";}; a = style.component elems.div "link" {style = s."div.link";};
in { in {
expected = s; expected = s;
actual = style.getStyles (para [(a "hello") (a "hello")]); actual = style.getStyles (para [(a "hello") (a "hello")]);
removeDunders = true; removeDunders = true;
})) }))
(it "extends styled tags" (let (it "extends styled tags" (let
s = { s = {
"p.para" = {foo = "bar";}; "p.para" = {foo = "bar";};
"p.oof" = {oof = "yes";}; "p.oof" = {oof = "yes";};
}; };
para = style.component elems.p "para" {style = s."p.para";}; para = style.component elems.p "para" {style = s."p.para";};
para2 = style.component para "oof" {style = s."p.oof";}; para2 = style.component para "oof" {style = s."p.oof";};
in { in {
expected = s; expected = s;
actual = style.getStyles (para2 ""); actual = style.getStyles (para2 "");
removeDunders = true; removeDunders = true;
})) }))
] ]
++ describe "stylesToString" [ )
(it "converts styles to string" (let (
s = { describe "stylesToString" [
"p" = {}; (it "converts styles to string" (let
"p.para" = {foo = "bar";}; s = {
"a.link" = {this = "that";}; "p" = {};
}; "p.para" = {foo = "bar";};
in { "a.link" = {this = "that";};
expected = '' };
a.link { in {
this: that; expected = ''
} a.link {
p.para { this: that;
foo: bar; }
} p.para {
''; foo: bar;
actual = style.stylesToString s; }
})) '';
] actual = style.stylesToString s;
}))
]
)
]