From 8ee2707ce645cda75ef9e8ae900aed850eaef86d Mon Sep 17 00:00:00 2001 From: tristan Date: Sun, 31 Dec 2023 03:08:41 +0000 Subject: [PATCH] format --- flake.nix | 45 +++++++++--------- nixite/style.nix | 66 +++++++++++++++----------- testing/style.test.nix | 102 ++++++++++++++++++++++------------------- 3 files changed, 115 insertions(+), 98 deletions(-) diff --git a/flake.nix b/flake.nix index 0524df4..e98d428 100644 --- a/flake.nix +++ b/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; diff --git a/nixite/style.nix b/nixite/style.nix index a434d8c..948561b 100644 --- a/nixite/style.nix +++ b/nixite/style.nix @@ -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; } diff --git a/testing/style.test.nix b/testing/style.test.nix index bbb5880..c57e0bf 100644 --- a/testing/style.test.nix +++ b/testing/style.test.nix @@ -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; + }) +]