--- !ruby/object:RDoc::RI::ClassDescription 
attributes: 
- !ruby/object:RDoc::RI::Attribute 
  comment: 
  - !ruby/struct:RDoc::Markup::Flow::P 
    :body: The optional <em>filename</em> argument passed to Kernel#eval when the ERB code is run
  name: filename
  rw: RW
- !ruby/object:RDoc::RI::Attribute 
  comment: 
  - !ruby/struct:RDoc::Markup::Flow::P 
    :body: The Ruby code generated by ERB
  name: src
  rw: R
class_methods: 
- !ruby/object:RDoc::RI::MethodSummary 
  name: new
- !ruby/object:RDoc::RI::MethodSummary 
  name: version
comment: 
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 1
  :text: ERB -- Ruby Templating
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 2
  :text: Introduction
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: ERB provides an easy to use but powerful templating system for Ruby. Using ERB, actual Ruby code can be added to any plain text document for the purposes of generating document information details and/or flow control.
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: "A very simple example is this:"
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "  require 'erb'\n\n  x = 42\n  template = ERB.new &lt;&lt;-EOF\n    The value of x is: &lt;%= x %&gt;\n  EOF\n  puts template.result(binding)\n"
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: "<em>Prints:</em> The value of x is: 42"
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: More complex examples are given below.
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 2
  :text: Recognized Tags
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: "ERB recognizes certain tags in the provided template and converts them based on the rules below:"
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "  &lt;% Ruby code -- inline with output %&gt;\n  &lt;%= Ruby expression -- replace with result %&gt;\n  &lt;%# comment -- ignored -- useful in testing %&gt;\n  % a line of Ruby code -- treated as &lt;% line %&gt; (optional -- see ERB.new)\n  %% replaced with % if first thing on a line and % processing is used\n  &lt;%% or %%&gt; -- replace with &lt;% or %&gt; respectively\n"
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: All other text is passed through ERB filtering unchanged.
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 2
  :text: Options
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: "There are several settings you can change when you use ERB:"
- !ruby/object:RDoc::Markup::Flow::LIST 
  contents: 
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: the nature of the tags that are recognized;
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: the value of <tt>$SAFE</tt> under which the template is run;
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: the binding used to resolve local variables in the template.
  type: :BULLET
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: See the ERB.new and ERB#result methods for more detail.
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 2
  :text: Character encodings
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: ERB (or ruby code generated by ERB) returns a string in the same character encoding as the input string. When the input string has a magic comment, however, it returns a string in the encoding specified by the magic comment.
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "  # -*- coding: UTF-8 -*-\n  require 'erb'\n\n  template = ERB.new &lt;&lt;EOF\n  &lt;%#-*- coding: Big5 -*-%&gt;\n    __ENCODING__ is &lt;%= __ENCODING__ %&gt;.\n  EOF\n  puts template.result\n"
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: <em>Prints:</em> __ENCODING__ is Big5.
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 2
  :text: Examples
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 3
  :text: Plain Text
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: ERB is useful for any generic templating situation. Note that in this example, we use the convenient &quot;% at start of line&quot; tag, and we quote the template literally with <tt>%q{...}</tt> to avoid trouble with the backslash.
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "  require &quot;erb&quot;\n\n  # Create template.\n  template = %q{\n    From:  James Edward Gray II &lt;james@grayproductions.net&gt;\n    To:  &lt;%= to %&gt;\n    Subject:  Addressing Needs\n\n    &lt;%= to[/\\w+/] %&gt;:\n\n    Just wanted to send a quick note assuring that your needs are being\n    addressed.\n\n    I want you to know that my team will keep working on the issues,\n    especially:\n\n    &lt;%# ignore numerous minor requests -- focus on priorities %&gt;\n    % priorities.each do |priority|\n      * &lt;%= priority %&gt;\n    % end\n\n    Thanks for your patience.\n\n    James Edward Gray II\n  }.gsub(/^  /, '')\n\n  message = ERB.new(template, 0, &quot;%&lt;&gt;&quot;)\n\n  # Set up template data.\n  to = &quot;Community Spokesman &lt;spokesman@ruby_community.org&gt;&quot;\n  priorities = [ &quot;Run Ruby Quiz&quot;,\n                 &quot;Document Modules&quot;,\n                 &quot;Answer Questions on Ruby Talk&quot; ]\n\n  # Produce result.\n  email = message.result\n  puts email\n"
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: <em>Generates:</em>
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "  From:  James Edward Gray II &lt;james@grayproductions.net&gt;\n  To:  Community Spokesman &lt;spokesman@ruby_community.org&gt;\n  Subject:  Addressing Needs\n\n  Community:\n\n  Just wanted to send a quick note assuring that your needs are being addressed.\n\n  I want you to know that my team will keep working on the issues, especially:\n\n      * Run Ruby Quiz\n      * Document Modules\n      * Answer Questions on Ruby Talk\n\n  Thanks for your patience.\n\n  James Edward Gray II\n"
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 3
  :text: Ruby in HTML
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: ERB is often used in <tt>.rhtml</tt> files (HTML with embedded Ruby). Notice the need in this example to provide a special binding when the template is run, so that the instance variables in the Product object can be resolved.
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "  require &quot;erb&quot;\n\n  # Build template data class.\n  class Product\n    def initialize( code, name, desc, cost )\n      @code = code\n      @name = name\n      @desc = desc\n      @cost = cost\n\n      @features = [ ]\n    end\n\n    def add_feature( feature )\n      @features &lt;&lt; feature\n    end\n\n    # Support templating of member data.\n    def get_binding\n      binding\n    end\n\n    # ...\n  end\n\n  # Create template.\n  template = %{\n    &lt;html&gt;\n      &lt;head&gt;&lt;title&gt;Ruby Toys -- &lt;%= @name %&gt;&lt;/title&gt;&lt;/head&gt;\n      &lt;body&gt;\n\n        &lt;h1&gt;&lt;%= @name %&gt; (&lt;%= @code %&gt;)&lt;/h1&gt;\n        &lt;p&gt;&lt;%= @desc %&gt;&lt;/p&gt;\n\n        &lt;ul&gt;\n          &lt;% @features.each do |f| %&gt;\n            &lt;li&gt;<b>&lt;%= f %&gt;</b>&lt;/li&gt;\n          &lt;% end %&gt;\n        &lt;/ul&gt;\n\n        &lt;p&gt;\n          &lt;% if @cost &lt; 10 %&gt;\n            <b>Only &lt;%= @cost %&gt;!!!</b>\n          &lt;% else %&gt;\n             Call for a price, today!\n          &lt;% end %&gt;\n        &lt;/p&gt;\n\n      &lt;/body&gt;\n    &lt;/html&gt;\n  }.gsub(/^  /, '')\n\n  rhtml = ERB.new(template)\n\n  # Set up template data.\n  toy = Product.new( &quot;TZ-1002&quot;,\n                     &quot;Rubysapien&quot;,\n                     &quot;Geek's Best Friend!  Responds to Ruby commands...&quot;,\n                     999.95 )\n  toy.add_feature(&quot;Listens for verbal commands in the Ruby language!&quot;)\n  toy.add_feature(&quot;Ignores Perl, Java, and all C variants.&quot;)\n  toy.add_feature(&quot;Karate-Chop Action!!!&quot;)\n  toy.add_feature(&quot;Matz signature on left leg.&quot;)\n  toy.add_feature(&quot;Gem studded eyes... Rubies, of course!&quot;)\n\n  # Produce result.\n  rhtml.run(toy.get_binding)\n"
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: <em>Generates (some blank lines removed):</em>
- !ruby/struct:RDoc::Markup::Flow::VERB 
  :body: "   &lt;html&gt;\n     &lt;head&gt;&lt;title&gt;Ruby Toys -- Rubysapien&lt;/title&gt;&lt;/head&gt;\n     &lt;body&gt;\n\n       &lt;h1&gt;Rubysapien (TZ-1002)&lt;/h1&gt;\n       &lt;p&gt;Geek's Best Friend!  Responds to Ruby commands...&lt;/p&gt;\n\n       &lt;ul&gt;\n           &lt;li&gt;<b>Listens for verbal commands in the Ruby language!</b>&lt;/li&gt;\n           &lt;li&gt;<b>Ignores Perl, Java, and all C variants.</b>&lt;/li&gt;\n           &lt;li&gt;<b>Karate-Chop Action!!!</b>&lt;/li&gt;\n           &lt;li&gt;<b>Matz signature on left leg.</b>&lt;/li&gt;\n           &lt;li&gt;<b>Gem studded eyes... Rubies, of course!</b>&lt;/li&gt;\n       &lt;/ul&gt;\n\n       &lt;p&gt;\n            Call for a price, today!\n       &lt;/p&gt;\n\n     &lt;/body&gt;\n   &lt;/html&gt;\n"
