Move more things over to new configs. Don't let root be configured

This commit is contained in:
Ben Hollis 2012-10-13 22:37:24 -07:00
parent a50ca56fbc
commit 4fe22e3fb5
14 changed files with 42 additions and 39 deletions

View file

@ -29,26 +29,25 @@ module Middleman
# Ready (all loading and parsing of extensions complete) hook
define_hook :ready
class << self
# Mix-in helper methods. Accepts either a list of Modules
# and/or a block to be evaluated
# @return [void]
def helpers(*extensions, &block)
def self.helpers(*extensions, &block)
class_eval(&block) if block_given?
include(*extensions) if extensions.any?
end
end
delegate :helpers, :to => :"self.class"
# Root project directory (overwritten in middleman build/server)
# @return [String]
config.define_setting :root, (ENV["MM_ROOT"] || Dir.pwd), 'Root project directory'
def self.root
ENV["MM_ROOT"] || Dir.pwd
end
delegate :root, :to => :"self.class"
# Pathname-addressed root
def self.root_path
Pathname(config[:root])
Pathname(root)
end
delegate :root_path, :to => :"self.class"
@ -96,14 +95,6 @@ module Middleman
# @return [String]
config.define_setting :http_prefix, "/", 'Default prefix for building paths'
# Default string encoding for templates and output.
# @return [String]
config.define_setting :encoding, "utf-8", 'Default string encoding for templates and output'
# Whether to catch and display exceptions
# @return [Boolean]
config.define_setting :show_exceptions, true, 'Whether to catch and display exceptions'
# Default layout name
# @return [String, Symbold]
config.define_setting :layout, :_auto_layout, 'Default layout name'
@ -182,7 +173,7 @@ module Middleman
#
# @return [String]
def source_dir
File.join(config[:root], config[:source])
File.join(root, config[:source])
end
delegate :logger, :instrument, :to => ::Middleman::Util

View file

@ -114,7 +114,7 @@ module Middleman::Cli
# @param [Middleman::Sitemap::Resource] resource
# @return [String] The full path of the file that was written
def render_to_file(resource)
build_dir = self.class.shared_instance.build_dir
build_dir = self.class.shared_instance.config[:build_dir]
output_file = File.join(build_dir, resource.destination_path)
begin

View file

@ -18,7 +18,7 @@ module Middleman
# After config
app.after_configuration do
helpers_path = File.expand_path(config[:helpers_dir], config[:root])
helpers_path = File.join(root, config[:helpers_dir])
next unless File.exists?(helpers_path)
Dir[File.join(helpers_path, config[:helpers_filename_glob])].each do |filename|

View file

@ -29,7 +29,7 @@ module Middleman
# Before parsing config, load the data/ directory
app.before_configuration do
files.reload_path(data_dir)
files.reload_path(config[:data_dir])
end
# After config, load everything else

View file

@ -62,7 +62,7 @@ module Middleman::CoreExtensions
def clear_data(file)
# Copied from Sitemap::Store#file_to_path, but without
# removing the file extension
file = File.expand_path(file, @app.root)
file = File.join(@app.root, file)
prefix = @app.source_dir.sub(/\/$/, "") + "/"
return unless file.include?(prefix)
path = file.sub(prefix, "")

View file

@ -272,7 +272,7 @@ module Middleman
# @return [String]
def fetch_layout(engine, opts)
# The layout name comes from either the system default or the options
local_layout = opts.has_key?(:layout) ? opts[:layout] : layout
local_layout = opts.has_key?(:layout) ? opts[:layout] : config[:layout]
return false unless local_layout
# Look for engine-specific options

View file

