simplify middleman root detection, add MM_ROOT env
This commit is contained in:
parent
75fba6aa54
commit
c3f501913d
|
@ -18,6 +18,7 @@
|
||||||
* config.rb and extensions can add command-line commands
|
* config.rb and extensions can add command-line commands
|
||||||
* Nested layouts using `wrap_layout` helper
|
* Nested layouts using `wrap_layout` helper
|
||||||
* Support for placekitten.com
|
* Support for placekitten.com
|
||||||
|
* Added MM_ROOT environmental variable
|
||||||
|
|
||||||
2.0.14
|
2.0.14
|
||||||
====
|
====
|
||||||
|
|
|
@ -1,64 +1,30 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
require "rubygems"
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
|
libdir = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "lib"))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
require 'pathname'
|
ARGV << "server" if ARGV.length < 1
|
||||||
require 'rubygems'
|
|
||||||
|
|
||||||
module Middleman
|
def locate_middleman_root!(cwd = Pathname.new(Dir.pwd))
|
||||||
module ProjectLocator
|
return cwd.to_s if File.exists?(File.join(cwd, 'config.rb'))
|
||||||
class << self
|
return false if cwd.root?
|
||||||
def locate_middleman_root!
|
locate_middleman_root!(cwd.parent)
|
||||||
cwd = Dir.pwd
|
|
||||||
|
|
||||||
if !in_middleman_project? && !in_middleman_project_subdirectory?
|
|
||||||
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
|
||||||
exit(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
if in_middleman_project?
|
|
||||||
did_locate_middleman_project(cwd)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
Dir.chdir("..") do
|
|
||||||
# Recurse in a chdir block: if the search fails we want to be sure
|
|
||||||
# the application is generated in the original working directory.
|
|
||||||
locate_middleman_root! unless cwd == Dir.pwd
|
|
||||||
end
|
|
||||||
rescue SystemCallError
|
|
||||||
# could not chdir, no problem just return
|
|
||||||
end
|
|
||||||
|
|
||||||
def in_middleman_project?
|
|
||||||
File.exists?('config.rb')
|
|
||||||
end
|
|
||||||
|
|
||||||
def in_middleman_project_subdirectory?(path = Pathname.new(Dir.pwd))
|
|
||||||
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
|
|
||||||
end
|
|
||||||
|
|
||||||
def did_locate_middleman_project(path)
|
|
||||||
# Set up gems listed in the Gemfile.
|
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
|
|
||||||
|
|
||||||
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
|
||||||
|
|
||||||
start_cli!
|
|
||||||
end
|
|
||||||
|
|
||||||
def start_cli!
|
|
||||||
require 'middleman'
|
|
||||||
Middleman::Cli::Base.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ARGV << "server" if ARGV.length < 1
|
if !ENV['MM_ROOT'] && found_path = locate_middleman_root!
|
||||||
if %w(server s build b).include?(ARGV[0])
|
ENV['MM_ROOT'] = found_path
|
||||||
Middleman::ProjectLocator.locate_middleman_root!
|
end
|
||||||
else
|
|
||||||
Middleman::ProjectLocator.start_cli!
|
if ENV['MM_ROOT']
|
||||||
|
# Set up gems listed in the Gemfile.
|
||||||
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV['MM_ROOT'])
|
||||||
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
|
end
|
||||||
|
|
||||||
|
require 'middleman'
|
||||||
|
Dir.chdir(ENV['MM_ROOT'] || Dir.pwd) do
|
||||||
|
Middleman::Cli::Base.start
|
||||||
end
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
require "rbconfig"
|
require "rbconfig"
|
||||||
|
|
||||||
# Setup our load paths
|
# Setup our load paths
|
||||||
libdir = File.dirname(__FILE__)
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
# Top-level Middleman object
|
# Top-level Middleman object
|
||||||
|
@ -230,7 +230,7 @@ module Middleman
|
||||||
'webrick' # Maybe Kirk?
|
'webrick' # Maybe Kirk?
|
||||||
else
|
else
|
||||||
require "thin"
|
require "thin"
|
||||||
::Thin::Logging.silent = !options[:is_logging]
|
::Thin::Logging.silent = !options[:logging]
|
||||||
'thin'
|
'thin'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ class Middleman::Base
|
||||||
|
|
||||||
# Root project directory (overwritten in middleman build/server)
|
# Root project directory (overwritten in middleman build/server)
|
||||||
# @return [String]
|
# @return [String]
|
||||||
set :root, Dir.pwd
|
set :root, ENV['MM_ROOT'] || Dir.pwd
|
||||||
|
|
||||||
# Name of the source directory
|
# Name of the source directory
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
@ -324,6 +324,8 @@ class Middleman::Base
|
||||||
@req = Rack::Request.new(env)
|
@req = Rack::Request.new(env)
|
||||||
@res = Rack::Response.new
|
@res = Rack::Response.new
|
||||||
|
|
||||||
|
puts "== Request: #{env["PATH_INFO"]}" if logging?
|
||||||
|
|
||||||
if env["PATH_INFO"] == "/__middleman__" && env["REQUEST_METHOD"] == "POST"
|
if env["PATH_INFO"] == "/__middleman__" && env["REQUEST_METHOD"] == "POST"
|
||||||
if req.params.has_key?("change")
|
if req.params.has_key?("change")
|
||||||
file_did_change(req.params["change"])
|
file_did_change(req.params["change"])
|
||||||
|
@ -402,6 +404,7 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# End the request
|
# End the request
|
||||||
|
puts "== Finishing Request: #{self.current_path}" if logging?
|
||||||
halt res.finish
|
halt res.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,11 @@ module Middleman::Cli
|
||||||
:default => nil,
|
:default => nil,
|
||||||
:desc => 'Build a subset of the project'
|
:desc => 'Build a subset of the project'
|
||||||
def build
|
def build
|
||||||
|
if !ENV["MM_ROOT"]
|
||||||
|
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
if options.has_key?("relative") && options["relative"]
|
if options.has_key?("relative") && options["relative"]
|
||||||
self.class.shared_instance.activate :relative_assets
|
self.class.shared_instance.activate :relative_assets
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,16 +19,21 @@ module Middleman::Cli
|
||||||
:aliases => "-p",
|
:aliases => "-p",
|
||||||
:default => "4567",
|
:default => "4567",
|
||||||
:desc => "The port Middleman will listen on"
|
:desc => "The port Middleman will listen on"
|
||||||
method_option "debug",
|
method_option "verbose",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Print debug messages'
|
:desc => 'Print debug messages'
|
||||||
def server
|
def server
|
||||||
|
if !ENV["MM_ROOT"]
|
||||||
|
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
:port => options["port"],
|
:port => options["port"],
|
||||||
:host => options["host"],
|
:host => options["host"],
|
||||||
:environment => options["environment"],
|
:environment => options["environment"],
|
||||||
:debug => options["debug"]
|
:debug => options["verbose"]
|
||||||
}
|
}
|
||||||
|
|
||||||
puts "== The Middleman is loading"
|
puts "== The Middleman is loading"
|
||||||
|
|
|
@ -57,6 +57,8 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(opts={}, locs={}, &block)
|
def render(opts={}, locs={}, &block)
|
||||||
|
puts "== Render Start: #{source_file}" if app.logging?
|
||||||
|
|
||||||
md = metadata.dup
|
md = metadata.dup
|
||||||
opts = options.deep_merge(md[:options]).deep_merge(opts)
|
opts = options.deep_merge(md[:options]).deep_merge(opts)
|
||||||
locs = locals.deep_merge(md[:locals]).deep_merge(locs)
|
locs = locals.deep_merge(md[:locals]).deep_merge(locs)
|
||||||
|
@ -71,7 +73,10 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
app.instance_eval(&block) if block_given?
|
app.instance_eval(&block) if block_given?
|
||||||
app.render_template(source_file, locs, opts)
|
result = app.render_template(source_file, locs, opts)
|
||||||
|
|
||||||
|
puts "== Render End: #{source_file}" if app.logging?
|
||||||
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue