Merge pull request #237 from kk7ds/preview-bind

Allow preview with a different bind address
This commit is contained in:
Paulus Schoutsen 2016-02-19 21:03:39 -08:00
commit 40cc9ec95e

View File

@ -77,13 +77,14 @@ task :watch do
end end
desc "preview the site in a web browser" desc "preview the site in a web browser"
task :preview do task :preview, :listen do |t, args|
listen_addr = args[:listen] || '127.0.0.1'
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}" puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css") system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --incremental") jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --incremental")
compassPid = Process.spawn("compass watch") compassPid = Process.spawn("compass watch")
rackupPid = Process.spawn("rackup --port #{server_port}") rackupPid = Process.spawn("rackup --port #{server_port} --host #{listen_addr}")
trap("INT") { trap("INT") {
[jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH } [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }