1
Fork 0
mirror of https://github.com/RGBCube/HTMNIX synced 2025-05-31 04:28:13 +00:00
No description
Find a file
2024-03-04 11:44:06 +03:00
.gitignore Add docs WIP 2024-03-04 11:44:06 +03:00
build.sh Remove useless --apply from build.sh 2024-03-04 11:44:06 +03:00
escape.nix Prefer lib. instead of builtins. 2024-02-28 14:09:09 +03:00
flake.lock Fix scopedImport 2024-02-28 12:54:15 +03:00
flake.nix Don't HTML-ify <nixpkgs> and handle lists properly 2024-03-04 11:44:06 +03:00
LICENSE.md Add docs WIP 2024-03-04 11:44:06 +03:00
README.md Add docs WIP 2024-03-04 11:44:06 +03:00

HTMNIX

Write composeable HTML with Nix!

Here is an example snippet:

<html>
  <head>
    <title>"Hello, Internet!"<.title>
  <.head>
  <body>
      <p>"Yep, this is 100% Nix!"<.p>

      <img.>{src="/foo.png"; alt="Attributes also work!";}
  <.body>
<.html>

You might be wondering, How?

If you are, go read my blog post!

More Examples

All of the examples here can be rendered with the following command (assuming html.nix has the example content):

TARGET_FILE=$(realpath html.nix) nix eval github:RGBCube/HTMNIX#result --raw --impure

Create a directory listing:

<ul>
  (lib.mapAttrsToList
    (name: type: <li>"${name} (${type})"<.li>)
    (builtins.readDir ./.))
<.ul>

List metadata about a derivation:

let
  pkg = (import <nixpkgs> {}).youtube-dl;
in

<div>{class="package";}
  <p>"Name: ${pkg.pname}"<.p>
  <details>
    <summary>"See metadata"<.summary>
    <ul>
      <li>"Full name: ${pkg.name}"
      <li>"Version: ${pkg.version}"
      <li>(let
        license = if lib.isList pkg.meta.license then
          lib.elemAt pkg.meta.license 0
        else
          pkg.meta.license;
      in "License: ${license.fullName}")
    <.ul>
  <.details>
<.div>

License

MIT License

Copyright (c) 2024-present RGBCube

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.