Show HN:一个与后端无关的用于构建响应式桌面应用的 Ruby 框架
Show HN: A backend agnostic Ruby framework for building reactive desktop apps

原始链接: https://codeberg.org/skinnyjames/hokusai

Hokusai是一个Ruby库,用于构建GUI应用程序,支持Raylib和SDL2后端。要开始使用,请在Gemfile中添加`gem "hokusai-zero"`并安装所选的后端(Raylib或SDL2)。运行应用程序需要指定后端共享库的路径(例如,`RAYLIB_PATH`或`SDL_PATH`)。 该库采用基于模板的方法,例如提供的使用`Hokusai::Block`的计数器应用程序。使用`vblock`和`hblock`等块定义布局,并使用`increment`和`decrement`等方法处理事件。可以使用`count_color`等属性动态控制样式。 开发需要xmake来构建依赖项(用于模板解析的tree-sitter和用于markdown的md4c)。说明中详细介绍了安装依赖项、构建语法和AST代码、运行规范以及执行演示的过程。Hokusai采用同行制作许可证(Peer Production License)授权。

Hokusai,一个用于构建响应式桌面应用程序的新Ruby框架,正在Hacker News上引发热议。它使用C/Ruby开发,采用自定义的tree sitter语法进行模板解析,并提供可组合的UI组件、事件/属性处理、插槽、样式和自动化功能。其目标是优先考虑易于编写的自定义组件,而不是固定的组件集。目前可在Windows、Mac和Linux上安装,但测试仍在进行中。 其许可证PPL引发了争议,因为它可能与GPL等其他许可证不兼容。人们担心这会影响其在Linux发行版中的采用和分发。由于包含了GPL2许可的`colorize` gem,还有人指出可能存在GPL违规行为。作者承认了许可证方面的问题,并正在重新考虑许可证的选择。 有人将其与`shoes.rb`、RubyMotion甚至Vue单文件组件进行了比较。讨论还涉及部署策略、潜在的Android支持以及基于代码的UI构建与Qt Designer等可视化设计器之间的权衡。社区表达了对其潜力的兴趣,并提供了宝贵的反馈。

原文

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

  • Install the following deps

  • Write your app

  • Run app with SDL_PATH=/libpath/for/libsdl.(so|dylib) ruby <your app>.rb

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
    • For SDL2
      • xmake q libsdl
      • xmake q libsdl_gfx
      • xmake q lbsdl_ttf
      • xmake q libsdl_image
  • Build grammar and ast code
  • Run specs
  • Run a demo

License

Hokusai is released under the Peer Production License

联系我们 contact @ memedata.com