Lifecycle Hooks
A number of lifecycle hooks are available for use in triggering actions outside of Lookbook.
All hook callback blocks are yielded a Lookbook
instance as the first argument. Some hooks additionally supply other arguments - see below for details.
Available hooks
.after_initialize
Run once Lookbook has been set up and the initial parsing of files has been completed.
Lookbook.after_initialize do |app|
puts "Lookbook version #{app.version} has started"
puts "There are #{app.previews.size} previews and #{app.pages.size} pages"
# other code here...
end
.after_change
Run each time a change is detected to a file that Lookbook is watching, unless listening for changes has been disabled in the config.
Receives a hash as the second argument with :modified
, :added
, and :removed
properties, each of which is an array of affected file paths.
Lookbook.after_change do |app, changes|
puts "Modified files: #{changes.modified.join("\n")}"
puts "Added files: #{changes.added.join("\n")}"
puts "Removed files: #{changes.removed.join("\n")}"
end
.before_exit
Run when the current process exits, after Lookbook has stopped any listeners.
Lookbook.after_initialize do |app|
puts "Shutting down..."
end