livereload
This commit is contained in:
parent
5934f4cbc0
commit
e81ba33b0d
5 changed files with 24 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
2.0.0
|
||||
=====
|
||||
|
||||
- Guard-powered auto-reloading of config.rb
|
||||
- Guard LiveReload
|
||||
- Sprockets JS
|
||||
- Refactored Dynamically Reloadable Core
|
||||
- Combine views/ and public/ into a single source/ folder.
|
||||
|
|
|
@ -4,6 +4,4 @@ ENV['MM_ENV'] = "build"
|
|||
|
||||
# Require app
|
||||
require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
|
||||
|
||||
require 'middleman'
|
||||
Middleman::Builder.start
|
|
@ -7,6 +7,7 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
|
|||
|
||||
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
|
||||
options = {}
|
||||
livereload_options = {}
|
||||
|
||||
# TODO: Switch to Thor
|
||||
OptionParser.new { |opts|
|
||||
|
@ -19,6 +20,9 @@ OptionParser.new { |opts|
|
|||
opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
|
||||
env = e
|
||||
}
|
||||
opts.on("--livereload_port PORT", "use PORT (default: 35729)") { |port|
|
||||
livereload_options[:port] = port
|
||||
}
|
||||
|
||||
opts.parse! ARGV
|
||||
}
|
||||
|
@ -36,4 +40,4 @@ if File.exists?("views") || File.exists?("public")
|
|||
exit
|
||||
end
|
||||
|
||||
Middleman::Guard.start(options)
|
||||
Middleman::Guard.start(options, livereload_options)
|
|
@ -144,6 +144,9 @@ module Middleman
|
|||
|
||||
# Proxy web services requests in dev mode only
|
||||
autoload :Proxy, "middleman/features/proxy"
|
||||
|
||||
# guard-livereload
|
||||
autoload :LiveReload, "middleman/features/live_reload"
|
||||
|
||||
# Automatically resize images for mobile devises
|
||||
# autoload :TinySrc, "middleman/features/tiny_src"
|
||||
|
|
|
@ -1,25 +1,35 @@
|
|||
require "guard"
|
||||
require "guard/guard"
|
||||
require "guard/livereload"
|
||||
|
||||
module Middleman::Guard
|
||||
def self.start(options={})
|
||||
def self.start(options={}, livereload={})
|
||||
options_hash = ""
|
||||
options.each do |k,v|
|
||||
options_hash << ", :#{k} => '#{v}'"
|
||||
end
|
||||
|
||||
livereload_options_hash = ""
|
||||
livereload.each do |k,v|
|
||||
livereload_options_hash << ", :#{k} => '#{v}'"
|
||||
end
|
||||
|
||||
::Guard.start({
|
||||
:guardfile_contents => %Q{
|
||||
guard 'MiddlemanServer'#{options_hash} do
|
||||
guard 'middleman'#{options_hash} do
|
||||
watch("config.rb")
|
||||
end
|
||||
|
||||
guard 'livereload'#{livereload_options_hash} do
|
||||
watch(%r{^source/(.*)$})
|
||||
end
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
module Guard
|
||||
class MiddlemanServer < Guard
|
||||
class Middleman < Guard
|
||||
def initialize(watchers = [], options = {})
|
||||
super
|
||||
@options = {
|
||||
|
@ -41,7 +51,7 @@ module Guard
|
|||
puts "== The Middleman is standing watch on port #{@options[:port]}"
|
||||
@server_options = { :Port => @options[:port], :AccessLog => [] }
|
||||
@server_job = fork do
|
||||
@server_options[:app] = Middleman.server.new
|
||||
@server_options[:app] = ::Middleman.server.new
|
||||
::Rack::Server.new(@server_options).start
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue