class HighLine::ListRenderer
This class is a utility for quickly and easily laying out lists to be used by HighLine.
Attributes
@return [HighLine] context
Items list @return [Array]
@return [Symbol] the current mode the List is being rendered @see initialize for more details see mode parameter of initialize
Changes the behaviour of some modes. Example, in :inline mode the option is treated as the ‘end separator’ (defaults to “ or ”) @return option parameter that changes the behaviour of some modes.
Public Class Methods
Source
# File lib/highline/list_renderer.rb, line 62 def initialize(items, mode = :rows, option = nil, highline) @highline = highline @mode = mode @option = option @items = render_list_items(items) end
The only required parameters are items and highline. @param items [Array] the Array of items to list @param mode [Symbol] controls how that list is formed @param option has different effects, depending on the mode. @param highline [HighLine] a HighLine instance to direct the output to.
Recognized modes are:
:columns_across-
items will be placed in columns, flowing from left to right. If given, option is the number of columns to be used. When absent, columns will be determined based on wrap_at or a default of 80 characters.
:columns_down-
Identical to
:columns_across, save flow goes down. :uneven_columns_across-
Like
:columns_acrossbut each column is sized independently. :uneven_columns_down-
Like
:columns_downbut each column is sized independently. :inline-
All items are placed on a single line. The last two items are separated by option or a default of “ or ”. All other items are separated by “, ”.
:rows-
The default mode. Each of the items is placed on its own line. The option parameter is ignored in this mode.
Each member of the items Array is passed through ERb and thus can contain their own expansions. Color escape expansions do not contribute to the final field width.
Public Instance Methods
Source
# File lib/highline/list_renderer.rb, line 71 def render return "" if items.empty? case mode when :inline list_inline_mode when :columns_across list_columns_across_mode when :columns_down list_columns_down_mode when :uneven_columns_across list_uneven_columns_mode when :uneven_columns_down list_uneven_columns_down_mode else list_default_mode end end
Render the list using the appropriate mode and options. @return [String] rendered list as String