Skip to content

Instantly share code, notes, and snippets.

@craibuc
Created March 3, 2014 12:21
Show Gist options
  • Select an option

  • Save craibuc/9323879 to your computer and use it in GitHub Desktop.

Select an option

Save craibuc/9323879 to your computer and use it in GitHub Desktop.
# remove for asciidoctor (Ruby) implementation
# require 'asciidoctor'
# require 'erb'
#
# Purpose: automatically run scripts when any .ADOC file changes; creates OS X (Mavericks) notifications
# Requires:
# - Ruby (https://www.ruby-lang.org)
# - guard (https://github.com/guard/)
# - guard-shell (https://github.com/hawx/guard-shell)
#
guard :shell do
# when guard see a change to a document with .adoc extension
watch(/(.*).adoc/) {|m|
n m[0], 'File Changed', :success
# generate HTML
`asciidoc #{m[0]}`
n m[0].gsub('adoc','html'), 'File Created', :success
# generate XML (precursor for ePUB, PDF, Mobi)
`asciidoc -b docbook #{m[0]}`
n m[0].gsub('adoc','xml'), 'File Created', :success
# generate PDF; template-docinfo.xml; FOP instead of dblatex
`a2x -f pdf -d book -a docinfo --fop #{m[0]}`
n m[0].gsub('adoc','pdf'), 'File Created', :success
# generate ePub; template-docinfo.xml; FOP instead of dblatex
`a2x -f epub -d book -a docinfo --fop #{m[0]}`
n m[0].gsub('adoc','epub'), 'File Created', :success
# use Asciidoctor (Ruby) implementations
# Asciidoctor.render_file(m[0], {:in_place => true, :safe => :unsafe})
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment