livereload

This commit is contained in:
Thomas Reynolds 2011-07-13 18:45:15 -07:00
parent 5934f4cbc0
commit e81ba33b0d
5 changed files with 24 additions and 7 deletions

View file

@ -1,6 +1,8 @@
2.0.0 2.0.0
===== =====
- Guard-powered auto-reloading of config.rb
- Guard LiveReload
- Sprockets JS - Sprockets JS
- Refactored Dynamically Reloadable Core - Refactored Dynamically Reloadable Core
- Combine views/ and public/ into a single source/ folder. - Combine views/ and public/ into a single source/ folder.

View file

@ -4,6 +4,4 @@ ENV['MM_ENV'] = "build"
# Require app # Require app
require File.join(File.dirname(__FILE__), "..", "lib", "middleman") require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
require 'middleman'
Middleman::Builder.start Middleman::Builder.start

View file

@ -7,6 +7,7 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development' env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
options = {} options = {}
livereload_options = {}
# TODO: Switch to Thor # TODO: Switch to Thor
OptionParser.new { |opts| OptionParser.new { |opts|
@ -19,6 +20,9 @@ OptionParser.new { |opts|
opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e| opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
env = e env = e
} }
opts.on("--livereload_port PORT", "use PORT (default: 35729)") { |port|
livereload_options[:port] = port
}
opts.parse! ARGV opts.parse! ARGV
} }
@ -36,4 +40,4 @@ if File.exists?("views") || File.exists?("public")
exit exit
end end
Middleman::Guard.start(options) Middleman::Guard.start(options, livereload_options)

View file

@ -144,6 +144,9 @@ module Middleman
# Proxy web services requests in dev mode only # Proxy web services requests in dev mode only
autoload :Proxy, "middleman/features/proxy" autoload :Proxy, "middleman/features/proxy"
# guard-livereload
autoload :LiveReload, "middleman/features/live_reload"
# Automatically resize images for mobile devises # Automatically resize images for mobile devises
# autoload :TinySrc, "middleman/features/tiny_src" # autoload :TinySrc, "middleman/features/tiny_src"

View file

@ -1,25 +1,35 @@
require "guard" require "guard"
require "guard/guard" require "guard/guard"
require "guard/livereload"
module Middleman::Guard module Middleman::Guard
def self.start(options={}) def self.start(options={}, livereload={})
options_hash = "" options_hash = ""
options.each do |k,v| options.each do |k,v|
options_hash << ", :#{k} => '#{v}'" options_hash << ", :#{k} => '#{v}'"
end end
livereload_options_hash = ""
livereload.each do |k,v|
livereload_options_hash << ", :#{k} => '#{v}'"
end
::Guard.start({ ::Guard.start({
:guardfile_contents => %Q{ :guardfile_contents => %Q{
guard 'MiddlemanServer'#{options_hash} do guard 'middleman'#{options_hash} do
watch("config.rb") watch("config.rb")
end end
guard 'livereload'#{livereload_options_hash} do
watch(%r{^source/(.*)$})
end
} }
}) })
end end
end end
module Guard module Guard
class MiddlemanServer < Guard class Middleman < Guard
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
super super
@options = { @options = {
@ -41,7 +51,7 @@ module Guard
puts "== The Middleman is standing watch on port #{@options[:port]}" puts "== The Middleman is standing watch on port #{@options[:port]}"
@server_options = { :Port => @options[:port], :AccessLog => [] } @server_options = { :Port => @options[:port], :AccessLog => [] }
@server_job = fork do @server_job = fork do
@server_options[:app] = Middleman.server.new @server_options[:app] = ::Middleman.server.new
::Rack::Server.new(@server_options).start ::Rack::Server.new(@server_options).start
end end
end end