Skip to content
ponylangPublic

About

Live view. For Pony.

Resources

Code of conduct

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Repository files navigation

livery

A library for building interactive, server-rendered LiveView UIs over WebSocket in Pony.

Status

Livery is beta quality software that will change frequently. Expect breaking changes. That said, you should feel comfortable using it in your projects.

Installation

  • Requires ponyc 0.78.0 or later.
  • Install corral
  • corral add github.com/ponylang/livery.git --version 0.15.0
  • corral fetch to fetch your dependencies
  • use "livery" to include this package
  • corral run -- ponyc to compile your application

Usage

Define a LiveView class, register routes, and start a listener:

use "templates"
use "json"
use "net"
use "livery"

class CounterView is LiveView
  let _template: HtmlTemplate val

  new create() ? =>
    _template = HtmlTemplate.parse(
      """
      <div>
        <h1>Count: {{ count }}</h1>
        <button lv-click="increment">+</button>
      </div>
      """)?

  fun ref mount(socket: Socket ref) =>
    socket.assign("count", "0")

  fun ref handle_event(event: String val, payload: JsonValue,
    socket: Socket ref)
  =>
    try
      let current = socket.get_assign("count")?.string()?.i64()?
      if event == "increment" then
        socket.assign("count", (current + 1).string())
      end
    end

  fun box render(assigns: Assigns box): String ? =>
    _template.render(assigns.template_values())?

actor Main
  new create(env: Env) =>
    let router = Router
    router.route("/counter",
      {(): LiveView ref^ ? => CounterView.create()?} val)

    Listener(TCPListenAuth(env.root), "0.0.0.0", "8081",
      router.build(), env.err)

See the examples directory for more.

API Documentation

https://ponylang.github.io/livery

About

Live view. For Pony.

Resources

Code of conduct

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages