implement new http-based messaging between guard and instance
This commit is contained in:
parent
e2fdd9a4d3
commit
abbd489c91
6 changed files with 69 additions and 45 deletions
|
@ -283,6 +283,17 @@ class Middleman::Base
|
||||||
@req = Rack::Request.new(env)
|
@req = Rack::Request.new(env)
|
||||||
@res = Rack::Response.new
|
@res = Rack::Response.new
|
||||||
|
|
||||||
|
if env["PATH_INFO"] == "/__middleman__" && env["REQUEST_METHOD"] == "POST"
|
||||||
|
if req.params.has_key?("change")
|
||||||
|
file_did_change(req.params["change"])
|
||||||
|
elsif req.params.has_key?("delete")
|
||||||
|
file_did_delete(req.params["delete"])
|
||||||
|
end
|
||||||
|
|
||||||
|
res.status = 200
|
||||||
|
return res.finish
|
||||||
|
end
|
||||||
|
|
||||||
# Catch :halt exceptions and use that response if given
|
# Catch :halt exceptions and use that response if given
|
||||||
catch(:halt) do
|
catch(:halt) do
|
||||||
process_request
|
process_request
|
||||||
|
@ -373,13 +384,13 @@ class Middleman::Base
|
||||||
# @param [String] Request path
|
# @param [String] Request path
|
||||||
# @return [String] Path with index file if necessary
|
# @return [String] Path with index file if necessary
|
||||||
def full_path(path)
|
def full_path(path)
|
||||||
# cache.fetch(:full_path, path) do
|
cache.fetch(:full_path, path) do
|
||||||
parts = path ? path.split('/') : []
|
parts = path ? path.split('/') : []
|
||||||
if parts.last.nil? || parts.last.split('.').length == 1
|
if parts.last.nil? || parts.last.split('.').length == 1
|
||||||
path = File.join(path, index_file)
|
path = File.join(path, index_file)
|
||||||
end
|
end
|
||||||
"/" + path.sub(%r{^/}, '')
|
"/" + path.sub(%r{^/}, '')
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new mime-type for a specific extension
|
# Add a new mime-type for a specific extension
|
||||||
|
|
|
@ -31,6 +31,10 @@ module Middleman
|
||||||
@cache[key]
|
@cache[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def keys
|
||||||
|
@cache.keys
|
||||||
|
end
|
||||||
|
|
||||||
# Clear the entire cache
|
# Clear the entire cache
|
||||||
def clear
|
def clear
|
||||||
@cache = {}
|
@cache = {}
|
||||||
|
|
|
@ -4,11 +4,6 @@ module Middleman::CoreExtensions::Rendering
|
||||||
# Autoload
|
# Autoload
|
||||||
require "coffee_script"
|
require "coffee_script"
|
||||||
|
|
||||||
begin
|
|
||||||
require "slim"
|
|
||||||
rescue LoadError
|
|
||||||
end
|
|
||||||
|
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
# Activate custom renderers
|
# Activate custom renderers
|
||||||
|
@ -17,6 +12,11 @@ module Middleman::CoreExtensions::Rendering
|
||||||
app.register Middleman::Renderers::Markdown
|
app.register Middleman::Renderers::Markdown
|
||||||
app.register Middleman::Renderers::ERb
|
app.register Middleman::Renderers::ERb
|
||||||
app.register Middleman::Renderers::Liquid
|
app.register Middleman::Renderers::Liquid
|
||||||
|
|
||||||
|
begin
|
||||||
|
require "slim"
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ module Middleman::CoreExtensions::Rendering
|
||||||
def initialize
|
def initialize
|
||||||
file_changed %r{^source/} do |file|
|
file_changed %r{^source/} do |file|
|
||||||
path = File.expand_path(file, root)
|
path = File.expand_path(file, root)
|
||||||
# cache.remove(:raw_template, path.to_sym)
|
cache.remove(:raw_template, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
|
@ -97,25 +97,25 @@ module Middleman::CoreExtensions::Rendering
|
||||||
# @private
|
# @private
|
||||||
def render_individual_file(path, locs = {}, opts = {}, &block)
|
def render_individual_file(path, locs = {}, opts = {}, &block)
|
||||||
path = path.to_s
|
path = path.to_s
|
||||||
body = #cache.fetch(:raw_template, path) do
|
|
||||||
# $stderr.puts "reading: #{path}"
|
body = cache.fetch(:raw_template, path) do
|
||||||
File.read(path)
|
File.read(path)
|
||||||
# end
|
end
|
||||||
|
|
||||||
extension = File.extname(path)
|
extension = File.extname(path)
|
||||||
options = opts.merge(options_for_ext(extension))
|
options = opts.merge(options_for_ext(extension))
|
||||||
options[:outvar] ||= '@_out_buf'
|
options[:outvar] ||= '@_out_buf'
|
||||||
|
|
||||||
template = #cache.fetch(:compiled_template, options, body) do
|
template = cache.fetch(:compiled_template, options, body) do
|
||||||
::Tilt.new(path, 1, options) { body }
|
::Tilt.new(path, 1, options) { body }
|
||||||
# end
|
end
|
||||||
|
|
||||||
template.render(self, locs, &block)
|
template.render(self, locs, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def options_for_ext(ext)
|
def options_for_ext(ext)
|
||||||
# cache.fetch(:options_for_ext, ext) do
|
cache.fetch(:options_for_ext, ext) do
|
||||||
options = {}
|
options = {}
|
||||||
|
|
||||||
extension_class = ::Tilt[ext]
|
extension_class = ::Tilt[ext]
|
||||||
|
@ -126,7 +126,7 @@ module Middleman::CoreExtensions::Rendering
|
||||||
end
|
end
|
||||||
|
|
||||||
options
|
options
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
|
@ -194,7 +194,7 @@ module Middleman::CoreExtensions::Rendering
|
||||||
# @private
|
# @private
|
||||||
def resolve_template(request_path, options={})
|
def resolve_template(request_path, options={})
|
||||||
request_path = request_path.to_s
|
request_path = request_path.to_s
|
||||||
# cache.fetch(:resolve_template, request_path, options) do
|
cache.fetch(:resolve_template, request_path, options) do
|
||||||
relative_path = request_path.sub(%r{^/}, "")
|
relative_path = request_path.sub(%r{^/}, "")
|
||||||
on_disk_path = File.expand_path(relative_path, self.source_dir)
|
on_disk_path = File.expand_path(relative_path, self.source_dir)
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ module Middleman::CoreExtensions::Rendering
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,7 @@
|
||||||
require "guard"
|
require "guard"
|
||||||
require "guard/guard"
|
require "guard/guard"
|
||||||
require "rbconfig"
|
require "rbconfig"
|
||||||
|
require "net/http"
|
||||||
|
|
||||||
if Config::CONFIG['host_os'].downcase =~ %r{mingw}
|
if Config::CONFIG['host_os'].downcase =~ %r{mingw}
|
||||||
require "win32/process"
|
require "win32/process"
|
||||||
|
@ -60,20 +61,16 @@ module Guard
|
||||||
|
|
||||||
if needs_to_restart
|
if needs_to_restart
|
||||||
reload
|
reload
|
||||||
elsif !@app.nil?
|
else
|
||||||
paths.each do |path|
|
paths.each do |path|
|
||||||
@app.logger.debug :file_change, Time.now, path if @app.settings.logging?
|
file_did_change(path)
|
||||||
@app.file_did_change(path)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_on_deletion(paths)
|
def run_on_deletion(paths)
|
||||||
if !@app.nil?
|
|
||||||
paths.each do |path|
|
paths.each do |path|
|
||||||
@app.logger.debug :file_remove, Time.now, path if @app.settings.logging?
|
file_did_delete(path)
|
||||||
@app.file_did_delete(path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,16 +79,16 @@ module Guard
|
||||||
# Quiet down Guard
|
# Quiet down Guard
|
||||||
# ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
|
# ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
|
||||||
|
|
||||||
|
@server_job = fork do
|
||||||
env = (@options[:environment] || "development").to_sym
|
env = (@options[:environment] || "development").to_sym
|
||||||
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
|
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
|
||||||
@app = ::Middleman.server.inst do
|
app = ::Middleman.server.inst do
|
||||||
set :environment, env
|
set :environment, env
|
||||||
set :logging, is_logging
|
set :logging, is_logging
|
||||||
end
|
end
|
||||||
|
|
||||||
app_rack = @app.class.to_rack_app
|
app_rack = app.class.to_rack_app
|
||||||
|
|
||||||
@server_job = fork do
|
|
||||||
opts = @options.dup
|
opts = @options.dup
|
||||||
opts[:app] = app_rack
|
opts[:app] = app_rack
|
||||||
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
|
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
|
||||||
|
@ -104,7 +101,20 @@ module Guard
|
||||||
Process.kill("KILL", @server_job)
|
Process.kill("KILL", @server_job)
|
||||||
Process.wait @server_job
|
Process.wait @server_job
|
||||||
@server_job = nil
|
@server_job = nil
|
||||||
@app = nil
|
# @app = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def talk_to_server(params={})
|
||||||
|
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
|
||||||
|
Net::HTTP.post_form(uri, {}.merge(params))
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_did_change(path)
|
||||||
|
talk_to_server :change => path
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_did_delete(path)
|
||||||
|
talk_to_server :delete => path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -4,7 +4,6 @@ module Middleman::Sitemap
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@cache = ::Middleman::Cache.new
|
|
||||||
@source = File.expand_path(@app.source, @app.root)
|
@source = File.expand_path(@app.source, @app.root)
|
||||||
@pages = {}
|
@pages = {}
|
||||||
end
|
end
|
||||||
|
@ -23,12 +22,12 @@ module Middleman::Sitemap
|
||||||
|
|
||||||
def ignore(path)
|
def ignore(path)
|
||||||
page(path) { ignore }
|
page(path) { ignore }
|
||||||
@cache.remove(:ignored_paths)
|
app.cache.remove(:ignored_paths)
|
||||||
end
|
end
|
||||||
|
|
||||||
def proxy(path, target)
|
def proxy(path, target)
|
||||||
page(path) { proxy_to(target.sub(%r{^/}, "")) }
|
page(path) { proxy_to(target.sub(%r{^/}, "")) }
|
||||||
@cache.remove(:proxied_paths)
|
app.cache.remove(:proxied_paths)
|
||||||
end
|
end
|
||||||
|
|
||||||
def page(path, &block)
|
def page(path, &block)
|
||||||
|
@ -53,7 +52,7 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored_paths
|
def ignored_paths
|
||||||
@cache.fetch :ignored_paths do
|
app.cache.fetch :ignored_paths do
|
||||||
@pages.values.select(&:ignored?).map(&:path)
|
@pages.values.select(&:ignored?).map(&:path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -63,7 +62,7 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def generic_paths
|
def generic_paths
|
||||||
@cache.fetch :generic_paths do
|
app.cache.fetch :generic_paths do
|
||||||
@pages.values.select(&:generic?).map(&:path)
|
@pages.values.select(&:generic?).map(&:path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,7 +72,7 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def proxied_paths
|
def proxied_paths
|
||||||
@cache.fetch :proxied_paths do
|
app.cache.fetch :proxied_paths do
|
||||||
@pages.values.select(&:proxy?).map(&:path)
|
@pages.values.select(&:proxy?).map(&:path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -123,7 +122,7 @@ module Middleman::Sitemap
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def extensionless_path(file)
|
def extensionless_path(file)
|
||||||
@cache.fetch(:extensionless_path, file) do
|
app.cache.fetch(:extensionless_path, file) do
|
||||||
path = file.dup
|
path = file.dup
|
||||||
|
|
||||||
end_of_the_line = false
|
end_of_the_line = false
|
||||||
|
|
|
@ -31,7 +31,7 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def metadata
|
def metadata
|
||||||
# store.cache.fetch(:metadata, source_file) do
|
app.cache.fetch(:metadata, source_file) do
|
||||||
metadata = { :options => {}, :locals => {} }
|
metadata = { :options => {}, :locals => {} }
|
||||||
app.provides_metadata.each do |callback, matcher|
|
app.provides_metadata.each do |callback, matcher|
|
||||||
next if !matcher.nil? && !source_file.match(matcher)
|
next if !matcher.nil? && !source_file.match(matcher)
|
||||||
|
@ -39,7 +39,7 @@ module Middleman::Sitemap
|
||||||
metadata = metadata.deep_merge(result)
|
metadata = metadata.deep_merge(result)
|
||||||
end
|
end
|
||||||
metadata
|
metadata
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(opts={}, locs={}, &block)
|
def render(opts={}, locs={}, &block)
|
||||||
|
|
Loading…
Add table
Reference in a new issue