Hooks

Overview

You can tweak PureBuilder Simply behavior with hooks feature.

write .pbsimply-hooks.rb on document root to use Hooks. It should define PBSimply::Hooks.load_hooks.

It called with PBSimply::Hooks object. PBSimply::Hooks object has “timing” methods. You can add Proc to timing object with << method.

#!/bin/ruby

def (PBSimply::Hooks).load_hooks h
  h.process << ->(v) {
    db[v["normalized_docpath"]] = v
  }

  h.post << ->(v) {
    db.delete_if do |dbk, dbv|
      not File.exist? dbv["dest_path"]
    end
  }
end

Hook called with one argument. Ordinary it is a Hash, but keys and values are different between timing object.

Timing methods

Methods of argument of PBSimply::Hooks#load_hooks.

#add {|arg| ... }

Add block to timing object.

#<< proc

Add proc to timing object.

#cmd(*cmdarg)

Add command to timing object. Call command with system(*cmdarg).

You can modify content of file at $pbsimply_currentdoc environment variable on pre.

#filter(*cmdarg)

Add command to timing object. Call command with IO.popen(cmdarg, "w+").

Command is given document content from STDIN, and overwrite document content with command’s output.

you can use this method only on pre.

Timing object

pre

pre {|frontmatter, procdoc| ... }

PBSimply::Hooks#pre is called before processing document.

pre is called after BLESSing.

procdoc is processing document’s temporary path. Its content same as source document but without frontmatter.

process

process {|frontmatter, procdoc, outpath| ... }

PBSimply::Hooks#process is called just after generating.

frontmatter and procdoc are same as #pre, but after other process. outpath is output file path.

delete

delete {|target_file_path, source_file_path| ... }

PBSimply::Hooks#delete is called when document is lost include it turn to draft.

target_file_path is output file path (existing or non-existing.)

source_file_path is source file path (existing or non-existing.)

post

post {|this_time_processed| ... }

PBsimply::Hooks#post is called after all document processed.

Argument is this_time_processed.

this_time_processed is an Array of Hash actual processed documents in this time.

It has source (original source file path,) dest (output file path,) frontmatter.

accs

PBSimply::Hooks#accs is called before generating ACCS index.

Arguments are index and indexes. They are same as @index and @indexes in .accsindex.erb.