#!/usr/bin/env ruby # coding: utf-8 require 'optparse' require 'bonsai' banner = %q{ 盆栽 bonsai, tiny and beautiful } opts = OptionParser.new do |opts| opts.banner = banner opts.on("--plant [NAME]", "creates the directory structure for your site") do |name| if name.nil? Bonsai.log "no site name given check `bonsai --help` for details" exit 0 end Bonsai::Generate.new("#{Dir.pwd}/#{name}") end opts.on("--cultivate", "run a local web server and process your files on save") do Bonsai.log banner require 'rack' require 'sinatra' require 'watch' Bonsai.root_dir = Dir.pwd server = fork { app = Rack::Builder.app { use Bonsai::StaticPassThrough, :root => Bonsai.root_dir + "/output", :urls => ["/"] run Bonsai::DevelopmentServer } Rack::Handler::Thin.run(app, :Port => 5000) } trap("SIGINT") do Process.kill("QUIT", server) exit end Watch.new("{content,templates,public}/**/*") { Bonsai::Exporter.process! } end opts.on("--repot", "export your site to #{Dir.pwd}/output") do Bonsai.root_dir = Dir.pwd Bonsai::Exporter.publish! end opts.on("-v", "--version") do Bonsai.log "Version: #{Bonsai.version}" end opts.on("--console", "start an IRB console session giving you access to your bonsai environment") do Bonsai.root_dir = Dir.pwd Bonsai::Console.new end end if ARGV.size == 0 puts "grow a tiny tree. \ntype --help for a command list" exit 1 end opts.parse!