class Middleman::Application
def initialize(&block)
def initialize(&block) # Search the root of the project for required files $LOAD_PATH.unshift(root) unless $LOAD_PATH.include?(root) ::Middleman::Util.instrument 'application.setup' do @callbacks = ::Middleman::CallbackManager.new @callbacks.install_methods!(self, [ :initialized, :configure, :before_extensions, :before_instance_block, :before_sitemap, :before_configuration, :after_configuration, :after_configuration_eval, :ready, :before_build, :after_build, :before_shutdown, :before, # Before Rack requests :before_render, :after_render, :before_server, :reload ]) @middleware = Set.new @mappings = Set.new @template_context_class = Class.new(Middleman::TemplateContext) @generic_template_context = @template_context_class.new(self) @config_context = ConfigContext.new(self, @template_context_class) # Setup the default values from calls to set before initialization @config = ::Middleman::Configuration::ConfigurationManager.new @config.load_settings(self.class.config.all_settings) config[:source] = ENV['MM_SOURCE'] if ENV['MM_SOURCE'] # TODO, make this less global ::Middleman::FileRenderer.cache.clear ::Middleman::TemplateRenderer.cache.clear end execute_callbacks(:before_extensions) @extensions = ::Middleman::ExtensionManager.new(self) execute_callbacks(:before_instance_block) # Evaluate a passed block if given config_context.instance_exec(&block) if block_given? apply_cli_options execute_callbacks(:before_sitemap) # Initialize the Sitemap @sitemap = ::Middleman::Sitemap::Store.new(self) ::Middleman::Extension.clear_after_extension_callbacks # Before config is parsed, before extensions get to it. execute_callbacks(:initialized) # Before config is parsed. Mostly used for extensions. execute_callbacks(:before_configuration) # Eval config. evaluate_configuration! # Run any `configure` blocks for the current environment. execute_callbacks([:configure, config[:environment]]) # Run any `configure` blocks for the current mode. execute_callbacks([:configure, config[:mode]]) apply_cli_options # Post parsing, pre-extension callback execute_callbacks(:after_configuration_eval) if Object.const_defined?(:Encoding) Encoding.default_external = config[:encoding] end # After extensions have worked after_config execute_callbacks(:after_configuration) # Everything is stable execute_callbacks(:ready) unless config[:exit_before_ready] end