ruby2html 2.1.0 — write views in pure Ruby, render HTML faster than ERB and Phlex
ruby2html lets you write views as a plain Ruby block DSL — div(class: ‘card’) { h1 @title } — and renders clean, escaped HTML with a C extension doing the hot work (SIMD escaping, tag rendering, attribute serialization). No runtime dependencies. Works standalone, as Rails .html.rb templates, inside ERB, in ViewComponent, or as lightweight Ruby2html::Component classes.
It’s fast. On a ~34 KB page with attributes and escaped text it does ~2,676 renders/s — about 1.35× faster than Erubi (Rails’ ERB engine) and 2.4–16× faster than Phlex 2, with roughly 8× fewer allocations than it had a version ago. Escaping is a security boundary: text and attributes are escaped by default, raw output only for things you explicitly mark safe.
What’s new in 2.1.0: - JRuby: a tiny Java escaper (new -java platform gem, jar prebuilt — no JDK to install) makes rendering ~1.9× faster on JRuby, byte-for-byte identical output. - TruffleRuby: now runs on the pure-Ruby path under Graal instead of the C ext via Sulong — ~28× faster there. - Ruby 4.0 supported and in CI; the version matrix tracks the official maintained list automatically. - One C extension + a byte-identical pure-Ruby twin, verified against each other on every engine (plus an XSS/escaping audit).
CRuby, JRuby, TruffleRuby, Rails 7.2+. MIT.
gem install ruby2html Release: https://github.com/sebyx07/ruby2html/releases/tag/v2.1.0 Source: https://github.com/sebyx07/ruby2html
Post a comment