Class: Amp::Help::ErbHelpEntry

Inherits:
HelpEntry show all
Defined in:
lib/amp-front/help/help.rb

Overview

Represents a help entry that filters its help text through ERB before returning.

This is useful because some entries might have programmatic logic to them - for example, the built in “commands” entry lists all the commands in the user’s current workflow. That requires logic, and while we used to simply have that be its own class, we can now stuff it in an ERB file.

Note: if you want to use pretty text in an ERB entry, you will have to use ruby code to do so. Use the following shortcuts:

<%= "Ampfiles".bold.underline %> # bolds and underlines
<%= "some.code()".black.on_green %> # changes to black and sets green bg color

See our extensions to the String class for more.

Instance Method Summary collapse

Methods inherited from HelpEntry

#desc, from_file, #initialize

Constructor Details

This class inherits a constructor from Amp::Help::HelpEntry

Instance Method Details

#text(options = {}) ⇒ String

Returns the help text to display for this entry.

For an ERB entry, we run ERB on the text in the entry, while also exposing the options variable as local, so the ERB can access the user’s runtime options.

Parameters:

  • options (Hash) (defaults to: {})

    the options for the process - that way the help commands can access the user’s run-time options and global configuration. For example, if the user passes in –verbose or –quiet, each help entry could handle that differently. Who are we to judge?

Returns:

  • (String)

    the help text for the entry.



205
206
207
208
209
210
# File 'lib/amp-front/help/help.rb', line 205

def text(options = {})
  full_text = super(options)
  
  erb = ERB.new(full_text, 0, "-")
  erb.result binding
end