ERuby

eRuby is a templating system that embeds Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to ASP, JSP and PHP.

Usage

eRuby allows Ruby code to be embedded within a pair of <% and %> delimiters. These embedded code blocks are then evaluated in-place (they are replaced by the result of their evaluation).

Here are a few examples of eRuby usage:

One Line of Ruby

<% ruby code %>

Output like hello from <% print "hello" %> would replace the ruby code between the delimiters.

Alternatively, lines starting with a % sign are interpreted as Ruby as well:

% ruby code

Multiple LinesThese can appear less graceful because the beginning and ending are not quite the same. They function like blocks in Ruby and are terminated by <% end %>. They are commonly used as looping constructs, which appear like this:

    <% 3.times do %>

  • list item
  • <% end %>

Outputting:

  • list item
  • list item
  • list item

If one comes from other languages such as PHP or Perl, the structure may not seem intuitive, but is often very concise and readable (if one knows Ruby).

The same code could also be written as:

    % 3.times do
  • list item
  • % end

Expression Result Substitution

<%= ruby expression %>
- Value evaluated from expression like 11 from 7 + 4 would replace the ruby expression between the delimiters. Often these are only one line.

Comments

<%# ruby code %>
- this is the same as a comment in Ruby. All Ruby code after the # is ignored and generates nothing.

Other things common in eRuby are simply common in Ruby, such as string substitution with

#{string_name}
which is similar templating languages in Perl or PHP. The main difference could be described as "string_name" in Ruby is a string object, and not a string variable. In practice it works almost the same.

Implementations

There are several implementations of eRuby:

eruby

eruby is an implementation of eRuby written in the C programming language.

erb

erb is an implementation of eRuby, written purely in the Ruby programming language.

erubis

erubis is an implementation of eRuby, implemented in ruby and also in java. It runs faster than eruby and erb, and has several useful options, including alternate tags allowing for valid xml.

ee also

* mod_ruby
* Haml
* RDoc
* Markaby

External links

* [http://www.modruby.net/en/index.rbx/eruby/download.html eruby source Download] (from [http://www.modruby.net www.modruby.net] )
* [http://ruby-doc.org/docs/ProgrammingRuby/html/web.html "Ruby and the web"] , a chapter from [http://ruby-doc.org/docs/ProgrammingRuby/ "The Pragmatic Programmer's Guide"]
* [http://www.hiveminds.co.uk/node/3094 eRuby: How to Get Started with Ruby Web Programming]
* [http://www.hiveminds.co.uk/node/3098 eRuby: Using Ruby DBI for Database Connectivity]
* [http://www.hiveminds.co.uk/node/3100 eRuby: Getting Started with Ruby on Windows IIS]
* [http://www.hiveminds.co.uk/node/3096 eRuby: Using Ruby and MySQL for dynamic web pages]
* [http://www.hiveminds.co.uk/node/3093 eRuby: Using Embedded Ruby to Create Web Pages]


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • ERuby — Vorlage:Infobox Dateiformat/Wartung/MIME fehltVorlage:Infobox Dateiformat/Wartung/MagischeZahl fehltVorlage:Infobox Dateiformat/Wartung/Entwickler fehltVorlage:Infobox Dateiformat/Wartung/Standard fehlt eRuby (erb) Dateiendung: .erb, .html.erb,… …   Deutsch Wikipedia

  • eRuby — В этой статье не хватает ссылок на источники информации. Информация должна быть проверяема, иначе она может быть поставлена под сомнение и удалена. Вы можете отр …   Википедия

  • Mongrel (web server) — Mongrel Developer(s) Zed A. Shaw Stable release 1.1.5 / May 22, 2008; 3 years ago (2008 05 22) Operating system Cross platform …   Wikipedia

  • Nitro (web framework) — Nitro Developer(s) George Moschovitis Stable release 0.41 / December 12, 2006; 4 years ago (2006 12 12) Operating system Cross platform …   Wikipedia

  • Merb — Original author(s) Ezra Zygmuntowicz Developer(s) Yehuda Katz Stable release 1.1.2[1] / June 17, 2010; 16 months ago (2010 06 17) …   Wikipedia

  • Ruby MRI — Ruby Developer(s) Yukihiro Matsumoto (among others) Stable release 1.9.2 / August 18, 2010; 14 months ago (2010 08 18) …   Wikipedia

  • ERB — Cette page d’homonymie répertorie les différents sujets et articles partageant un même nom. 1) Sigles et acronymes ERB : ancien acronyme français pour l École de Radiotélégraphie de Bordeaux, actuellement ENSEIRB. ERB. acronyme anglais… …   Wikipédia en Français

  • Erb — Cette page d’homonymie répertorie les différents sujets et articles partageant un même nom. 1) Sigles et acronymes ERB : ancien acronyme français pour l École de Radiotélégraphie de Bordeaux, actuellement ENSEIRB. ERB. acronyme anglais… …   Wikipédia en Français

  • Erb (homonymie) — Erb Cette page d’homonymie répertorie les différents sujets et articles partageant un même nom. 1) Sigles et acronymes ERB : ancien acronyme français pour l École de Radiotélégraphie de Bordeaux, actuellement ENSEIRB. ERB. acronyme anglais… …   Wikipédia en Français

  • Merb — Тип Фреймворк для разработки веб приложений Автор Эззра Зигмунтович Разработчик Йехуда Катц Написана на Ruby Операционная система Кроссплатформенное программное обеспечение Языки интерфейса …   Википедия


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.