Sha256: 601f87734040e4d1df2a2c81209a9895ef58c7296ffe985f4ed509e44b6bd0e0

Contents?: true

Size: 1.78 KB

Versions: 42

Compression:

Stored size: 1.78 KB

Contents

module Hirb
  # This module is meant to be extended to provide methods for use in a console/irb shell.
  # For example:
  #    >> extend Hirb::Console
  #    >> view 'some string', :class=>Some::String::Formatter
  #    >> table [[:row1], [:row2]]
  module Console
    class<<self
      # A console version of render_output() which takes its same options but allows for shorthand. All options are passed to
      # the helper except for the formatter options. Formatter options are :class, :method and :output_method.
      # Examples:
      #   render_output output, :class=>:tree :type=>:directory
      #   # is the same as:
      #   render_output output, :class=>:tree, :options=> {:type=>:directory}
      #
      def render_output(output, options={})
        View.load_config unless View.config_loaded?
        View.render_output(output, options.merge(:console=>true))
      end

      # Takes same arguments and options as render_output() but returns formatted output instead of rendering it.
      def format_output(output, options={}, &block)
        View.load_config unless View.config_loaded?
        View.formatter.format_output(output, options.merge(:console=>true), &block)
      end
    end

    # Renders a table for the given object. Takes same options as Hirb::Helpers::Table.render.
    def table(output, options={})
      Console.render_output(output, options.merge(:class=>"Hirb::Helpers::AutoTable"))
    end

    # Renders any specified view for the given object. Takes same options as Hirb::View.render_output.
    def view(output, options={})
      Console.render_output(output, options)
    end

    # Renders a menu given an array using Hirb::Menu.render.
    def menu(output, options={}, &block)
      Console.format_output(output, options.merge(:class=>"Hirb::Menu"), &block)
    end
  end
end

Version data entries

42 entries across 41 versions & 5 rubygems

Version Path
hirber-0.8.7 lib/hirb/console.rb
hirber-0.8.6 lib/hirb/console.rb
hirber-0.8.5 lib/hirb/console.rb
hirber-0.8.4 lib/hirb/console.rb
hirber-0.8.2 lib/hirb/console.rb
hirber-0.8.1 lib/hirb/console.rb
hirber-0.8.0 lib/hirb/console.rb
hirb-0.7.3 lib/hirb/console.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/hirb-0.7.1/lib/hirb/console.rb
hirb-0.7.2 lib/hirb/console.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
climine-0.0.2 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
climine-0.0.1 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/lib/hirb/console.rb
hirb-0.7.1 lib/hirb/console.rb
hirb-0.7.0 lib/hirb/console.rb
hirb-0.6.2 lib/hirb/console.rb