Skip to content
@go-ruby-erb

go-ruby-erb

go-ruby-erb

go-ruby-erb

Ruby's ERB template compiler in pure Go — MRI-compatible byte-for-byte, no cgo.

🌐 Website · 📚 Documentation

Docs License: BSD-3-Clause Go 1.26.4+ Coverage 100%


go-ruby-erb is a pure-Go (no cgo) reimplementation of ERB, Ruby's templating system — the deterministic, interpreter-independent core of MRI's ERB::Compiler. It turns an ERB template string into the Ruby source that renders it, matching MRI 4.0.5 byte-for-byte, and provides ERB::Util's html_escape / url_encode helpers.

Compiling a template — tag scanning, trim modes, the <%% %%> literals, magic-comment detection, the String#dump text encoding — is fully deterministic and needs no interpreter, so it lives here as pure Go. The final eval(compiled_src, binding) that produces the rendered string does need a Ruby interpreter and stays in the consumer (e.g. rbgo).

This library compiles; the host evaluates.

It is standalone and reusable by any Go program, and is the ERB backend for the sibling org go-embedded-ruby.

Repositories

Repo What it is
erb the compiler: tag scanner, trim modes, the Compile / Compiler API, and ERB::Util (HTMLEscape / URLEncode)
docs MkDocs Material documentation, versioned with mike, served at /docs/
go-ruby-erb.github.io the Hugo landing page
brand logos and brand assets

Principles

  • Pure Go, zero cgo. Cross-compiles and embeds anywhere; a static binary by default.
  • A compiler, not a renderer. It emits MRI-byte-exact Ruby source plus the magic comment; the rendering eval needs an interpreter and lives downstream — that split is what lets the deterministic core ship as pure Go.
  • MRI byte-exact. Emitted source and rendered output match the reference ERB::Compiler exactly, validated by a differential oracle against the ruby binary.
  • Standalone & reusable. No dependency on the Ruby runtime; the dependency runs the other way.
  • 100% test coverage is the target, enforced as a CI gate.

Status

Compiler complete — MRI byte-exact. A faithful port of MRI's lib/erb/compiler.rb: all tag kinds (<% %>, <%= %>, <%# %>), the <%% %%> literals, every trim mode (-, >, <>, % and combinations), magic-comment detection (incl. the emacs -*- … -*- form), and binary-exact literal-run encoding via Ruby's String#dump, plus ERB::Util's HTMLEscape / URLEncode. Differential-tested against MRI 4.0.5 — emitted source and rendered output compared byte-for-byte — at 100% coverage, gofmt + go vet clean, CI green across the six 64-bit Go targets (amd64, arm64, riscv64, loong64, ppc64le, s390x). The rendering eval is downstream in the go-embedded-ruby consumer, not part of this module.

BSD-3-Clause.

Popular repositories Loading

  1. .github .github Public

  2. go-ruby-erb.github.io go-ruby-erb.github.io Public

    HTML

  3. brand brand Public

  4. docs docs Public

    Go

  5. erb erb Public

    Go

Repositories

Showing 5 of 5 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…