Show HN: A backend agnostic Ruby framework for building reactive desktop apps

1 month ago 3

A Ruby library for authoring GUI applications

status-badge guides docs license

Getting started

In your Gemfile

gem "hokusai-zero", "0.1.7"

In order to run an application, you will need to install a backend

Raylib

  • Install raylib >= 5.0
  • Write your app
  • Run app with RAYLIB_PATH=/libpath/for/libraylib.(so|dylib) ruby <your app>.rb

SDL2

Example counter application

require "hokusai" require "hokusai/backends/raylib" class Counter < Hokusai::Block template <<-EOF [template] vblock hblock label { :content="count" size="130" :color="count_color" } hblock vblock label { content="Add" @click="increment" } vblock label { content="Subtract" @click="decrement" } EOF uses( vblock: Hokusai::Blocks::Vblock, hblock: Hokusai::Blocks::Hblock, label: Hokusai::Blocks::Label, ) attr_accessor :count def increment(event) self.count += 1 end def decrement(event) self.count -= 1 end def count_color self.count > 0 ? [0,0,255] : [255,0,0] end def initialize(**args) @count = 0 super(**args) end end Hokusai::Backends::RaylibBackend.run(Counter) do |config| config.width = 500 config.height = 500 config.title = "Counter application" end

Development

The build tooling of this project is xmake. You will need it to compile dependencies and run demos.

Hokusai contains a tree-sitter grammar to parse templates, and uses md4c to parse markdown.

When compiling the C portion of hokusai, tree-sitter will be statically linked.

Requirements:

  • xmake to build dependencies
  • Ruby to run applications

Steps:

  • Download project
  • Install dependencies
    • bundle install
    • xmake q hoku-tree-sitter
    • xmake q hoku-md4c
    • For Raylib
      • xmake q raylib
    • For SDL2
      • xmake q libsdl
      • xmake q libsdl_gfx
      • xmake q lbsdl_ttf
      • xmake q libsdl_image
  • Build grammar and ast code
    • xmake b hokusai
  • Run specs
    • xmake b -g test
  • Run a demo
    • xmake demo counter

License

Hokusai is released under the Peer Production License

Read Entire Article