eRuby

from Wikipedia, the free encyclopedia
eRuby (erb)
File extension : .erb, .html.erb, .xml.erb
Current version: 1.3.0 (as of November 8, 2008)
Type: Markup language
Website : modruby.net/en/index.rbx/eruby/whatis.html ( Memento from November 4, 2012 in the Internet Archive )

eRuby is a template mechanism that enables Ruby to be embedded in a text file. It is often used to integrate Ruby code into an HTML document, similar to ASP , JSP or PHP . eRuby is available for the same platforms that Ruby is available for, and it is available under the GPL and LGPL licenses .

use

eRuby allows you to insert Ruby code between a pair of <%and %>or <%=and %>. These embedded blocks of code are executed. With <% %>, the block is then replaced by the empty string. This is mainly used for loop constructs, but also for if-then-else conditions or for setting variables used later. When <%= %>the result of the enclosed expression is inserted.

Here are a few examples of using eRuby:

One line of Ruby

<% ruby code %>

Output of "Hello": <% puts "Hallo" %>

Alternatively, lines that %begin with are also interpreted completely as Ruby:

% ruby code

Multiple lines

These constructs can be a bit ungrateful because the beginning and the end are not clearly recognizable as belonging together. They work like blocks in Ruby and are <% end %>terminated by. These language constructs are often used for loops, such as:

<ul>
<% 3.times do %>

  <li>list item</li>

<% end %>
</ul>

Which produces the following output:

  • list item
  • list item
  • list item

The same code could also be written like this:

<ul>
% 3.times do
  <li>list item</li>
% end
</ul>

Insertion of results

<%= Ruby-Ausdruck %>
- Der Wert, der als Ergebnis des Ausdrucks herauskommt, z. B. 11 von 7 + 4, ersetzt im Ergebnis den ganzen Ausdruck einschließlich der
<%= %>

Brackets. Often it is just a line or part of a line.

Comments

<%# Kommentar %>
- dies ist dasselbe wie ein Kommentar in Ruby. Der ganze Kommentar wird beim Erzeugen der Ausgabe weggelassen.

Other things that are common in eRuby were simply taken over from Ruby, such as string interpolation with

#{Ausdruck}

which are also available in a similar form in languages ​​such as Perl (programming language) and PHP .

Implementations

There are many implementations of eRuby:

eruby

eruby is an implementation of eRuby written in C.

inherit

erb is an implementation of eRuby written entirely in Ruby .

erubis

erubis is an implementation of eRuby written in Ruby and also in Java . According to its own homepage, it runs faster than eruby and erb (as of 2011) and has many more options, including alternative tags that enable the writing of valid XML .

ember

ember is an implementation of eRuby written in pure Ruby. It allows debugging of eRuby templates, improves their composition options and allows powerful abbreviations for eRuby directives.

See also

credentials

  1. kuwata-lab.com
  2. ember

Web links