Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

temple

> 编程语言
Open source

Template compilation framework in Ruby

514 stars0 likes3 views
WebsiteGitHub

About

Template compilation framework in Ruby

Temple

Temple is an abstraction and a framework for compiling templates to pure Ruby. It's all about making it easier to experiment, implement and optimize template languages. If you're interested in implementing your own template language, or anything else related to the internals of a template engine: You've come to the right place.

Have a look around, and if you're still wondering: Ask on the mailing list and we'll try to do our best. In fact, it doesn't have to be related to Temple at all. As long as it has something to do with template languages, we're interested: .

Links

  • Source:
  • Bugs:
  • List:
  • API documentation:
    • Latest Gem:
    • GitHub master:
  • Abstractions:

Overview

Temple is built on a theory that every template consists of three elements:

  • Static text
  • Dynamic text (pieces of Ruby which are evaluated and sent to the client)
  • Codes (pieces of Ruby which are evaluated and not sent to the client, but might change the control flow).

The goal of a template engine is to take the template and eventually compile it into the core abstraction:

 [:multi,
   [:static, "Hello "],
   [:dynamic, "@user.name"],
   [:static, "!\n"],
   [:code, "if @user.birthday == Date.today"],
   [:static, "Happy birthday!"],
   [:code, "end"]]

Then you can apply some optimizations, feed it to Temple and it generates fast Ruby code for you:

 _buf = []
 _buf  Render a file
 MyTemplate.new { "String" }.render # => Render a string

Installation

You need at least Ruby 1.9.3 to work with Temple. Temple is published as a Ruby Gem which can be installed as following:

 $ gem install temple

Engines using Temple

  • Slim
  • Hamlit
  • Faml
  • Sal
  • Temple-Mustache (Example implementation)
  • Temple ERB example implementation (Temple::ERB::Template)
  • WLang

Acknowledgements

Thanks to _why for creating an excellent template engine (Markaby) which is quite slow. That's how I started experimenting with template engines in the first place.

I also owe Ryan Davis a lot for his excellent projects ParserTree, RubyParser, Ruby2Ruby and SexpProcessor. Temple is heavily inspired by how these tools work.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言