239 lines
5.6 KiB
Nix
239 lines
5.6 KiB
Nix
let
|
|
html = import ../nixite/html.nix;
|
|
elems = import ../nixite/elems.nix;
|
|
site = import ../nixite/site.nix;
|
|
style = import ../nixite/style.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")
|
|
];
|
|
};
|
|
};
|
|
asJSON = true;
|
|
})
|
|
|
|
(it "applies a favicon" {
|
|
expected = {
|
|
"index.html" = elems.html { } [
|
|
(elems.head { } [
|
|
(elems.title { } "foobar")
|
|
(elems.link {
|
|
rel = "shortcut icon";
|
|
href = ./src/favicon.png;
|
|
})
|
|
])
|
|
(elems.main { } "something")
|
|
];
|
|
blog = {
|
|
"index.html" = elems.html { } [
|
|
(elems.head { } [
|
|
(elems.title { } "foobar")
|
|
(elems.link {
|
|
rel = "shortcut icon";
|
|
href = ./src/favicon.png;
|
|
})
|
|
])
|
|
(elems.main { } "something")
|
|
];
|
|
};
|
|
};
|
|
actual = applyFavicon ./src/favicon.png {
|
|
"index.html" = elems.html { } [
|
|
(elems.head { } [ (elems.title { } "foobar") ])
|
|
(elems.main { } "something")
|
|
];
|
|
blog = {
|
|
"index.html" = elems.html { } [
|
|
(elems.head { } [ (elems.title { } "foobar") ])
|
|
(elems.main { } "something")
|
|
];
|
|
};
|
|
};
|
|
asJSON = true;
|
|
})
|
|
|
|
(it "gets all styles" {
|
|
expected = {
|
|
"p.class" = { color = "blue"; };
|
|
"a.class2" = { color = "green"; };
|
|
};
|
|
actual = getStyles (let
|
|
p = style.tag "p" "class" { style = { color = "blue"; }; };
|
|
g = style.tag "a" "class2" { style = { color = "green"; }; };
|
|
in {
|
|
"index.html" = p "";
|
|
blog = { "index.html" = g ""; };
|
|
});
|
|
removeDunders = true;
|
|
})
|
|
|
|
(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 = {
|
|
"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 "switches functions" (let
|
|
coolPage = _: {
|
|
type = "page";
|
|
name = "cool-page";
|
|
content = "";
|
|
};
|
|
in {
|
|
actual = switchFunctions {
|
|
something = "";
|
|
a-thing = { src = coolPage; };
|
|
a-list = [{ thingy = coolPage; }];
|
|
};
|
|
expected = {
|
|
something = "";
|
|
a-thing = { src = "/static/cool-page"; };
|
|
a-list = [{ thingy = "/static/cool-page"; }];
|
|
};
|
|
}))
|
|
|
|
(it "gets functions" (let
|
|
coolPage = _: {
|
|
type = "page";
|
|
name = "cool-page";
|
|
content = "cool content";
|
|
};
|
|
otherPage = _: {
|
|
type = "page";
|
|
name = "page2";
|
|
content = "stuff";
|
|
};
|
|
in {
|
|
actual = getFunctions {
|
|
something = "yes";
|
|
a-list =
|
|
[ { thingy = coolPage; } [ (elems.img { src = otherPage; } "") ] ];
|
|
};
|
|
expected = {
|
|
"cool-page" = "cool content";
|
|
"page2" = "stuff";
|
|
};
|
|
}))
|
|
|
|
(it "extracts functions" (let
|
|
coolPage = _: {
|
|
type = "page";
|
|
name = "cool-page";
|
|
content = "cool content";
|
|
};
|
|
otherPage = _: {
|
|
type = "page";
|
|
name = "page2";
|
|
content = "stuff";
|
|
};
|
|
|
|
in {
|
|
actual = extractFunctions {
|
|
something = "";
|
|
a-thing = { src = coolPage; };
|
|
a-list = [{ thingy = otherPage; }];
|
|
};
|
|
expected = {
|
|
something = "";
|
|
a-thing = { src = "/static/cool-page"; };
|
|
a-list = [{ thingy = "/static/page2"; }];
|
|
static = {
|
|
"cool-page" = "cool content";
|
|
"page2" = "stuff";
|
|
};
|
|
};
|
|
}))
|
|
|
|
(it "copies all the files" ({
|
|
actual = copyTo "." {
|
|
page = "this is a page";
|
|
subdir = {
|
|
page = "this page is in a subdir";
|
|
link = ./src;
|
|
};
|
|
};
|
|
expected = ''
|
|
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
|
|
mkdir -p ./subdir
|
|
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
|
|
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
|
|
|
|
'';
|
|
}))
|
|
|
|
]
|