Module: Ronin::Templates::Erb

Includes:
Template
Defined in:
lib/ronin/templates/erb.rb

Overview

The Erb module uses the Template module to find and render Embedded Ruby (ERB) templates.

Instance Method Summary collapse

Methods included from Template

#enter_template, #find_template, #read_template, #template_dir, #template_dirs

Instance Method Details

#erb(template) ⇒ String

Renders the inline ERB template in the scope of the object.

Examples:

@user = 'lolcats'

erb %{
USER: <%= @user %>
PASSWORD: <%= @user.reverse %>
}
# => "\nUSER: lolcats\nPASSWORD: staclol\n"

53
54
55
# File 'lib/ronin/templates/erb.rb', line 53

def erb(template)
  ERB.new(template,nil,'-').result(binding)
end

#erb_file(template_path) ⇒ String

Renders an ERB template file in the scope of the object.

Examples:

erb_file 'path/to/template.erb'

71
72
73
74
75
# File 'lib/ronin/templates/erb.rb', line 71

def erb_file(template_path)
  read_template(template_path) do |template|
    erb(template)
  end
end