Sha256: d647863e9eda477a4e2a93b70f138253395d994dfa7b89d18243a50468bfb101

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

module Vedeu

  module API

    # Provides colour and style helpers for use in the {API::Interface},
    # {API::Line} and {API::Stream} classes.
    #
    # @api public
    module Helpers

      # Define either or both foreground and background colours for an
      # interface, line or a stream.
      #
      # @param values [Hash]
      #
      # @example
      #   interface 'my_interface' do
      #     colour background: '#000000', foreground: '#ffffff'
      #     ...
      #
      #   line do
      #     colour background: '#000000', foreground: '#ffffff'
      #     ...
      #
      #   stream do
      #     colour background: '#000000', foreground: '#ffffff'
      #     ...
      #
      # @raise [InvalidSyntax] When the values parameter does not contain
      #   required keys.
      # @return [Hash]
      def colour(values)
        unless values.key?(:foreground) || values.key?(:background)
          fail InvalidSyntax, '#colour expects a Hash containing ' \
            ':foreground or :background or both.'
        end

        attributes[:colour] = values
      end

      # Define a style or styles for an interface, line or a stream.
      #
      # @param values [Array|String]
      # @param block  [Proc]
      #
      # @example
      #   interface 'my_interface' do
      #     style 'normal'
      #     ...
      #
      #   line do
      #     style ['bold', 'underline']
      #     ...
      #
      #   stream do
      #     style 'blink'
      #     ...
      #
      # @return [Array]
      def style(values = [], &block)
        if block_given?
          attributes[:streams] << API::Stream
                                    .build({ style: Array(values) }, &block)

        else
          Array(values).each { |value| attributes[:style] << value }

        end
      end

    end # Helpers

  end # API

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.4 lib/vedeu/api/helpers.rb
vedeu-0.2.3 lib/vedeu/api/helpers.rb