NAME ABOUT SYNOPSIS DESCRIPTION OPTIONS SYNTAX EXAMPLES HACKING VERSIONS CREDITS LICENSE SEE ALSO

ember(1)

  1. ember(1)
  2. Version 0.1.1
  3. ember(1)

NAME

ember - eRuby template processor

ABOUT

Ember (EMBEdded Ruby) is an eRuby template processor that allows debugging, reduces markup, and improves composability of eRuby templates.

Features

Resources

Issue tracker (report bugs, request features, get help)

http://github.com/sunaku/ember/issues

Source code (browse online or obtain with Git)

http://github.com/sunaku/ember

API documentation

http://snk.tuxfamily.org/lib/ember/api/

Announcements feed

http://snk.tuxfamily.org/lib/ember/ann.xml

Official website

http://snk.tuxfamily.org/lib/ember/

Setup

Prerequisites:

Installing:

gem install ember

Upgrading:

gem update ember

Removing:

gem uninstall ember

SYNOPSIS

ember [OPTIONS] [FILE]

DESCRIPTION

Evaluates eRuby directives (see SYNTAX below) in the given FILE and writes the result to the standard output stream (STDOUT). If FILE is not given, then the standard input stream (STDIN) is evaluated instead.

OPTIONS

-s, --shorthand

Treat lines beginning with zero or more whitespace followed by the "%" character as eRuby directives.

-i, --infer_end

Add missing <% end %> directives based on indentation.

-u, --unindent

Unindent the bodies of directives that define a Ruby block (do ... end) or scope (begin ... end).

-c, --compile

Print underlying Ruby program compiled from the input eRuby template and exit.

-h, --help

Print this message and exit.

-v, --version

Print version number and exit.

SYNTAX

This section explains eRuby template syntax and Ember extensions thereof.

eRuby templates are plain-text documents that contain special processing instructions known as directives. These instructions are evaluated in place, meaning that they are replaced by the result of their evaluation.

Directives

Directives are expressed in either standard or shorthand notation:

Notation    Directive   Head   Operation   Body   Tail
--------    ---------   ----   ---------   ----   ----
Standard    <%XY%>      <%     X           Y      %>
Shorthand   %XY         %      X           Y

In standard notation, the directive is composed of a head, an operation, a body, and a tail; and it may appear anywhere in the template.

In shorthand notation, the directive is composed of a head, an operation, and a body; and it may only appear in the template if it occupies an entire line (leading whitespace is permitted only in Ember; trailing whitespace is permitted in both Ember and eRuby).

Regardless of the notation used, directives are atomic constructs; they cannot be nested within one another.

Operations

The first character following the head of a directive is known as an operation. It determines how the directive is processed by Ember.

#

The entire directive is omitted from the output.

=

The body of the directive is evaluated as Ruby code, and the result of this evaluation is inserted into the output.

~

(only in Ember) The body of the directive is evaluated as an eRuby template, and the result of this evaluation is inserted into the output.

+

(only in Ember) The body of the directive is evaluated as Ruby code, and the result of this evaluation is assumed to be a string that specifies the path (either absolute or relative to the eRuby template file in which this directive is found) to a file containing an eRuby template. This file is read and its contents are evaluated as an eRuby template, and the result of this evaluation is inserted into the output.

<

(only in Ember) The body of the directive is evaluated as Ruby code, and the result of this evaluation is assumed to be a string that specifies the path (either absolute or relative to the eRuby template file in which this directive is found) to a file. This file is read and its contents are inserted into the output.

|

(only in Ember) The body of the directive is treated as the beginning of a Ruby block. The do keyword is automatically appended to the body of the directive if missing.

%

One "%" character is omitted from the head of the directive and the entire directive is inserted into the output.

None of the above

The body of the directive is evaluated as Ruby code, but the result of this evaluation is not inserted into the output.

EXAMPLES

Begin by loading Ember into Ruby:

require 'rubygems' # might not be necessary; see HACKING
require 'ember'

