Class: Webby::Journal

Inherits:
Object
  • Object
show all
Defined in:
lib/webby/journal.rb

Overview

The Journal class is used to output simple messages regarding the creation and updating of files when webby applications are run. The output messages will be color coded if the terminal supports the ANSI codes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJournal

Create a new journal



15
16
17
18
# File 'lib/webby/journal.rb', line 15

def initialize
  @logger = ::Logging::Logger[self]
  @colorize = ENV.has_key?('TERM')
end

Instance Attribute Details

#colorizeObject

Returns the value of attribute colorize.



10
11
12
# File 'lib/webby/journal.rb', line 10

def colorize
  @colorize
end

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/webby/journal.rb', line 11

def logger
  @logger
end

Instance Method Details

#create(msg) ⇒ Object

Output a create message.



53
54
55
# File 'lib/webby/journal.rb', line 53

def create( msg )
  typed_message('create', msg, (colorize ? :green : nil))
end

#create_or_update(page) ⇒ Object

Output a “create” message or an “update” message depending on whether the given page already has a generated output file or not.



43
44
45
46
47
48
49
# File 'lib/webby/journal.rb', line 43

def create_or_update( page )
  if test(?e, page.destination)
    update(page.destination)
  else
    create(page.destination)
  end
end

#exists(msg) ⇒ Object

Output an exists message.



77
78
79
# File 'lib/webby/journal.rb', line 77

def exists( msg )
  typed_message('exists', msg, (colorize ? :cyan : nil))
end

#force(msg) ⇒ Object

Output a force message.



65
66
67
# File 'lib/webby/journal.rb', line 65

def force( msg )
  typed_message('force', msg, (colorize ? :red : nil))
end

#identical(msg) ⇒ Object

Output an identical message.



83
84
85
# File 'lib/webby/journal.rb', line 83

def identical( msg )
  typed_message('identical', msg, (colorize ? :cyan : nil))
end

#skip(msg) ⇒ Object

Output a skip message.



71
72
73
# File 'lib/webby/journal.rb', line 71

def skip( msg )
  typed_message('skip', msg, (colorize ? :yellow : nil))
end

#typed_message(type, msg, color = nil) ⇒ Object

Output a message of the given type using the option color code. The available codes are as follows:

  • black

  • red

  • green

  • yellow

  • blue

  • magenta

  • cyan

  • white

The color is specified as a string or a symbol.



34
35
36
37
38
# File 'lib/webby/journal.rb', line 34

def typed_message( type, msg, color = nil )
  type = type.to_s.rjust(13)
  type = self.send(color, type) unless color.nil?
  logger.info "#{type}  #{msg.to_s}"
end

#update(msg) ⇒ Object

Output an update message.



59
60
61
# File 'lib/webby/journal.rb', line 59

def update( msg )
  typed_message('update', msg, (colorize ? :yellow : nil))
end