jetzig-framework / jetzig

Jetzig is a web framework written in Zig
MIT License
457 stars 21 forks source link

Partial library #61

Open Froxcey opened 4 months ago

Froxcey commented 4 months ago

Pretty much component library for Jetzig. If Jetzig can provide a way for projects to export partials, consume partials from external modules, and provide utilities to make this a well supported feature, I think it would create a vibrant Jetzig ecosystem. This is what I have in mind:

📁 cool_icons/
  📄 build.zig
  📄 build.zig.zon
  📁 assets/
    🖼️ github.svg
    📄 anim.js
  📁 src/
    📄 github.zmpl

📁 website/
  📄 .jetzig
  📄 build.zig
  📄 build.zig.zon
  📁 src/
    📁 app/
      📁 views/
        📄 root.zig
        📁 root/
          📄 index.zmpl

cool_icons/src/github.zmpl:

@args link: []const u8
<a href="https://github.com/{{link}}">
  <img src="@asset("github.svg")"/>
</a>
<script src="@asset("anim.js")"></script>

cool_icons/build.zig:

+ jetzig.exportLibrary();

website/src/app/views/root/index.zmpl

+ @partial &cool_icons/github(link: "froxcey/cool_icons")

This will generate the following HTML:

+ <a href="https://github.com/froxcey/cool_icons">
+    <img src="assets/cool_icons/github.svg"/>
+ </a>
+ <script src="assets/cool_icons/anim.js"></script>

With this, we can do something more complicated, like an webauthn library. The library can export some middleware utility code and front-end components. Cool right?

vibe