#!/usr/bin/env ruby # coding: utf-8 require 'bundler/setup' require 'optparse' require File.join(File.dirname(File.dirname(__FILE__)), 'lib/bonsai') banner = %q{ 盆栽 bonsai, tiny and beautiful } opts = OptionParser.new do |opts| opts.banner = banner opts.on("-p", "--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("-c", "--cultivate", "run a local web server and process your files on save") do begin Bonsai.log banner Bonsai.log "Press Control+C to quit" require 'rack' require 'sinatra' require 'watch' require 'launchy' 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.default.run(app, :Port => 5000) do Launchy.open("http://localhost:5000/") end } Watch.new("{content,templates,public}/**/*") { Bonsai::Exporter.process! } rescue Interrupt Process.kill("QUIT", server) Process.wait(server) exit end end opts.on("-r", "--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!