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"

Parameters:

  • template (String)

    Source of the ERB template.

Returns:

  • (String)

    Result of the rendered template.



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

def erb(template)
  ERB.new(template).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'

Parameters:

  • template_path (String)

    The relative path of the ERB template.

Returns:

  • (String)

    Result of the rendered template.



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

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