Class: HammerCLI::Help::TextBuilder
- Inherits:
-
Object
- Object
- HammerCLI::Help::TextBuilder
- Defined in:
- lib/hammer_cli/help/text_builder.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
Instance Method Summary collapse
- #at(path = []) {|sub_builder| ... } ⇒ Object
- #find_item(item_id) ⇒ Object
- #indent(content, indentation = nil) ⇒ Object
-
#initialize(richtext = false) ⇒ TextBuilder
constructor
A new instance of TextBuilder.
- #insert(mode, item_id) {|sub_builder| ... } ⇒ Object
- #list(items, options = {}, &block) ⇒ Object
- #note(content, options = {}) ⇒ Object
- #section(label, options = {}) {|sub_builder| ... } ⇒ Object
- #string ⇒ Object
- #text(content, options = {}) ⇒ Object
Constructor Details
#initialize(richtext = false) ⇒ TextBuilder
Returns a new instance of TextBuilder.
8 9 10 11 |
# File 'lib/hammer_cli/help/text_builder.rb', line 8 def initialize(richtext = false) @richtext = richtext @definition = HammerCLI::Help::Definition.new end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
6 7 8 |
# File 'lib/hammer_cli/help/text_builder.rb', line 6 def definition @definition end |
Instance Method Details
#at(path = []) {|sub_builder| ... } ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/hammer_cli/help/text_builder.rb', line 42 def at(path = []) item = path.empty? ? self : @definition.at(path) sub_builder = TextBuilder.new(@richtext) sub_builder.definition = item.definition yield(sub_builder) item.definition = sub_builder.definition end |
#find_item(item_id) ⇒ Object
38 39 40 |
# File 'lib/hammer_cli/help/text_builder.rb', line 38 def find_item(item_id) @definition.find_item(item_id) end |
#indent(content, indentation = nil) ⇒ Object
56 57 58 |
# File 'lib/hammer_cli/help/text_builder.rb', line 56 def indent(content, indentation = nil) HammerCLI::Help::AbstractItem.indent(content, indentation) end |
#insert(mode, item_id) {|sub_builder| ... } ⇒ Object
50 51 52 53 54 |
# File 'lib/hammer_cli/help/text_builder.rb', line 50 def insert(mode, item_id) sub_builder = TextBuilder.new(@richtext) yield(sub_builder) @definition.insert_definition(mode, item_id, sub_builder.definition) end |
#list(items, options = {}, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/hammer_cli/help/text_builder.rb', line 25 def list(items, = {}, &block) return if items.empty? @definition << HammerCLI::Help::List.new(items, , &block) end |
#note(content, options = {}) ⇒ Object
21 22 23 |
# File 'lib/hammer_cli/help/text_builder.rb', line 21 def note(content, = {}) @definition << HammerCLI::Help::Note.new(content, ) end |
#section(label, options = {}) {|sub_builder| ... } ⇒ Object
31 32 33 34 35 36 |
# File 'lib/hammer_cli/help/text_builder.rb', line 31 def section(label, = {}, &block) sub_builder = TextBuilder.new(@richtext) yield(sub_builder) if block_given? [:richtext] ||= @richtext @definition << HammerCLI::Help::Section.new(label, sub_builder.definition, ) end |
#string ⇒ Object
13 14 15 |
# File 'lib/hammer_cli/help/text_builder.rb', line 13 def string @definition.build_string end |