百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

erb

> 编程语言
开源

一个易于使用但功能强大的模板系统,适用于 Ruby

184 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个易于使用但功能强大的模板系统,适用于 Ruby

ERB (Embedded Ruby)

ERB is an easy-to-use, but also very powerful, template processor.

ERB is commonly used to produce:

  • Customized or personalized email messages.
  • Customized or personalized web pages.
  • Software code (in code-generating applications).

Like method sprintf, ERB can format run-time data into a string. ERB, however, is much more powerful.

How ERB Works

Using ERB, you can create a template: a plain-text string that has specially-formatted tags, then store it into an ERB object; when ERB produces the result string, it:

  • Inserts run-time-evaluated expressions into the result.
  • Executes snippets of Ruby code.
  • Omits comments from the results.

In the result:

  • All non-tag text is passed through, unchanged.
  • Each tag is either replaced (expression tag), or omitted entirely (execution tag or comment tag).

There are three types of tags:

Tag Form Action Text in Result
Expression tag `` Evaluates ruby_expression. Value of expression.
Execution tag `` Executes ruby_code. None.
Comment tag `` None. None.

These examples use erb, the ERB command-line interface; each "echoes" a string template and pipes it to erb as input:

  • Expression tag:
    bash
    $ echo "" | erb
    false
    
    $ echo "" | erb
    4
  • Execution tag:
    bash
    $ echo " Long message.  Short message. " | erb
     Short message.
  • Comment tag:
    bash
    $ echo " Nonsense." | erb
     Nonsense.

How to Use ERB

You can use ERB either:

  • In a program: see class ERB.
  • From the command line: see ERB Executable.

Installation

ERB is installed with Ruby, and so there's no further installation needed.

Other Template Engines

There are a variety of template engines available in various Ruby projects. For example, RDoc, distributed with Ruby, uses its own template engine, which can be reused elsewhere.

Other popular template engines may be found in the Ruby Toolbox.

Code

The ERB source code is in GitHub project ruby/erb.

Bugs

Bugfixes may be filed at ERB Pull Requests.

License

This software is available as open source under the terms of the 2-Clause BSD License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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