From 395f62942117996fc4b52899f8002ae7b14b3cfd Mon Sep 17 00:00:00 2001 From: Simon Kagedal Reimer Date: Thu, 12 Mar 2015 11:24:00 -0400 Subject: [PATCH] Some error handling and other niceties. --- build.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) mode change 100644 => 100755 build.rb diff --git a/build.rb b/build.rb old mode 100644 new mode 100755 index 4afd7d1..cae02e9 --- a/build.rb +++ b/build.rb @@ -1,14 +1,20 @@ +#!/usr/bin/env ruby + require 'pathname' -require 'fileutils' require 'yaml' -require 'liquid' require 'optparse' +begin require 'liquid' +rescue LoadError + puts "Please install the 'liquid' Ruby gem (available in Debian/Ubuntu as 'ruby-liquid')" + exit 1 +end + CONFIG = { pages_dir: '_manual', layouts_dir: '_layouts', static_dir: 'source', - output_dir: '_site' # will get wiped! + output_dir: '_site' } def child_url?(a, b) @@ -58,7 +64,9 @@ class Site end def copy_static() - `rsync -a --delete --exclude='*~' #{static_dir}/. #{output_dir}` + unless system("rsync -a --delete --exclude='*~' #{static_dir}/. #{output_dir}") + puts "Couldn't copy static files, is rsync installed?" + end end def find_children(url) @@ -218,7 +226,12 @@ end class Server def start_watcher() - require 'listen' + begin require 'listen' + rescue LoadError + puts "To use the --watch function, please install the 'listen' Ruby gem" + puts "(available in Debian/Ubuntu as 'ruby-listen')" + return nil + end listener = Listen.to(CONFIG[:pages_dir], wait_for_delay: 1.0, only: /.html$/) do |modified, added, removed| Site.new.build @@ -252,6 +265,11 @@ def main options = {} OptionParser.new do |opts| + opts.banner = %{Usage: build.rb [options] + +Use 'build.rb' to build the manual. Use 'build.rb serve' to also +start a web server. Options: +} opts.on("--watch", "Watch for changes") { options[:watch] = true } end.parse! -- 2.37.2