Class: Webby::Journal
- Inherits:
-
Object
- Object
- Webby::Journal
- 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
-
#colorize ⇒ Object
Returns the value of attribute colorize.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#create(msg) ⇒ Object
Output a create message.
-
#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.
-
#exists(msg) ⇒ Object
Output an exists message.
-
#force(msg) ⇒ Object
Output a force message.
-
#identical(msg) ⇒ Object
Output an identical message.
-
#initialize ⇒ Journal
constructor
Create a new journal.
-
#skip(msg) ⇒ Object
Output a skip message.
-
#typed_message(type, msg, color = nil) ⇒ Object
Output a message of the given type using the option color code.
-
#update(msg) ⇒ Object
Output an update message.
Constructor Details
#initialize ⇒ Journal
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
#colorize ⇒ Object
Returns the value of attribute colorize.
10 11 12 |
# File 'lib/webby/journal.rb', line 10 def colorize @colorize end |
#logger ⇒ Object (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 ) ('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 ) ('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 ) ('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 ) ('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 ) ('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 ( 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 ) ('update', msg, (colorize ? :yellow : nil)) end |