format
This commit is contained in:
parent
ff2f68c907
commit
8ee2707ce6
3 changed files with 115 additions and 98 deletions
45
flake.nix
45
flake.nix
|
@ -20,34 +20,33 @@
|
|||
style = nixite.style;
|
||||
|
||||
packages.${system} = {
|
||||
default =
|
||||
nixite.mkSite (nixite.site.applyStyle ./testing/src/style.css {
|
||||
default = nixite.mkSite (nixite.site.applyStyle ./testing/src/style.css {
|
||||
"index.html" = with nixite.elems; (doc
|
||||
[
|
||||
(title "Nixite")
|
||||
]
|
||||
(main [
|
||||
(nixite.md.readMd ./testing/src/index.md)
|
||||
(link "/blog" "blog")
|
||||
(list [
|
||||
"item 1"
|
||||
"item 2"
|
||||
"item 3"
|
||||
])
|
||||
]));
|
||||
blog = {
|
||||
"index.html" = with nixite.elems; (doc
|
||||
[
|
||||
(title "Nixite")
|
||||
(title "A post")
|
||||
]
|
||||
(main [
|
||||
(nixite.md.readMd ./testing/src/index.md)
|
||||
(link "/blog" "blog")
|
||||
(list [
|
||||
"item 1"
|
||||
"item 2"
|
||||
"item 3"
|
||||
])
|
||||
(p ''
|
||||
This is a post
|
||||
'')
|
||||
(link "/" "Home")
|
||||
]));
|
||||
blog = {
|
||||
"index.html" = with nixite.elems; (doc
|
||||
[
|
||||
(title "A post")
|
||||
]
|
||||
(main [
|
||||
(p ''
|
||||
This is a post
|
||||
'')
|
||||
(link "/" "Home")
|
||||
]));
|
||||
};
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
serve = self.serve self.packages.${system}.default;
|
||||
|
||||
|
|
|
@ -2,38 +2,48 @@ let
|
|||
html = import ./html.nix;
|
||||
|
||||
join = {
|
||||
__functor = self: new: self // new //
|
||||
{ style = self.style + new.style; };
|
||||
__functor = self: new:
|
||||
self
|
||||
// new
|
||||
// {style = self.style + new.style;};
|
||||
};
|
||||
|
||||
mkStyle = identifier: styles: ''
|
||||
${identifier} {
|
||||
${toString (builtins.attrValues (
|
||||
builtins.mapAttrs (key: value:
|
||||
''${key}: ${value};''
|
||||
) styles
|
||||
))}
|
||||
}
|
||||
'';
|
||||
${identifier} {
|
||||
${toString (builtins.attrValues (
|
||||
builtins.mapAttrs (
|
||||
key: value: ''${key}: ${value};''
|
||||
)
|
||||
styles
|
||||
))}
|
||||
}
|
||||
'';
|
||||
|
||||
mkIdentifier = tag: { class ? [], id ? "", ... }: "${tag}"
|
||||
+ builtins.concatStringsSep "" (map (c: "." + c) class)
|
||||
+ ( if id != "" then "#" else "" ) + id;
|
||||
mkIdentifier = tag: {
|
||||
class ? [],
|
||||
id ? "",
|
||||
...
|
||||
}:
|
||||
"${tag}"
|
||||
+ builtins.concatStringsSep "" (map (c: "." + c) class)
|
||||
+ (
|
||||
if id != ""
|
||||
then "#"
|
||||
else ""
|
||||
)
|
||||
+ id;
|
||||
in {
|
||||
styled = name: tag: cprops: styles:
|
||||
{
|
||||
${name} = props: child: (html.tag tag (props // cprops) child);
|
||||
|
||||
in
|
||||
{
|
||||
styled = name: tag: cprops: styles: {
|
||||
style = mkStyle (mkIdentifier tag cprops) styles;
|
||||
}
|
||||
// join;
|
||||
|
||||
${name} = props: child:
|
||||
(html.tag tag (props // cprops) child);
|
||||
|
||||
style = mkStyle (mkIdentifier tag cprops) styles;
|
||||
|
||||
} // join;
|
||||
|
||||
style = identifier: styles: {
|
||||
|
||||
style = mkStyle identifier styles;
|
||||
|
||||
} // join;
|
||||
style = identifier: styles:
|
||||
{
|
||||
style = mkStyle identifier styles;
|
||||
}
|
||||
// join;
|
||||
}
|
||||
|
|
|
@ -7,58 +7,66 @@ let
|
|||
(style.styled "p" "p" {} {
|
||||
some-style = "some value";
|
||||
})
|
||||
(style.styled "div" "div" { class = ["something"]; } {
|
||||
(style.styled "div" "div" {class = ["something"];} {
|
||||
this = "that";
|
||||
})
|
||||
(style.styled "s" "div" { id = "s"; class = ["something"]; } {
|
||||
s = "yes";
|
||||
})
|
||||
(style.styled "foobar" "div" { class = ["foo" "bar"]; } {
|
||||
(style.styled "s" "div" {
|
||||
id = "s";
|
||||
class = ["something"];
|
||||
} {
|
||||
s = "yes";
|
||||
})
|
||||
(style.styled "foobar" "div" {class = ["foo" "bar"];} {
|
||||
something = "something";
|
||||
})
|
||||
(style.style "body" {
|
||||
foo = "bar";
|
||||
});
|
||||
|
||||
in [
|
||||
(it "makes a p component" ({
|
||||
expected = (html.tag "p" {} "yes");
|
||||
actual = my.p {} "yes";
|
||||
}))
|
||||
(it "makes a component" ({
|
||||
expected = (html.tag "div" { class = ["something"]; } "foobar");
|
||||
actual = my.div {} "foobar";
|
||||
}))
|
||||
(it "makes special components" ({
|
||||
expected = (html.tag "div" { id = "s"; class = ["something"]; } "foobar");
|
||||
actual = my.s {} "foobar";
|
||||
}))
|
||||
(it "works on many classes" ({
|
||||
expected = (html.tag "div" { class = ["foo" "bar"]; } "foobar");
|
||||
actual = my.foobar {} "foobar";
|
||||
}))
|
||||
(it "combines attrs" ({
|
||||
expected = (html.tag "div" { id = "foo"; class = ["something"]; } "foobar");
|
||||
actual = my.div { id = "foo"; } "foobar";
|
||||
}))
|
||||
(it "makes a style" ({
|
||||
expected = ''
|
||||
p {
|
||||
some-style: some value;
|
||||
}
|
||||
div.something {
|
||||
this: that;
|
||||
}
|
||||
div.something#s {
|
||||
s: yes;
|
||||
}
|
||||
div.foo.bar {
|
||||
something: something;
|
||||
}
|
||||
body {
|
||||
foo: bar;
|
||||
}
|
||||
'';
|
||||
actual = my.style;
|
||||
}))
|
||||
]
|
||||
(it "makes a p component" {
|
||||
expected = html.tag "p" {} "yes";
|
||||
actual = my.p {} "yes";
|
||||
})
|
||||
(it "makes a component" {
|
||||
expected = html.tag "div" {class = ["something"];} "foobar";
|
||||
actual = my.div {} "foobar";
|
||||
})
|
||||
(it "makes special components" {
|
||||
expected = html.tag "div" {
|
||||
id = "s";
|
||||
class = ["something"];
|
||||
} "foobar";
|
||||
actual = my.s {} "foobar";
|
||||
})
|
||||
(it "works on many classes" {
|
||||
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
|
||||
actual = my.foobar {} "foobar";
|
||||
})
|
||||
(it "combines attrs" {
|
||||
expected = html.tag "div" {
|
||||
id = "foo";
|
||||
class = ["something"];
|
||||
} "foobar";
|
||||
actual = my.div {id = "foo";} "foobar";
|
||||
})
|
||||
(it "makes a style" {
|
||||
expected = ''
|
||||
p {
|
||||
some-style: some value;
|
||||
}
|
||||
div.something {
|
||||
this: that;
|
||||
}
|
||||
div.something#s {
|
||||
s: yes;
|
||||
}
|
||||
div.foo.bar {
|
||||
something: something;
|
||||
}
|
||||
body {
|
||||
foo: bar;
|
||||
}
|
||||
'';
|
||||
actual = my.style;
|
||||
})
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue