Class: Laze::Secretary

Inherits:
Object
  • Object
show all
Defined in:
lib/laze/secretary.rb

Overview

The Secretary combines all other classes to a working application and serves as a central point of information for other classes that need to know stuff that are none of their primary concern.

The secretary keeps track of the build options and the storage and target engines that are currently used.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Secretary

:nodoc:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/laze/secretary.rb', line 30

def initialize(options = {}) #:nodoc:
  default_options = {
    :store      => :filesystem,
    :target     => :filesystem,
    :source     => '.',
    :directory  => 'output',
    :minify_js  => false,
    :minify_css => false,
    :loglevel   => :warn,
    :logfile    => 'stderr'
  }
  @options = default_options.merge(self.class.site_config).merge(options)

  # Set the logger options
  logger = Logger.new((@options[:logfile] == 'stderr' ? STDERR : @options[:logfile]))
  logger.level = Logger.const_get(@options[:loglevel].to_s.upcase)
  logger.datetime_format = "%H:%M:%S"
  Laze.const_set('LOGGER', logger) unless Laze.const_defined?('LOGGER')

  Secretary.current = self
end

Class Attribute Details

.currentObject

Since there should only be a singe secretary object, we let the singleton class keep track of the current instance.



16
17
18
# File 'lib/laze/secretary.rb', line 16

def current
  @current
end

Instance Attribute Details

#optionsObject (readonly)

Options that tell Laze what to do and how to do it.



11
12
13
# File 'lib/laze/secretary.rb', line 11

def options
  @options
end

Class Method Details

.site_configObject

Read configuration from the laze.yml file in the current directory. – TODO: make sure this reads from the source directory, not the current.



21
22
23
24
25
26
27
# File 'lib/laze/secretary.rb', line 21

def site_config
  if File.exists?('laze.yml')
    YAML.load_file('laze.yml').symbolize_keys
  else
    {}
  end
end

Instance Method Details

#runObject

Run laze to build the output website.



63
64
65
66
67
68
69
70
71
# File 'lib/laze/secretary.rb', line 63

def run
  Laze.debug 'Starting source processing'
  target.reset
  store.each do |item|
    target.create item
  end
  target.save
  Laze.debug 'Source processing ready'
end

#storeObject

The current storage engine.



53
54
55
# File 'lib/laze/secretary.rb', line 53

def store
  @store ||= Store.find(options[:store]).new(options[:source])
end

#targetObject

The current target deployment engine.



58
59
60
# File 'lib/laze/secretary.rb', line 58

def target
  @target ||= Target.find(options[:target]).new(options[:directory])
end