Compiled at build time.
ESWBuildPlugin turns every .esw and .hesw file into a plain Swift function. No runtime parsing; template typos fail the build.
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
<%!
var users: [User]
%>
<% for user in users { %><li><%= user.name %></li><% } %>
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.
WHAT YOU GET
ESWBuildPlugin turns every .esw and .hesw file into a plain Swift function. No runtime parsing; template typos fail the build.
A component tag compiles to a Swift call, so the compiler checks every attribute, slot, and argument type.
Output is HTML-escaped unless you opt in. Layouts and partials are ordinary templates you compose as Swift functions.
ESWLive keeps state in Swift on the server. A click runs your handler and the browser receives only what changed.
A CLOSER LOOK
Three short files. The whole idea.
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>
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.heswstruct 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>
Each click runs handleEvent and re-renders, and the browser receives only the values that changed. Serve it through your own HTTP adapter.
Counter.swiftimport 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
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(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.