;TI" Subject: Addressing Needs
;TI"
;TI"Community:
;TI"
;TI"TJust wanted to send a quick note assuring that your needs are being addressed.
;TI"
;TI"RI want you to know that my team will keep working on the issues, especially:
;TI"
;TI" * Run Ruby Quiz
;TI" * Document Modules
;TI") * Answer Questions on Ruby Talk
;TI"
;TI"Thanks for your patience.
;TI"
;TI"James Edward Gray II
;T;0S; ;
i;I"Ruby in HTML;T@o;
;[I"_ERB is often used in .rhtml files (HTML with embedded Ruby). Notice the need in ;TI"^this example to provide a special binding when the template is run, so that the instance ;TI"5variables in the Product object can be resolved.;T@o;;[HI"require "erb"
;TI"
;TI""# Build template data class.
;TI"class Product
;TI"0 def initialize( code, name, desc, cost )
;TI" @code = code
;TI" @name = name
;TI" @desc = desc
;TI" @cost = cost
;TI"
;TI" @features = [ ]
;TI" end
;TI"
;TI"" def add_feature( feature )
;TI" @features << feature
;TI" end
;TI"
;TI", # Support templating of member data.
;TI" def get_binding
;TI" binding
;TI" end
;TI"
;TI"
# ...
;TI" end
;TI"
;TI"# Create template.
;TI"template = %{
;TI"
;TI"? Ruby Toys -- <%= @name %>
;TI"
;TI"
;TI"0 <%= @name %> (<%= @code %>)
;TI" <%= @desc %>
;TI"
;TI"
;TI") <% @features.each do |f| %>
;TI"( - <%= f %>
;TI" <% end %>
;TI"
;TI"
;TI"
;TI"! <% if @cost < 10 %>
;TI"+ Only <%= @cost %>!!!
;TI" <% else %>
;TI") Call for a price, today!
;TI" <% end %>
;TI"
;TI"
;TI"
;TI"
;TI"}.gsub(/^ /, '')
;TI"
;TI"rhtml = ERB.new(template)
;TI"
;TI"# Set up template data.
;TI"#toy = Product.new( "TZ-1002",
;TI"& "Rubysapien",
;TI"M "Geek's Best Friend! Responds to Ruby commands...",
;TI"! 999.95 )
;TI"Jtoy.add_feature("Listens for verbal commands in the Ruby language!")
;TI"@toy.add_feature("Ignores Perl, Java, and all C variants.")
;TI".toy.add_feature("Karate-Chop Action!!!")
;TI"4toy.add_feature("Matz signature on left leg.")
;TI"?toy.add_feature("Gem studded eyes... Rubies, of course!")
;TI"
;TI"# Produce result.
;TI" rhtml.run(toy.get_binding)
;T;0o;
;[I"1Generates (some blank lines removed):;T@o;;[I"
;TI"; Ruby Toys -- Rubysapien
;TI"
;TI"
;TI"' Rubysapien (TZ-1002)
;TI"B Geek's Best Friend! Responds to Ruby commands...
;TI"
;TI"
;TI"O - Listens for verbal commands in the Ruby language!
;TI"E - Ignores Perl, Java, and all C variants.
;TI"3 - Karate-Chop Action!!!
;TI"9 - Matz signature on left leg.
;TI"D - Gem studded eyes... Rubies, of course!
;TI"
;TI"
;TI"
;TI"' Call for a price, today!
;TI"
;TI"
;TI"
;TI"
;T;0S; ;
i;I"
Notes;T@o;
;[I"UThere are a variety of templating solutions available in various Ruby projects. ;TI"SFor example, RDoc, distributed with Ruby, uses its own template engine, which ;TI"can be reused elsewhere.;T@o;
;[I"?Other popular engines could be found in the corresponding ;TI"M{Category}[https://www.ruby-toolbox.com/categories/template_engines] of ;TI"The Ruby Toolbox.;T:
@fileI"lib/erb.rb;T:0@omit_headings_from_table_of_contents_below0o;;[ ;@;0o;;[ ;@;0o;;[ ;@;0o;;[ ;@;0;0;0[ [
I"
encoding;TI"R;T:publicFI"lib/erb.rb;T[
I"
filename;TI"RW;T;F@#[
I"lineno;T@&;F@#[
I"src;T@";F@#[U:RDoc::Constant[i I"NOT_GIVEN;TI"ERB::NOT_GIVEN;T:private0o;;[ ;@;0@@cRDoc::NormalClass0U;[i I"ZERO_SAFE_LEVELS;TI"ERB::ZERO_SAFE_LEVELS;T;0o;;[ ;@;0@@@20[ [[I"
class;T[[;[[I"new;T@#[I"version;T@#[:protected[ [;[ [I"
instance;T[[;[[I"def_class;T@#[I"def_method;T@#[I"def_module;T@#[I"location=;T@#[I"make_compiler;T@#[I"result;T@#[I"result_with_hash;T@#[I"run;T@#[I"set_eoutvar;T@#[;[ [;[[I"new_toplevel;T@#[ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@@cRDoc::TopLevel