Class: Guard::Sass::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/sass/formatter.rb

Overview

The formatter handles providing output to the user.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Formatter

Returns a new instance of Formatter.

Parameters:

  • opts (Hash) (defaults to: {})
  • otps (Hash)

    a customizable set of options


10
11
12
# File 'lib/guard/sass/formatter.rb', line 10

def initialize(opts={})
  @hide_success = opts.fetch(:hide_success, false)
end

Instance Method Details

#error(msg, opts = {}) ⇒ Object

Show an error message and notification.

Parameters:

  • msg (String)
  • opts (Hash) (defaults to: {})

33
34
35
36
# File 'lib/guard/sass/formatter.rb', line 33

def error(msg, opts={})
  ::Guard::UI.error("[Sass] #{msg}", opts)
  notify(opts[:notification], :image => :failed)
end

#notify(msg, opts = {}) ⇒ Object

Show a system notification.

Parameters:


42
43
44
# File 'lib/guard/sass/formatter.rb', line 42

def notify(msg, opts={})
  ::Guard::Notifier.notify(msg, ({:title => "Guard::Sass"}).merge(opts))
end

#success(msg, opts = {}) ⇒ Object

Show a success message and notification if successes are being shown.

Parameters:

  • msg (String)
  • opts (Hash) (defaults to: {})

18
19
20
21
22
23
24
25
26
27
# File 'lib/guard/sass/formatter.rb', line 18

def success(msg, opts={})
  unless @hide_success
    benchmark = nil
    if time = opts.delete(:time)
      benchmark = "[\e[33m%2.2fs\e[0m] " % time
    end
    ::Guard::UI.info("\t\e[1;37mSass\e[0m %s%s" % [benchmark, msg], opts)
    notify(opts[:notification], :image => :success)
  end
end