Class: Webby::AutoBuilder
- Inherits:
-
Object
- Object
- Webby::AutoBuilder
- Defined in:
- lib/webby/auto_builder.rb
Overview
The AutoBuilder class is used to monitor the content and layouts folders and to compile the resource files only when they are modified. If a layout is modified, then all resources that depend upon the layout are compiled.
Class Method Summary collapse
-
.run ⇒ Object
call-seq: AutoBuilder.run.
Instance Method Summary collapse
-
#initialize ⇒ AutoBuilder
constructor
call-seq: AutoBuilder.new.
-
#run ⇒ Object
call-seq: run.
-
#update(*events) ⇒ Object
call-seq: update( *events ).
Constructor Details
#initialize ⇒ AutoBuilder
call-seq:
AutoBuilder.new
Create a new AutoBuilder class.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/webby/auto_builder.rb', line 29 def initialize @log = Logging::Logger[self] @builder = Builder.new @watcher = DirectoryWatcher.new '.', :interval => 2 @watcher.add_observer self glob = [] glob << File.join(::Webby.site.layout_dir, '**', '*') glob << File.join(::Webby.site.content_dir, '**', '*') @watcher.glob = glob end |
Class Method Details
.run ⇒ Object
call-seq:
AutoBuilder.run
Creates a new AutoBuilder and sets it running. This method will only return when the user presses Ctrl-C.
20 21 22 |
# File 'lib/webby/auto_builder.rb', line 20 def self.run self.new.run end |
Instance Method Details
#run ⇒ Object
call-seq:
run
Starts the DirectoryWatcher running and waits till the user presses Ctrl-C to stop the watcher thread.
71 72 73 74 75 76 77 78 |
# File 'lib/webby/auto_builder.rb', line 71 def run @log.info 'starting autobuild (Ctrl-C to stop)' Signal.trap('INT') {@watcher.stop} @watcher.start @watcher.join end |
#update(*events) ⇒ Object
call-seq:
update( *events )
The update method is called by the DirectoryWatcher when files have been modified, added, or deleted. An array of events is passed to his method, and each event contains the event type and the path to the file.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/webby/auto_builder.rb', line 49 def update( *events ) ary = events.find_all {|evt| evt.type != :removed} return if ary.empty? ary.each do |evt| @log.debug "changed #{evt.path}" next unless test ?f, evt.path next if evt.path =~ ::Webby.exclude Resource.new evt.path end @builder.run :load_files => false rescue => err @log.error err end |