traverse up directories to find root mm project. closes #19
This commit is contained in:
parent
62abada7f5
commit
f40c8a56da
2 changed files with 43 additions and 18 deletions
|
@ -44,13 +44,41 @@ OptionParser.new { |opts|
|
||||||
|
|
||||||
ENV['RACK_ENV'] = env
|
ENV['RACK_ENV'] = env
|
||||||
|
|
||||||
class Middleman::Server
|
@current_path = Dir.pwd
|
||||||
set :root, Dir.pwd
|
@path_parts = @current_path.split("/")
|
||||||
|
@found_root = false
|
||||||
|
|
||||||
|
while (!@found_root && (@path_parts.length > 0))
|
||||||
|
@current_path = File.join(*@path_parts)
|
||||||
|
|
||||||
|
public_folder = File.join(@current_path, "public")
|
||||||
|
views_folder = File.join(@current_path, "views")
|
||||||
|
|
||||||
|
if File.exists?(public_folder) && File.exists?(views_folder)
|
||||||
|
@found_root = true
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
@path_parts.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !@found_root
|
||||||
|
$stderr.puts "== Error: Could not find a Middleman project structure, perhaps you are in the wrong folder?"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
# If the old init.rb exists, use it, but issue warning
|
||||||
|
old_config = File.join(@current_path, "init.rb")
|
||||||
|
if File.exists? old_config
|
||||||
|
$stderr.puts "== Error: The init.rb file (deprecated) needs to be be renamed to config.rb"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# require 'shotgun'
|
# require 'shotgun'
|
||||||
# config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
# config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
||||||
# app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
|
# app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
|
||||||
|
Middleman::Server.root = @current_path
|
||||||
app = Middleman::Server.new
|
app = Middleman::Server.new
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Middleman
|
||||||
class Server < Sinatra::Base
|
class Server < Sinatra::Base
|
||||||
# Basic Sinatra config
|
# Basic Sinatra config
|
||||||
set :app_file, __FILE__
|
set :app_file, __FILE__
|
||||||
set :root, ENV["MM_DIR"] || Dir.pwd
|
#set :root, ENV["MM_DIR"] || Dir.pwd
|
||||||
set :reload, false
|
set :reload, false
|
||||||
set :sessions, false
|
set :sessions, false
|
||||||
set :logging, false
|
set :logging, false
|
||||||
|
@ -117,13 +117,17 @@ module Middleman
|
||||||
def process_request(options={})
|
def process_request(options={})
|
||||||
# Normalize the path and add index if we're looking at a directory
|
# Normalize the path and add index if we're looking at a directory
|
||||||
path = request.path
|
path = request.path
|
||||||
path = File.join(path, settings.index_file) if path.split('/').last.split('.').length == 1
|
parts = path ? path.split('/') : []
|
||||||
path.gsub!(%r{^/}, '')
|
if parts.last.nil? || parts.last.split('.').length == 1
|
||||||
static_path = File.join(Middleman::Server.public, path)
|
path = File.join(path, settings.index_file)
|
||||||
if File.exists? static_path
|
|
||||||
send_file static_path
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
path.gsub!(%r{^/}, '')
|
||||||
|
|
||||||
|
static_path = File.join(Middleman::Server.public, path)
|
||||||
|
# if File.exists? static_path
|
||||||
|
# send_file static_path
|
||||||
|
# return
|
||||||
|
# end
|
||||||
|
|
||||||
old_layout = settings.current_layout
|
old_layout = settings.current_layout
|
||||||
settings.layout(options[:layout]) if !options[:layout].nil?
|
settings.layout(options[:layout]) if !options[:layout].nil?
|
||||||
|
@ -150,16 +154,9 @@ require "middleman/assets"
|
||||||
|
|
||||||
# The Rack App
|
# The Rack App
|
||||||
class Middleman::Server
|
class Middleman::Server
|
||||||
def self.new(*args, &block)
|
def self.new(*args, &block)
|
||||||
# If the old init.rb exists, use it, but issue warning
|
|
||||||
old_config = File.join(self.root, "init.rb")
|
|
||||||
if File.exists? old_config
|
|
||||||
$stderr.puts "== Warning: The init.rb file has been renamed to config.rb"
|
|
||||||
local_config = old_config
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check for and evaluate local configuration
|
# Check for and evaluate local configuration
|
||||||
local_config ||= File.join(self.root, "config.rb")
|
local_config = File.join(self.root, "config.rb")
|
||||||
if File.exists? local_config
|
if File.exists? local_config
|
||||||
$stderr.puts "== Reading: Local config" if logging?
|
$stderr.puts "== Reading: Local config" if logging?
|
||||||
Middleman::Server.class_eval File.read(local_config)
|
Middleman::Server.class_eval File.read(local_config)
|
||||||
|
|
Loading…
Reference in a new issue