Part of the Roost family

Write HTML.
Ship Swift.

Templates compiled into Swift functions.

EEx-style tags and HTML-aware HESW templates, checked by the Swift compiler at build time. Typed components, escaping by default, and live views when you need them.

ESW 1.8 · Swift 6.3 · Build plugin

users.esw
<%!
var users: [User]
%>
<% for user in users { %><li><%= user.name %></li><% } %>
Generated by ESWBuildPlugin · abridgedrenderUsers(users:)
func renderUsers(
    users: [User]
) -> String {
    var _buf = ESWBuffer()
    for user in users {
    _buf.append(#"<li>"#)
    _buf.appendEscaped(user.name)
    _buf.append(#"</li>"#)
    }
    return _buf.finalize()
}

Part of Roost.
One Swift stack.

Roost The web framework 2.1 Nexus HTTP & routing 2.0 Spectro PostgreSQL & migrations 2.1

WHAT YOU GET

Templates the
compiler checks.

Compiled at build time.

ESWBuildPlugin turns every .esw and .hesw file into a plain Swift function. No runtime parsing; template typos fail the build.

Typed components.

A component tag compiles to a Swift call, so the compiler checks every attribute, slot, and argument type.

Escaped by default.

Output is HTML-escaped unless you opt in. Layouts and partials are ordinary templates you compose as Swift functions.

Live when you need it.

ESWLive keeps state in Swift on the server. A click runs your handler and the browser receives only what changed.

A CLOSER LOOK

Template, component,
live view.

Three short files. The whole idea.

Parameters with types.

The opening block declares typed parameters. Expressions are escaped; the double-equals form inserts trusted HTML, such as another template. This file becomes renderPostsIndex(title: posts: isAdmin:).

Views/posts/index.esw
<%!
var title: String
var posts: [Post]
var isAdmin: Bool = false
%>
<h1><%= title %></h1>
<% if isAdmin { %>
  <a href="/posts/new">New post</a>
<% } %>
<ul>
<% for post in posts { %>
  <li><%== renderPostsCard(post: post) %></li>
<% } %>
</ul>

Attributes the compiler checks.

Define a component once in Swift. Using it in a template compiles to Card.render(title:footer:content:), with named slots passed as arguments.

Card.swift · profile.hesw
struct Card: ESWComponent {
    static func render(title: String, footer: String = "", content: String = "") -> String {
        #hesw("""
        <article class="card">
          <h2>{title}</h2>
          {ESWValue.safe(content)}
          <footer>{ESWValue.safe(footer)}</footer>
        </article>
        """)
    }
}

<!-- Views/profile.hesw -->
<.card title={user.name}>
  <p>{user.bio}</p>
  <:footer>Member since {user.joinedYear}</:footer>
</.card>

State stays on the server.

Each click runs handleEvent and re-renders, and the browser receives only the values that changed. Serve it through your own HTTP adapter.

Counter.swift
import ESWLive

struct Counter: Interactive {
    func mount(_ context: LiveContext) async throws -> Int { 0 }

    func handleEvent(_ event: LiveEvent, state: Int) async throws -> Int {
        guard event.name == "increment" else { throw LiveError.invalidEvent }
        return state + 1
    }

    func render(_ count: Int) -> ESWLiveRender {
        #live("""
        <output id="count">{count}</output>
        <button type="button" esw-click="increment">+1</button>
        """)
    }
}

INSTALL

Add it to
your package.

One plugin does the compiling.

Depend on ESW, and ESWLive for live views. Attach ESWBuildPlugin and put .esw or .hesw files in your target; each becomes a render function at build time.

Swift 6.3+ · macOS 14+

Read the guide
Package.swift
.package(url: "https://github.com/roost-framework/ESW.git", from: "1.8.0")

.target(
    name: "App",
    dependencies: [
        .product(name: "ESW", package: "esw"),
        .product(name: "ESWLive", package: "esw")
    ],
    plugins: [.plugin(name: "ESWBuildPlugin", package: "esw")]
)

Your markup,
type-checked.

Explore ESW on GitHub