Sha256: ac317fd76cea675e75390a8552bb2485c90ac1d076e24ed35797f59392f60d42

Contents?: true

Size: 1.63 KB

Versions: 31

Compression:

Stored size: 1.63 KB

Contents

require 'hammer_cli/help/definition'

module HammerCLI
  module Help
    class TextBuilder
      attr_accessor :definition

      def initialize(richtext = false)
        @richtext = richtext
        @definition = HammerCLI::Help::Definition.new
      end

      def string
        @definition.build_string
      end

      def text(content, options = {})
        @definition << HammerCLI::Help::Text.new(content, options)
      end

      def note(content, options = {})
        @definition << HammerCLI::Help::Note.new(content, options)
      end

      def list(items, options = {}, &block)
        return if items.empty?

        @definition << HammerCLI::Help::List.new(items, options, &block)
      end

      def section(label, options = {}, &block)
        sub_builder = TextBuilder.new(@richtext)
        yield(sub_builder) if block_given?
        options[:richtext] ||= @richtext
        @definition << HammerCLI::Help::Section.new(label, sub_builder.definition, options)
      end

      def find_item(item_id)
        @definition.find_item(item_id)
      end

      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

      def insert(mode, item_id)
        sub_builder = TextBuilder.new(@richtext)
        yield(sub_builder)
        @definition.insert_definition(mode, item_id, sub_builder.definition)
      end

      def indent(content, indentation = nil)
        HammerCLI::Help::AbstractItem.indent(content, indentation)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
hammer_cli-3.13.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.12.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.10.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.9.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.8.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.7.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.5.1 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.6.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.5.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.4.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.3.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.2.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.1.1 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.0.2 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.1.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.0.1 lib/hammer_cli/help/text_builder.rb
hammer_cli-3.0.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-2.5.1 lib/hammer_cli/help/text_builder.rb
hammer_cli-2.5.0 lib/hammer_cli/help/text_builder.rb
hammer_cli-2.3.1 lib/hammer_cli/help/text_builder.rb