summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix6
-rw-r--r--lib/html.nix159
2 files changed, 90 insertions, 75 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 2e3127d..0264e55 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,5 +1,3 @@
-{ lib }:
-
-{
- pp.html = import ./html.nix { inherit lib; };
+{lib}: {
+ pp.html = import ./html.nix {inherit lib;};
}
diff --git a/lib/html.nix b/lib/html.nix
index f66184b..105888e 100644
--- a/lib/html.nix
+++ b/lib/html.nix
@@ -1,34 +1,30 @@
-{ lib, ... }:
-
-let
+{lib, ...}: let
comment = content: "<!-- ${content} -->";
lines = content:
- if lib.isList content then
- (if content == [ ] then
- ""
- else
- lines (builtins.head content) + "\n" + lines (builtins.tail content))
- else
- content;
+ if lib.isList content
+ then
+ (
+ if content == []
+ then ""
+ else lines (builtins.head content) + "\n" + lines (builtins.tail content)
+ )
+ else content;
sortByFun = cmp: f: lib.sort (x: y: cmp (f x) (f y));
sortByPath = cmp: keys: sortByFun cmp (lib.getAttrFromPath keys);
- sortByKey = cmp: key: sortByPath cmp [ key ];
+ sortByKey = cmp: key: sortByPath cmp [key];
for = iterable: f:
- if lib.isList iterable then
- builtins.map f iterable
- else
- lib.mapAttrsToList f iterable;
+ if lib.isList iterable
+ then builtins.map f iterable
+ else lib.mapAttrsToList f iterable;
setAttr = attr: value: ''${attr}="${value}"'';
- tagWithAttrs = tag: attrs:
- "<${tag}${
- lib.concatMapStrings (x: " ${x}") (lib.mapAttrsToList setAttr attrs)
- }>";
+ tagWithAttrs = tag: attrs: "<${tag}${
+ lib.concatMapStrings (x: " ${x}") (lib.mapAttrsToList setAttr attrs)
+ }>";
tryOverride = f: arg:
- if lib.isAttrs arg then
- tryOverride (attrs: content: f (arg // attrs) content)
- else
- f { } arg;
+ if lib.isAttrs arg
+ then tryOverride (attrs: content: f (arg // attrs) content)
+ else f {} arg;
container = tag:
tryOverride
(attrs: content: "${tagWithAttrs tag attrs}${lines content}</${tag}>");
@@ -169,7 +165,7 @@ let
"template"
];
tagsContainerFuns =
- builtins.foldl' (module: tag: module // { "${tag}" = container tag; }) { }
+ builtins.foldl' (module: tag: module // {"${tag}" = container tag;}) {}
tagsContainer;
tagsEmpty = [
@@ -189,61 +185,82 @@ let
"track"
"wbr"
];
- tagsEmptyFuns = builtins.foldl' (module: tag:
- let tagWith = empty tag;
- in module // {
+ tagsEmptyFuns = builtins.foldl' (module: tag: let
+ tagWith = empty tag;
+ in
+ module
+ // {
"${tag}With" = tagWith;
- "${tag}" = tagWith { };
- }) { } tagsEmpty;
+ "${tag}" = tagWith {};
+ }) {}
+ tagsEmpty;
file = path: "/static/files/${path}";
- href = tryOverride (attrs: url: content:
- tagsContainerFuns.a ({ href = url; } // attrs) content);
+ href =
+ tryOverride (attrs: url: content:
+ tagsContainerFuns.a ({href = url;} // attrs) content);
icon =
- tryOverride (attrs: id: tagsContainerFuns.i (attrs // { class = id; }) "");
+ tryOverride (attrs: id: tagsContainerFuns.i (attrs // {class = id;}) "");
mailto = tryOverride (attrs: address: href attrs "mailto:${address}" address);
timerange = let
- print = date:
- let
- year = builtins.toString date.year;
- month = lib.optionalString (date.month < 10) "0"
- + builtins.toString date.month;
- monthPretty = builtins.head (lib.drop (date.month - 1) [
- "jan"
- "feb"
- "mar"
- "apr"
- "may"
- "jun"
- "jul"
- "aug"
- "sep"
- "oct"
- "nov"
- "dev"
- ]);
- day = builtins.toString date.day;
- in tagsContainerFuns.time { date = "${year}-${month}-${day}"; }
+ print = date: let
+ year = builtins.toString date.year;
+ month =
+ lib.optionalString (date.month < 10) "0"
+ + builtins.toString date.month;
+ monthPretty = builtins.head (lib.drop (date.month - 1) [
+ "jan"
+ "feb"
+ "mar"
+ "apr"
+ "may"
+ "jun"
+ "jul"
+ "aug"
+ "sep"
+ "oct"
+ "nov"
+ "dev"
+ ]);
+ day = builtins.toString date.day;
+ in
+ tagsContainerFuns.time {date = "${year}-${month}-${day}";}
"${monthPretty}. ${year}";
- in start: end: "${print start} - ${print end}";
+ in
+ start: end: "${print start} - ${print end}";
doctype = type: ''
<!DOCTYPE ${type}>
'';
-in tagsContainerFuns // tagsEmptyFuns // {
- inherit for comment container doctype empty file href icon lines mailto
- timerange;
-} // {
- sort = let
- lt = x: y: x < y;
- gt = x: y: x > y;
- in {
- byKey = sortByKey lt;
- byPath = sortByPath lt;
- byFun = sortByFun lt;
- reverse = {
- byKey = sortByKey gt;
- byPath = sortByPath gt;
- byFun = sortByFun gt;
+in
+ tagsContainerFuns
+ // tagsEmptyFuns
+ // {
+ inherit
+ for
+ comment
+ container
+ doctype
+ empty
+ file
+ href
+ icon
+ lines
+ mailto
+ timerange
+ ;
+ }
+ // {
+ sort = let
+ lt = x: y: x < y;
+ gt = x: y: x > y;
+ in {
+ byKey = sortByKey lt;
+ byPath = sortByPath lt;
+ byFun = sortByFun lt;
+ reverse = {
+ byKey = sortByKey gt;
+ byPath = sortByPath gt;
+ byFun = sortByFun gt;
+ };
};
- };
-}
+ }