Module: Acclaim::Command::Help::Template
- Defined in:
- lib/acclaim/command/help/template.rb
Overview
Manages help templates.
Class Method Summary collapse
-
.create_from(template_file) ⇒ Object
Creates a new ERB instance with the contents of
template
. -
.folder ⇒ Object
Returns the
template
folder relative to this directory. -
.for(*args) ⇒ Object
Computes the result of the template
file
using thecommand
‘s binding. -
.load(template_file) ⇒ Object
Loads the contents of a template file from the template #folder.
Class Method Details
.create_from(template_file) ⇒ Object
Creates a new ERB instance with the contents of template
.
25 26 27 |
# File 'lib/acclaim/command/help/template.rb', line 25 def create_from(template_file) ERB.new load(template_file), nil, '%<>' end |
.folder ⇒ Object
Returns the template
folder relative to this directory.
15 16 17 |
# File 'lib/acclaim/command/help/template.rb', line 15 def folder File.join File.dirname(__FILE__), 'template' end |
.for(*args) ⇒ Object
Computes the result of the template file
using the command
‘s binding.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/acclaim/command/help/template.rb', line 31 def for(*args) , command = args.extract_ribbon!, args.shift template = create_from .file? 'command.erb' command_binding = command.instance_eval { binding } # Since blocks are closures, the binding has access to the # template_options ribbon: # # p command_binding.eval 'template_options' # => {} template.result command_binding end |
.load(template_file) ⇒ Object
Loads the contents of a template file from the template #folder.
20 21 22 |
# File 'lib/acclaim/command/help/template.rb', line 20 def load(template_file) File.read File.join(folder, template_file) end |