Erbside Demonstrandum
Ruby
Sideline Rendering
Given a file named ‘example.rb’ containing:
# ordinary comment
VERSION = "?" # :erb: VERSION = "<%= 1+1 %>"
The rendered result of ‘example.rb’ will be:
# ordinary comment
VERSION = "2" # :erb: VERSION = "<%= 1+1 %>"
Sideline Rendering with First Match Marker
Given a file named ‘example.rb’ containing:
# Script generated 200X #:erb: ^generated <%= 2009 %>
The rendered result of ‘example.rb’ will be:
# Script generated 2009 #:erb: ^generated <%= 2009 %>
Notice in this case we rendered a comment.
Multiline Rendering
Given a file named ‘example.rb’ containing:
#:erb+1: <%= %w{z y x}.sort.join("\n") %>
blah blah blah
The rendered result of ‘example.rb’ will be:
#:erb+3: <%= %w{z y x}.sort.join("\n") %>
x
y
z
Block Rendering
Given a file named ‘example.rb’ containing:
=begin :erb+0:
<%= %w{a b c}.map{ |x| "#{x}!" }.join("\n") %>
=end
The rendered result of ‘example.rb’ will be:
=begin :erb+3:
<%= %w{a b c}.map{ |x| "#{x}!" }.join("\n") %>
=end
a!
b!
c!
Bash
Sideline Rendering
Given a file named ‘example.sh’ containing:
# ordinary comment
VERSION = "?" # :erb: VERSION = "<%= 1+1 %>"
The rendered result of ‘example.sh’ will be:
# ordinary comment
VERSION = "2" # :erb: VERSION = "<%= 1+1 %>"
Sideline Rendering with First Match Marker
Given a file named ‘example.sh’ containing:
# Script generated 200X #:erb: ^generated <%= 2009 %>
The rendered result of ‘example.sh’ will be:
# Script generated 2009 #:erb: ^generated <%= 2009 %>
Notice in this case we rendered a comment.
Multiline Rendering
Given a file named ‘example.sh’ containing:
#:erb+1: <%= %w{z y x}.sort.join("\n") %>
blah blah blah
The rendered result of ‘example.sh’ will be:
#:erb+3: <%= %w{z y x}.sort.join("\n") %>
x
y
z
Block Rendering
Given a file named ‘example.sh’ containing:
#=begin :erb+0:
<%= %w{a b c}.map{ |x| "#{x}!" }.join("\n") %>
#=end
The rendered result of ‘example.sh’ will be:
#=begin :erb+3:
<%= %w{a b c}.map{ |x| "#{x}!" }.join("\n") %>
#=end
a!
b!
c!
C/C++
Sideline Example
Sideline example, where the erb comment is to the side of the text it will replace. Given a file named ‘example.c’ containing:
version = "?"; // :erb: version = "<%= 1+1 %>";
The rendered result of ‘example.c’ will be:
version = "2"; // :erb: version = "<%= 1+1 %>";
Multiline Example
Multi-line example, where the erb comment replaces multiple lines but is defined by a single line. Given a file named ‘example.c’ containing:
void main() {
//:erb+1: <%= %w{z(); y(); x();}.sort.join("\n").indent(2) %>
will be replaced
}
The rendered result of ‘example.c’ will be:
void main() {
//:erb+3: <%= %w{z(); y(); x();}.sort.join("\n").indent(2) %>
x();
y();
z();
}
Block Example
Block example, where the ERB comment replaces multiple lines and is defined by a block comment. Given a file named ‘example.c’ containing:
/* :erb+0:
<%= %w{a b c}.map{ |e| "\#include <#{e}.h>" }.join("\n") %>
*/
The rendered result of ‘example.c’ will be:
/* :erb+3:
<%= %w{a b c}.map{ |e| "\#include <#{e}.h>" }.join("\n") %>
*/
#include <a.h>
#include <b.h>
#include <c.h>
Javascript
Sideline Rendering
Given a file named ‘example.js’ containing:
var version = "?"; // :erb: var version = "<%= 1+1 %>";
The rendered result of ‘example.js’ will be:
var version = "2"; // :erb: var version = "<%= 1+1 %>";
Given a file named ‘example.js’ containing:
// Manifest generated 2009 #:erb: ^generated <%= 2009 %>
The rendered result of ‘example.js’ will be:
// Manifest generated 2009 #:erb: ^generated <%= 2009 %>
Multiline Rendering
Given a file named ‘example.js’ containing:
//:erb+1: <%= %w{z; y; x;}.sort.join("\n") %>
blah blah blah
The rendered result of ‘example.js’ will be:
//:erb+3: <%= %w{z; y; x;}.sort.join("\n") %>
x;
y;
z;
Block Rendering
Given a file named ‘example.js’ containing:
/* :erb+1:
<%= %w{z; y; x;}.sort.join("\n") %>
*/
blah blah blah
The rendered result of ‘example.js’ will be:
/* :erb+3:
<%= %w{z; y; x;}.sort.join("\n") %>
*/
x;
y;
z;
CSS
Sideline Rendering
Given a file named ‘example.css’ containing:
{ color: #000; } // :erb: { color: #<%= 1+1 %>00; }
The rendered result of ‘example.css’ will be:
{ color: #200; } // :erb: { color: #<%= 1+1 %>00; }
Rather then spell out the entire line we can use the front match marker. Given a file named ‘example.css’ containing:
{ color: #000; } // :erb: ^#<%= 2+2 %>00; }
The rendered result of ‘example.css’ will be:
{ color: #400; } // :erb: ^#<%= 2+2 %>00; }
Multiline Rendering
Given a file named ‘example.css’ containing:
//:erb+1: <%= %w{z; y; x;}.sort.join("\n") %>
blah blah blah
The rendered result of ‘example.css’ will be:
//:erb+3: <%= %w{z; y; x;}.sort.join("\n") %>
x;
y;
z;
Block Rendering
Given a file named ‘example.css’ containing:
/* :erb+1:
<%= %w{z; y; x;}.sort.join("\n") %>
*/
blah blah blah
The rendered result of ‘example.css’ will be:
/* :erb+3:
<%= %w{z; y; x;}.sort.join("\n") %>
*/
x;
y;
z;
XML/HTML
Sideline Example
Given a file named ‘example.xml’ containing:
<!-- ordianry comment -->
<root>
<version number="?"/> <!-- :erb: <version number="<%= 1+1 %>"/> -->
</root>
The rendered result of ‘example.xml’ will be:
<!-- ordianry comment -->
<root>
<version number="2"/> <!-- :erb: <version number="<%= 1+1 %>"/> -->
</root>
Multiline Rendering
Given a file named ‘example.xml’ containing:
<root>
<letters>
<!-- :erb+1: <%= %w{z y x}.sort.join("\n").indent(4) %> -->
blah blah blah
</letters>
</root>
The rendered result of ‘example.xml’ will be:
<root>
<letters>
<!-- :erb+3: <%= %w{z y x}.sort.join("\n").indent(4) %> -->
x
y
z
</letters>
</root>
Block Rendering
Given a file named ‘example.xml’ containing:
<root>
<!-- :erb+0:
<%= %w{a b c}.map{ |x| "<#{x}/>" }.join("\n") %>
-->
</root>
The rendered result of ‘example.xml’ will be:
<root>
<!-- :erb+3:
<%= %w{a b c}.map{ |x| "<#{x}/>" }.join("\n") %>
-->
<a/>
<b/>
<c/>
</root>
Commandline Interface
Given a file named ‘example.rb’ containing:
example # :erb: change <%= 1+1 %>
Rendering via the commandline:
$ erbside -o example.rb
The result will be:
change 2 # :erb: change <%= 1+1 %>