README.txt
README.txt
Last Update: Sun Jan 17 16:08:11 -0500 2010
dot/f_1.png

erbextensions

DESCRIPTION:

This package enhances the Standard ERB library, including providing:

  • A method for returning the processed contents of a named erb file (ERB.process_file). This makes it very easy to include one erb file within another erb file.

PROBLEMS:

None (known).

SYNOPSIS:

examples/template_wrapper.erb:
<%=
   require 'rubygems'
   require 'erbextensions'

   $recipient = "Dr. Frankenstein"
   $position  = "assistant"
   $source    = "Mad Scientist Monthly"
   $field     = "resurrection science"
   $skill     = "restraining experimental subjects"

   #
   # This call would be much cleaner with the 'relative' gem:
   # ERB::process_file(PathRelativeToCaller.new("template.erb"))
   #
   ERB::process_file(File.join(File.dirname(__FILE__), "template.erb"))
%>
examples/template.erb:
Dear <%= $recipient %>,
  I am writing to be considered for the <%= $position %> position that
you recently advertised in <%= $source %>.  I possess a keen interest
in <%= $field %> and am eager to apply my deep skills in
<%= $skill %>.  I have enclosed my resume for
your consideration.

Sincerely,
Igor

The example consists of a cover letter that is templated on a few variables in order to adjust the letter’s pitch to match the job being sought. After the template variables are initialized in template_wrapper.erb, an ERB.process_file call includes the expanded contents of template.erb. On the command line, run:

erb examples/template_wrapper.erb

to produce:

The output of erb examples/template_wrapper.erb:
Dear Dr. Frankenstein,
  I am writing to be considered for the assistant position that
you recently advertised in Mad Scientist Monthly.  I possess a keen interest
in resurrection science and am eager to apply my deep skills in
restraining experimental subjects.  I have enclosed my resume for
your consideration.

Sincerely,
Igor

RECOMMENDATIONS:

This gem best is used with the relative gem (relative.rubyforge.org). The relative gem upgrades the Ruby core and standard libraries to handle paths relative to source files, which makes referencing a file within an erb file much easier (see the comment in examples/template_wrapper.erb for a demonstration)

REQUIREMENTS:

Hoe is required but only for running the tests.

INSTALL:

sudo gem install erbextensions

AUTHORS:

Designing Patterns

SUPPORT:

Please post questions, concerns, or requests for enhancement to the forums on the project page. Alternatively, direct contact information for Designing Patterns can be found on the project page for this gem.

ENHANCEMENTS:

Please feel free to contact us with any ideas; we will try our best to enhance the software and respond to user requests. Of course, we are more likely to work on a particular enhancement if we know that there are users who want it. Designing Patterns provides contracting and consulting services, so if there is an enhancement that must get done (and in a specified time frame), please inquire about retaining our services!

LICENSE:

The license text can be found in the LICENSE file at the root of the distribution.

This package is licensed with an MIT license:

Copyright © 2008-2009 Designing Patterns

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

SHARE AND ENJOY!