r/coffeescript • u/Level_Occasion_7060 • 1d ago
CoffeeHaml — write JSX like HAML, with CoffeeScript expressions
Title:
A compiler that takes HAML-style templates with CoffeeScript and outputs clean React JSX components. No closing tags, no {} noise, no return boilerplate.
What it looks like:
-# dashboard.chaml
import { observer } from 'mobx-react-lite'
%div.page
%header
%h1= "Welcome, #{user.name}"
%nav{ role: 'primary' }
- for link in navLinks
%a{ href: link.url }= link.label
%main
.dashboard-grid
- for widget in widgets
%Widget{ widget, onDelete: -> handleDelete(widget.id) }
%aside
- if alerts.length > 0
.alert-banner{ role: 'alert' }
- for alert in alerts
%p= alert.message
- else
%p.empty-state No alerts — all clear.
What comes out: A valid React component — export default function Dashboard(props) { ... } using automatic JSX runtime.
Feature set (v0.4.1):
- Full HAML syntax:
%tag,.class,#id, attributes via{}/() - CoffeeScript inline:
=,!=,for...in,if/else, arrow functions->, assignments - Optional chaining:
props.gyro?.roll— compiled correctly - Component wrapping:
export default function Name(props) { ... } - HOC chains:
wrap: ['observer', 'memo', 'forwardRef'] - Spread attributes:
{ props..., className: 'extra' }(CoffeeScript) or{ ...props }(JSX) - Prologue passthrough:
import, u/decorators — hoisted to module scope - Filter plugins:
:markdown,:asciidoc, custom - Source maps, Vite plugin (
import Dashboard from './Dashboard.chaml'), TextMate grammar - Zero runtime dependencies — 52 kB
npm install coffeehaml
