ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ???????????????????????????????????? ???????????????????????????????????? ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ???????????????????????????????????? ???????????????????????????????????? U:RDoc::NormalClass[iI"ERB:ET@I" Object;To:RDoc::Markup::Document: @parts[o;;[=S:RDoc::Markup::Heading: leveli: textI"ERB -- Ruby Templating;To:RDoc::Markup::BlankLineS; ; i; I"Introduction;T@o:RDoc::Markup::Paragraph;[I"QERB provides an easy to use but powerful templating system for Ruby. Using ;TI"KERB, actual Ruby code can be added to any plain text document for the ;TI"Mpurposes of generating document information details and/or flow control.;T@o; ;[I"#A very simple example is this:;T@o:RDoc::Markup::Verbatim;[ I"require 'erb' ;TI" ;TI" x = 42 ;TI"template = ERB.new <<-EOF ;TI"# The value of x is: <%= x %> ;TI" EOF ;TI"#puts template.result(binding) ;T: @format0o; ;[I"+Prints: The value of x is: 42;T@o; ;[I"+More complex examples are given below.;T@S; ; i; I"Recognized Tags;T@o; ;[I"RERB recognizes certain tags in the provided template and converts them based ;TI"on the rules below:;T@o;;[ I"+<% Ruby code -- inline with output %> ;TI"3<%= Ruby expression -- replace with result %> ;TI"d<%# comment -- ignored -- useful in testing %> (`<% #` doesn't work. Don't use Ruby comments.) ;TI"N% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new) ;TI"J%% replaced with % if first thing on a line and % processing is used ;TI"6<%% or %%> -- replace with <% or %> respectively ;T;0o; ;[I">All other text is passed through ERB filtering unchanged.;T@S; ; i; I" Options;T@o; ;[I"@There are several settings you can change when you use ERB:;To:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0;[o; ;[I"0the nature of the tags that are recognized;;To;;0;[o; ;[I"Athe binding used to resolve local variables in the template.;T@o; ;[I" ;TI"4 \_\_ENCODING\_\_ is <%= \_\_ENCODING\_\_ %>. ;TI" EOF ;TI"puts template.result ;T;0o; ;[I"/Prints: \_\_ENCODING\_\_ is Big5.;T@S; ; i; I" Examples;T@S; ; i; I"Plain Text;T@o; ;[I"`ERB is useful for any generic templating situation. Note that in this example, we use the ;TI"Sconvenient "% at start of line" tag, and we quote the template literally with ;TI":%q{...} to avoid trouble with the backslash.;T@o;;[*I"require "erb" ;TI" ;TI"# Create template. ;TI"template = %q{ ;TI"? From: James Edward Gray II ;TI" To: <%= to %> ;TI"" Subject: Addressing Needs ;TI" ;TI" <%= to[/\w+/] %>: ;TI" ;TI"K Just wanted to send a quick note assuring that your needs are being ;TI" addressed. ;TI" ;TI"H I want you to know that my team will keep working on the issues, ;TI" especially: ;TI" ;TI"D <%# ignore numerous minor requests -- focus on priorities %> ;TI"' % priorities.each do |priority| ;TI" * <%= priority %> ;TI" % end ;TI" ;TI"! Thanks for your patience. ;TI" ;TI" James Edward Gray II ;TI"}.gsub(/^ /, '') ;TI" ;TI"3message = ERB.new(template, trim_mode: "%<>") ;TI" ;TI"# Set up template data. ;TI"?to = "Community Spokesman " ;TI"%priorities = [ "Run Ruby Quiz", ;TI"( "Document Modules", ;TI"6 "Answer Questions on Ruby Talk" ] ;TI" ;TI"# Produce result. ;TI"email = message.result ;TI"puts email ;T;0o; ;[I"Generates:;T@o;;[I"=From: James Edward Gray II ;TI"=To: Community Spokesman ;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;;[;I"lib/erb/version.rb;T;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[iI"NOT_GIVEN;TI"ERB::NOT_GIVEN;T: private0o;;[;@;0@@cRDoc::NormalClass0U;[iI" VERSION;TI"ERB::VERSION;T;0o;;[;@;0@@@-0[[[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[i0o;;[;0;0[ @I"lib/erb/compiler.rb;TI"lib/erb/def_method.rb;TI"lib/erb/util.rb;T@@cRDoc::TopLevel