Class: Amp::Help::HelpEntry
Overview
The generic HelpEntry class encapsulates a entry in the help system. The entry has text that it provides to the user, as well as a name. The base HelpEntry class does not track its own name, because well, that’s not useful! All it needs to know how to do is present its text when asked for it.
Direct Known Subclasses
Class Method Summary collapse
-
.from_file(filename) ⇒ HelpEntry
Singleton method that opens a file and returns a HelpEntry representing it.
Instance Method Summary collapse
-
#desc ⇒ Object
Describes the entry briefly, so if the user must pick, they have a decent shot at knowing what this entry is about.
-
#initialize(name, text = "") ⇒ HelpEntry
constructor
Creates a new HelpEntry, and registers it in the Help system, making it immediately available.
-
#text(options = {}) ⇒ String
Returns the help text to display for this entry.
Constructor Details
#initialize(name, text = "") ⇒ HelpEntry
Creates a new HelpEntry, and registers it in the Help system, making it immediately available. It is for this reason that all subclasses should call super
, because that registration is important!
121 122 123 124 |
# File 'lib/amp-front/help/help.rb', line 121 def initialize(name, text = "") @text = text HelpRegistry.register(name, self) end |
Class Method Details
.from_file(filename) ⇒ HelpEntry
Singleton method that opens a file and returns a HelpEntry representing it. What makes this method spiffy is that it tries to detect the type of file – markdown, ERb, et cetera, based on the file’s extension, and picks the appropriate class to represent that help entry.
The entry is registered under the name of the file - without any extensions - and the file’s full contents are provided as the initial text.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/amp-front/help/help.rb', line 100 def from_file(filename) klass = case File.extname(filename).downcase when ".md", ".markdown" MarkdownHelpEntry when ".erb" ErbHelpEntry else HelpEntry end name = File.basename(filename).split(".", 2).first klass.new(name, File.read(filename)) end |
Instance Method Details
#desc ⇒ Object
Describes the entry briefly, so if the user must pick, they have a decent shot at knowing what this entry is about. Hopefully.
In the generic case, use the text and grab the first few words.
147 148 149 |
# File 'lib/amp-front/help/help.rb', line 147 def desc %Q{a regular help entry ("#{text.split[0..5].join(" ")} ...")} end |
#text(options = {}) ⇒ String
Returns the help text to display for this entry.
In the generic case, just return the @text variable.
136 137 138 |
# File 'lib/amp-front/help/help.rb', line 136 def text( = {}) @text end |