Module: Acclaim::Command::Help::Template

Defined in:
lib/acclaim/command/help/template.rb

Overview

Manages help templates.

Since:

  • 0.0.1

Class Method Summary collapse

Class Method Details

.create_from(template_file) ⇒ Object

Creates a new ERB instance with the contents of template.

Since:

  • 0.0.1



25
26
27
# File 'lib/acclaim/command/help/template.rb', line 25

def create_from(template_file)
  ERB.new load(template_file), nil, '%<>'
end

.folderObject

Returns the template folder relative to this directory.

Since:

  • 0.0.1



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.

Since:

  • 0.0.1



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/acclaim/command/help/template.rb', line 31

def for(*args)
  template_options, command = args.extract_ribbon!, args.shift
  template = create_from template_options.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.

Since:

  • 0.0.1



20
21
22
# File 'lib/acclaim/command/help/template.rb', line 20

def load(template_file)
  File.read File.join(folder, template_file)
end