@ -28,7 +28,7 @@ module Middleman
# @param [String, Symbol] layout_name
# @return [void]
def with_layout(layout_name, &block)
old_layout = layout
old_layout = config[:layout]
config[:layout] = layout_name
instance_exec(&block) if block_given?
@ -50,7 +50,7 @@ module Middleman
blocks << block if block_given?
# Default layout
opts[:layout] = layout if opts[:layout].nil?
opts[:layout] = config[:layout] if opts[:layout].nil?
# If the url is a regexp
if url.is_a?(Regexp) || url.include?("*")
@ -66,7 +66,7 @@ module Middleman
# Normalized path
url = '/' + Middleman::Util.normalize_path(url)
if url.end_with?('/') || File.directory?(File.join(source_dir, url))
url = File.join(url, index_file)
url = File.join(url, config[:index_file])
end
# Setup proxy

View file

@ -6,6 +6,10 @@ module Middleman::CoreExtensions::RubyEncoding
# Once registerd
def registered(app)
# Default string encoding for templates and output.
# @return [String]
app.config.define_setting :encoding, "utf-8", 'Default string encoding for templates and output'
app.send :include, InstanceMethods
end
@ -15,8 +19,8 @@ module Middleman::CoreExtensions::RubyEncoding
module InstanceMethods
def initialize
if Object.const_defined?(:Encoding)
Encoding.default_internal = encoding
Encoding.default_external = encoding
Encoding.default_internal = config[:encoding]
Encoding.default_external = config[:encoding]
end
super

View file

@ -11,10 +11,14 @@ module Middleman
# Once registered
def registered(app)
# Whether to catch and display exceptions
# @return [Boolean]
app.config.define_setting :show_exceptions, true, 'Whether to catch and display exceptions'
# When in dev
app.configure :development do
# Include middlemare
if show_exceptions
if config[:show_exceptions]
use ::Middleman::CoreExtensions::ShowExceptions::Middleware
end
end

View file

@ -19,7 +19,7 @@ module Middleman
end
app.after_configuration do
::Less.paths << File.expand_path(css_dir, source_dir)
::Less.paths << File.join(source_dir, config[:css_dir])
end
# Tell Tilt to use it as well (for inline sass blocks)

View file

@ -45,7 +45,7 @@ module Middleman
path = @sitemap.file_to_path(file)
return false unless path
ignored = @app.ignored_sitemap_matchers.any? do |name, callback|
ignored = @app.config[:ignored_sitemap_matchers].any? do |name, callback|
callback.call(file)
end
@ -85,7 +85,7 @@ module Middleman
::Middleman::Sitemap::Resource.new(
@sitemap,
@sitemap.file_to_path(file),
File.expand_path(file, @app.root)
File.join(@app.root, file)
)
end
end

View file

@ -164,7 +164,7 @@ module Middleman
# @param [String] file
# @return [String]
def file_to_path(file)
file = File.expand_path(file, @app.root)
file = File.join(@app.root, file)
prefix = @app.source_dir.sub(/\/$/, "") + "/"
return false unless file.start_with?(prefix)
@ -172,8 +172,8 @@ module Middleman
path = file.sub(prefix, "")
# Replace a file name containing automatic_directory_matcher with a folder
unless @app.automatic_directory_matcher.nil?
path = path.gsub(@app.automatic_directory_matcher, "/")
unless @app.config[:automatic_directory_matcher].nil?
path = path.gsub(@app.config[:automatic_directory_matcher], "/")
end
extensionless_path(path)

View file

@ -10,9 +10,12 @@ end
Given /^an empty app$/ do
step %Q{a directory named "empty_app"}
step %Q{I cd to "empty_app"}
ENV["MM_ROOT"] = nil
end
Given /^a fixture app "([^\"]*)"$/ do |path|
ENV["MM_ROOT"] = nil
# This step can be reentered from several places but we don't want
# to keep re-copying and re-cd-ing into ever-deeper directories
next if File.basename(current_dir) == path

View file

@ -40,9 +40,10 @@ Given /^the Server is running$/ do
ENV["MM_SOURCE"] = ""
end
ENV["MM_ROOT"] = root_dir
initialize_commands = @initialize_commands || []
initialize_commands.unshift lambda {
set :root, root_dir
set :environment, @current_env || :development
set :show_exceptions, false
}