ERuby

Template: Infobox file format / Maintenance / MIME missing template: Infobox file format / Maintenance / Magic number is missing template: Infobox file format / Maintenance / Developers missing template: Infobox file format / Maintenance / default missing

ERuby is a template mechanism which allows to embed Ruby in a text file. It is often used for this in order to integrate Ruby code into an HTML document, similar to ASP, JSP or PHP. eRuby is available for the same platforms for which there is Ruby, and it is under the GPL and LGPL licenses available.

Use

ERuby it, Ruby code to be inserted between a pair of <% and% > or < % = and% > allowed. These embedded code blocks are executed. In < % %> then the block is replaced by an empty string. This is mainly used for looping constructs, but also for if-then- else conditions or for setting variables to be used later. In < % = %>, the result of the enclosed expression is inserted.

Here are a few examples of the use of eRuby:

A line Ruby

<% Ruby code %> Edition of " Hello ": <% puts " Hello "%>

Alternatively, also lines that start with %, fully interpreted as Ruby:

% Ruby code Several lines of

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

    <% 3.times do% >   
  • list item < / li > <% End %> What produces the following output:

    • List item
    • List item
    • List item

    The same code could be rewritten as:

      % 3.times do   
    • list item < / li > % end Result establishment

      <% = Ruby expression %> - The value that comes out as a result of the expression, eg 11 of 7 4, replaced as a result of the whole expression, including the

      <% = %> - Bracketing. Often it is only a line or part of a line.

      Comments

      < % # Comment %> - This is the same as a comment in Ruby. The whole comment is omitted when generating the output. Other things that are common in eRuby were simply taken over by Ruby, such as the Zeichenketteninterpolation with

      # { Expression} That exist in 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, which is written in C.

      Erb

      Erb is an implementation of eRuby, which is written entirely in Ruby.

      Erubis

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

      Ember

      Ember is written in pure Ruby implementation of eRuby. It allows you to debug eRuby templates, improves their composition possibilities and allow powerful abbreviations for eRuby directives.

314798
de