Instantiate an Ember template processor:

source   = "your eRuby template here"
options  = {} # see API documentation
template = Ember::Template.new(source, options)

Inspect the Ruby program that was compiled (and is used) by the Ember template processor to evaluate the eRuby template given as input:

puts template.program

View the result of evaluating the eRuby template:

puts template.render

See the API documentation for more information.

An empty template

Begin with an empty template:




The above template compiles into:

(_erbout = []; _erbout << "\n"
; _erbout.join)

And renders as:




Comment directives

Add comment directives:

<%# this is a comment %>
%# this is also a comment

<%# this
is
    a
multi-line comment %>

With {:shorthand=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
_erbout << "\n"
_erbout << "\n"
_erbout << "\n"




_erbout << "  \n"
; _erbout.join)

And renders as:




  

Escaped directives

Add escaped directives:

<%% this is an escaped directive %>
%% this is an escaped directive

With {:shorthand=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
_erbout << "<% this is an escaped directive %>\n"
_erbout << "% this is an escaped directive\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

<% this is an escaped directive %>
% this is an escaped directive

Vocal directives

Add vocal directives, which produce output:

<%= "hello" %>
%= "world"

With {:shorthand=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
_erbout << ("hello") << "\n"
_erbout << ("world") << "\n"
_erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

hello
world

Silent directives

Add silent directives, which do not produce output:

<% a = "hello" %>
% b = "world"

<%= a %>
%= b

With {:shorthand=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
 a = "hello" 
 b = "world"
_erbout << "\n"
_erbout << (a) << "\n"
_erbout << (b) << "\n"
_erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

hello
world

Block directives

Add some Ruby blocks:

% words = %w[hello world]

<% words.each do |w| %>
  <%= w %>
<% end %>

% words.each do |w|
  %= w
% end

%|words.each |w|
  %= w
% end

With {:shorthand=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
 words = %w[hello world]
_erbout << "\n"
 words.each do |w| 
_erbout << "  " << (w) << "\n"
 end 
_erbout << "\n"
 words.each do |w|
_erbout << "  " << (w) << "\n"
 end
_erbout << "\n"
words.each do |w|
_erbout << "  " << (w) << "\n"
 end
_erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

  hello
  world

  hello
  world

  hello
  world

Infer block endings

Omit <% end %> directives from the template:

% words = %w[hello world]

<% words.each do |w| %>
  <%= w %>

% words.each do |w|
  %= w

%|words.each |w|
  %= w

With {:shorthand=>true, :infer_end=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
 words = %w[hello world]
_erbout << "\n"
 words.each do |w| 
_erbout << "  " << (w) << "\n"
end; _erbout << "\n"
 words.each do |w|
_erbout << "  " << (w) << "\n"
end; _erbout << "\n"
words.each do |w|
_erbout << "  " << (w) << "\n"
end; _erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

  hello
  world

  hello
  world

  hello
  world

Raw file inclusion

When doc/example.txt contains:

This is a plain-text file.  Notice that <%=
"eRuby directives" %> have no effect here!

And the eRuby template is:

<%< "doc/example.txt" %>

%< "doc/example.txt"

With {:shorthand=>true, :source_file=>"./EXAMPLES"} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
_erbout << (::Ember::Template.read_file(( "doc/example.txt" ), {:shorthand=>true, :source_file=>"./EXAMPLES"})) << "\n"
_erbout << "\n"
_erbout << (::Ember::Template.read_file(( "doc/example.txt"), {:shorthand=>true, :source_file=>"./EXAMPLES"})) << "\n"
_erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

This is a plain-text file.  Notice that <%=
"eRuby directives" %> have no effect here!

This is a plain-text file.  Notice that <%=
"eRuby directives" %> have no effect here!

Template file inclusion

When doc/example.erb contains:

This is an eRuby template.  Notice that <%=
"eRuby directives" %> do take effect here!

And the eRuby template is:

<%+ "doc/example.erb" %>

%+ "doc/example.erb"

With {:shorthand=>true, :source_file=>"./EXAMPLES"} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
::Ember::Template.load_file(( "doc/example.erb" ), {:shorthand=>true, :source_file=>"./EXAMPLES"}.merge!(:continue_result => true)).render(nil, 79777922); _erbout << "\n"
_erbout << "\n"
::Ember::Template.load_file(( "doc/example.erb"), {:shorthand=>true, :source_file=>"./EXAMPLES"}.merge!(:continue_result => true)).render(nil, 79777922); _erbout << "\n"
_erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

This is an eRuby template.  Notice that eRuby directives do take effect here!

This is an eRuby template.  Notice that eRuby directives do take effect here!

Dynamic template evaluation

<%~ "%= 2 + 2" %>

%~ "%= 2 + 2"

With {:shorthand=>true} options, the above template compiles into:

(_erbout = []; _erbout << "\n"
::Ember::Template.new(( "%= 2 + 2" ), {:shorthand=>true}.merge!(:continue_result => true)).render(nil, 79408546); _erbout << "\n"
_erbout << "\n"
::Ember::Template.new(( "%= 2 + 2"), {:shorthand=>true}.merge!(:continue_result => true)).render(nil, 79408546); _erbout << "\n"
_erbout << "\n"
_erbout << "  \n"
; _erbout.join)

And renders as:

4

4

HACKING

This section is meant for people who want to develop Ember's source code.

Prerequisites

Install Ruby libraries necessary for development:

gem install ember --development

Infrastructure

Inochi serves as Ember's project infrastructure. It handles tasks such as building this manual and API documentation, and packaging, announcing, and publishing new releases. See its manual to get started:

inochi --help

$LOAD_PATH setup

Ensure that the lib/ directory is listed in Ruby's $LOAD_PATH before you use any libraries therein or run any executables in the bin/ directory.

This can be achieved by passing an option to Ruby:

ruby -Ilib

Or by setting the $RUBYLIB environment variable:

export RUBYLIB=lib   # bash, ksh, zsh
setenv RUBYLIB lib   # csh
set -x RUBYLIB lib   # fish

Or by installing the ruby-wrapper tool.

RubyGems setup

If you use Ruby 1.8 and RubyGems to manage your Ruby software, then ensure that RubyGems is activated before you use any libraries in the lib/ directory or run any executables in the bin/ directory.

This can be achieved by passing an option to Ruby:

ruby -rubygems

Or by setting the $RUBYOPT environment variable:

export RUBYOPT=-rubygems   # bash, ksh, zsh
setenv RUBYOPT -rubygems   # csh
set -x RUBYOPT -rubygems   # fish

Running tests

Simply execute the included test runner, which sets up Ruby's $LOAD_PATH for testing, loads the included test/test_helper.rb file, and then evaluates all test/**/*_test.rb files:

test/runner

Its exit status will indicate whether all tests have passed. It may also print additional pass/fail information depending on the testing library used in the test/test_helper.rb file.

Contributing

Fork this project on GitHub (see Resources above) and send a pull request.

VERSIONS

This section contains release notes of current and past releases.

Version 0.1.1 (2010-04-20)

This release fixes a nested rendering bug, updates the manual, and further beautifies the Ruby code that results from eRuby template compilation.

Bug fixes:

Housekeeping:

Version 0.1.0 (2010-04-03)

This release improves the handling of eRuby comment directives, fixes a bug in the <% end %> inference logic, and performs some minor housekeeping.

New features:

Bug fixes:

Housekeeping:

Version 0.0.1 (2009-10-03)

This release improves Ruby 1.9 support and revises the user manual.

Bug fixes:

Housekeeping:

Version 0.0.0 (2009-02-13)

This is the first public release of Ember. Enjoy!

CREDITS

Suraj N. Kurapati

LICENSE

(the ISC license)

Copyright 2009 Suraj N. Kurapati sunaku@gmail.com

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

SEE ALSO

erb(1), Erubis, eruby

  1. April 2010
  2. ember(1)