- !ruby/struct:RDoc::Markup::Flow::H 
  :level: 2
  :text: Notes
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: "There are a variety of templating solutions available in various Ruby projects:"
- !ruby/object:RDoc::Markup::Flow::LIST 
  contents: 
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: ERB's big brother, eRuby, works the same but is written in C for speed;
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: Amrita (smart at producing HTML/XML);
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: cs/Template (written in C for speed);
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: RDoc, distributed with Ruby, uses its own template engine, which can be reused elsewhere;
  - !ruby/struct:RDoc::Markup::Flow::LI 
    :label: "*"
    :body: and others; search the RAA.
  type: :BULLET
- !ruby/struct:RDoc::Markup::Flow::P 
  :body: Rails, the web application framework, uses ERB to create views.
constants: 
- !ruby/object:RDoc::RI::Constant 
  comment: 
  name: Revision
  value: "'$Date:: 2009-01-17 21:20:08 +0900#$'"
full_name: ERB
includes: []

instance_methods: 
- !ruby/object:RDoc::RI::MethodSummary 
  name: def_class
- !ruby/object:RDoc::RI::MethodSummary 
  name: def_method
- !ruby/object:RDoc::RI::MethodSummary 
  name: def_module
- !ruby/object:RDoc::RI::MethodSummary 
  name: result
- !ruby/object:RDoc::RI::MethodSummary 
  name: run
- !ruby/object:RDoc::RI::MethodSummary 
  name: set_eoutvar
name: ERB
superclass: Object
