LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

erb

Embedded Ruby template processor

TLDR

Process ERB template
$ erb [template.erb]
copy
Process with Ruby variables
$ erb -r [./vars.rb] [template.erb]
copy
Output to file
$ erb [template.erb] > [output.html]
copy
Trim mode for cleaner output
$ erb -T - [template.erb]
copy
Print result without newline
$ erb -P [template.erb]
copy

SYNOPSIS

erb [options] [file...]

DESCRIPTION

erb processes ERB (Embedded Ruby) templates, allowing Ruby code to be embedded within text files. ERB is commonly used in Rails views and configuration file generation.Templates use special tags: `<%= expr %>` outputs the expression result, `<% code %>` executes code without output, and `<%# comment %>` is for comments.

PARAMETERS

-r library

Require Ruby library before processing.
-T mode
Trim mode: 0, 1, 2, or -.
-P
Don't print newline after output.
-e
Ignore RUBYOPT environment variable.
-x
Print Ruby script instead of executing.
-n
Print line numbers in output.
-v
Verbose mode.
--version
Show version.

TEMPLATE SYNTAX

$ <h1><%= @title %></h1>
<ul>
<% @items.each do |item| %>
  <li><%= item %></li>
<% end %>
</ul>
<%# This is a comment %>
copy

TRIM MODES

$ -T 0  - No trimming
-T 1  - Trim lines ending with %>
-T 2  - Trim lines containing only <% %>
-T -  - Trim newlines after -%>
copy

INSTALL

sudo apt install ruby
copy
sudo dnf install ruby
copy
sudo pacman -S ruby
copy
sudo apk add ruby
copy
sudo zypper install ruby
copy
brew install ruby
copy
nix profile install nixpkgs#ruby
copy

CAVEATS

Embedded Ruby executes with full permissions. Input should be trusted. Complex logic belongs in code, not templates. Whitespace handling may need trim mode adjustment.

HISTORY

ERB was created by Masatoshi Seki and included in Ruby's standard library. It became popular with Ruby on Rails as the default view template engine, though Rails now often uses alternatives like Slim or Haml.

SEE ALSO

ruby(1), irb(1), haml(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid