Show HN: 一个与后端无关的 Ruby 框架,用于构建响应式桌面应用
这是一个基于 Ruby 的框架,名为 Hokusai,用于构建与后端无关的响应式桌面应用程序。它使用 Raylib 或 SDL2 作为后端,并提供示例计数器应用程序。开发需要安装 xmake 和 Ruby,并按照步骤构建和运行。该项目使用 Peer Production License 协议。
该项目是一个与后端无关的 Ruby 框架,用于构建响应式桌面应用程序。
20 commits 10 branches 0 tags 4.3 MiB C 53.4% Ruby 43.7% Lua 1.1% JavaScript 0.9% Rust 0.5% Other 0.3% main
下载 ZIP 下载 TAR.GZ 下载 BUNDLE Open with VS Code Open with VSCodium Open with Intellij IDEA
skinnyjames 5380728dd8 Update README.md | 2025-05-09 16:06:59 +00:00
Hokusai
一个用于编写 GUI 应用程序的 Ruby 库
快速开始
在你的 Gemfile 中添加:
gem "hokusai-zero", "0.1.7"
为了运行应用程序,你需要安装一个后端
Raylib
- 安装 raylib >= 5.0
- 编写你的应用
- 使用以下命令运行应用:
RAYLIB_PATH=/libpath/for/libraylib.(so|dylib) ruby <your app>.rb
SDL2
- 安装以下依赖:
- 编写你的应用
- 使用以下命令运行应用:
SDL_PATH=/libpath/for/libsdl.(so|dylib) ruby <your app>.rb
示例计数器应用程序
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
开发
该项目的构建工具是 xmake。 你需要它来编译依赖项和运行演示。
Hokusai 包含一个 tree-sitter 语法来解析模板,并使用 md4c
来解析 markdown。
当编译 Hokusai 的 C 部分时,tree-sitter 将被静态链接。
依赖:
- xmake 用于构建依赖
- Ruby 用于运行应用
步骤:
- 下载项目
- 安装依赖
bundle install
xmake q hoku-tree-sitter
xmake q hoku-md4c
- 对于 Raylib
xmake q raylib
- 对于 SDL2
xmake q libsdl
xmake q libsdl_gfx
xmake q lbsdl_ttf
xmake q libsdl_image
- 构建语法和 ast 代码
xmake b hokusai
- 运行 specs
xmake b -g test
- 运行一个示例
xmake demo counter
许可协议
Hokusai 在 Peer Production License 下发布。