Separate Environments from Modes
This commit is contained in:
parent
d035b449ea
commit
a21dca025e
19 changed files with 113 additions and 97 deletions
|
@ -11,8 +11,6 @@ module Middleman
|
|||
app.define_hook :instance_available
|
||||
app.define_hook :after_configuration
|
||||
app.define_hook :before_configuration
|
||||
app.define_hook :build_config
|
||||
app.define_hook :development_config
|
||||
|
||||
app.config.define_setting :autoload_sprockets, true, 'Automatically load sprockets at startup?'
|
||||
app.config[:autoload_sprockets] = (ENV['AUTOLOAD_SPROCKETS'] == 'true') if ENV['AUTOLOAD_SPROCKETS']
|
||||
|
@ -26,11 +24,11 @@ module Middleman
|
|||
#
|
||||
# @example
|
||||
# # Only minify when building
|
||||
# configure :build do
|
||||
# configure :production do
|
||||
# activate :minify_javascript
|
||||
# end
|
||||
#
|
||||
# @param [String, Symbol] env The environment to run in (:build, :development)
|
||||
# @param [String, Symbol] env The environment to run in
|
||||
# @return [void]
|
||||
def configure(env, &block)
|
||||
send("#{env}_config", &block)
|
||||
|
@ -80,18 +78,19 @@ module Middleman
|
|||
|
||||
# Override application initialization to load `config.rb` and to call lifecycle hooks.
|
||||
def initialize(&block)
|
||||
super
|
||||
|
||||
self.class.inst = self
|
||||
|
||||
# Search the root of the project for required files
|
||||
$LOAD_PATH.unshift(root) unless $LOAD_PATH.include?(root)
|
||||
|
||||
# Evaluate a passed block if given
|
||||
config_context.instance_exec(&block) if block_given?
|
||||
|
||||
super
|
||||
|
||||
::Middleman::Extension.clear_after_extension_callbacks
|
||||
|
||||
::Middleman::Extensions.auto_activate[:before_configuration].each do |ext_name|
|
||||
activate ext_name
|
||||
end
|
||||
::Middleman::Extensions.auto_activate(:before_configuration, self)
|
||||
|
||||
if config[:autoload_sprockets]
|
||||
begin
|
||||
|
@ -102,9 +101,6 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
# Evaluate a passed block if given
|
||||
config_context.instance_exec(&block) if block_given?
|
||||
|
||||
run_hook :initialized
|
||||
|
||||
run_hook :before_configuration
|
||||
|
@ -112,19 +108,17 @@ module Middleman
|
|||
# Check for and evaluate local configuration in `config.rb`
|
||||
local_config = File.join(root, 'config.rb')
|
||||
if File.exist? local_config
|
||||
logger.debug '== Reading: Local config'
|
||||
logger.debug '== Reading: Local config'
|
||||
config_context.instance_eval File.read(local_config), local_config, 1
|
||||
end
|
||||
|
||||
if build?
|
||||
run_hook :build_config
|
||||
config_context.execute_configure_callbacks(:build)
|
||||
env_config = File.join(root, 'environments', "#{config[:environment]}.rb")
|
||||
if File.exist? env_config
|
||||
logger.debug "== Reading: #{config[:environment]} config"
|
||||
config_context.instance_eval File.read(env_config), env_config, 1
|
||||
end
|
||||
|
||||
if development?
|
||||
run_hook :development_config
|
||||
config_context.execute_configure_callbacks(:development)
|
||||
end
|
||||
config_context.execute_configure_callbacks(config[:environment])
|
||||
|
||||
run_hook :instance_available
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue