Skip to content

Lightweight Elixir DSL for generating HTML in a clean, expressive, and composable way - using just Elixir syntax.

License

Notifications You must be signed in to change notification settings

PenguinBoi12/silk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Silk

Tests Silk version

Silk is a lightweight Elixir DSL for generating HTML in a clean, expressive, and composable way - using just Elixir syntax.

Features

  • Elixir-style HTML generation with blocks.
  • Supports standard and void HTML tags.
  • Compile-time HTML construction using macros.
  • Supports Pheonix LiveView Component

Silk is a great fit for:

  • Generating dynamic HTML fragments in scripts or apps
  • Writing small UI components without reaching for a full template engine
  • Keeping everything in Elixir, especially in tooling, testing, or LiveView helper contexts

Installation

def deps do
  [
    {:silk_html, "~> 0.1.0"}
  ]
end

Usage

Start by importing the Silk module and using the tag macro:

import Silk

tag :section, class: "content" do
  tag :h1, do: "Welcome"
end

Dynamic content? No problem:

import Silk

tag :ul do
  Enum.map ["one", "two", "three"], fn item ->
    tag :li, do: item
  end
end

Void tags like img, br, or input:

tag :img, src: "/logo.png", alt: "Logo"

Phoenix LivewView and Live Component

Simple usage:

import Silk.LiveView

live_tag(:button, "phx-click: "save") do
  "Save!"
end

With rendering:

attr :for, :string, default: nil
slot :inner_block, required: true

def label(assigns) do
  live_tag(:label, for: assigns.for, class: "block text-sm font-semibold leading-6 text-zinc-800") do
    ~H[{render_slot(@inner_block)}]
  end
end

Note: Currently it is not possible to call a live component (i.e. .label) from live_tag.

License

Silk is released under GPL-3.0 - See the LICENCE.

About

Lightweight Elixir DSL for generating HTML in a clean, expressive, and composable way - using just Elixir syntax.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages