Fire.app Feature Tutorial
Introducing Template Language: ERB
Fire.app provides many template languages to simplify HTML development.
We choose to introduce ERB here because ERB is actually "HTML with embedded Ruby." Those good with HTML will find ERB is easy to get familiar with.
With Fire.app we can easily use the template language by adding a corresponding file extension. For example, ERB uses this file extension
The three common ways to insert RUBY into ERB are listed below:
Only executes Ruby code and does not output results into HTML:
<% Ruby code... %>
Use an equal sign
= to execute Ruby code and output results into HTML.
<%= Ruby code... %>
Use a sharp sign
# to write a comment.
<%# Comment... %>
In addition, there are three commonly used functions:
<% if condition %> This part will be executed if condition is true <% else %> This part will be executed if condition is false <% end %>
<% if (1+1==2) %> This line will be displayed. <% else %> This line will never be displayed. <% end %>
Because the condition
1+1==2 is always true, the result of the code above will be
This line will be displayed. no matter what time it runs.
Do something for n times
<% n.times do %> do something <% end %>
<% 3.times do %> Good morning! <% end %>
The result of the code above will be
Good morning! Good morning! Good morning! .
Generating a number from 0 to n-1 randomly
<%= rand(n) %>
<%= rand(3) %>
The result of the code above could be