class Middleman::Application
Public Class Methods
Shared cache instance
@private @return [Middleman::Util::Cache] The cache
# File lib/middleman-core/application.rb, line 195 def self.cache @_cache ||= ::Tilt::Cache.new end
Mix-in helper methods. Accepts either a list of Modules and/or a block to be evaluated @return [void]
# File lib/middleman-core/application.rb, line 51 def self.helpers(*extensions, &block) class_eval(&block) if block_given? include(*extensions) if extensions.any? end
Initialize the Middleman
project
# File lib/middleman-core/application.rb, line 171 def initialize(&block) # Clear the static class cache cache.clear # Setup the default values from calls to set before initialization self.class.config.load_settings(self.class.superclass.config.all_settings) if Object.const_defined?(:Encoding) Encoding.default_internal = config[:encoding] Encoding.default_external = config[:encoding] end # Evaluate a passed block if given instance_exec(&block) if block_given? config[:source] = ENV['MM_SOURCE'] if ENV['MM_SOURCE'] super end
Root project directory (overwritten in middleman build/server) @return [String]
# File lib/middleman-core/application.rb, line 59 def self.root ENV['MM_ROOT'] || Dir.pwd end
Pathname-addressed root
# File lib/middleman-core/application.rb, line 65 def self.root_path Pathname(root) end
Public Instance Methods
Hooks clones _hooks from the class to the instance. github.com/apotonick/hooks/blob/master/lib/hooks/instance_hooks.rb#L10 Middleman
expects the same list of hooks for class and instance hooks:
# File lib/middleman-core/application.rb, line 233 def _hooks self.class._hooks end
Whether we’re in build mode @return [Boolean] If we’re in build mode
# File lib/middleman-core/application.rb, line 208 def build? config[:environment] == :build end
Whether we’re in development mode @return [Boolean] If we’re in dev mode
# File lib/middleman-core/application.rb, line 202 def development? config[:environment] == :development end
Reference to Logger
singleton
# File lib/middleman-core/application.rb, line 166 def logger ::Middleman::Logger.singleton end
The full path to the source directory
@return [String]
# File lib/middleman-core/application.rb, line 215 def source_dir File.join(root, config[:source]) end
Work around this bug: bugs.ruby-lang.org/issues/4521 where Ruby will call to_s/inspect while printing exception messages, which can take a long time (minutes at full CPU) if the object is huge or has cyclic references, like this.
# File lib/middleman-core/application.rb, line 225 def to_s "#<Middleman::Application:0x#{object_id}>" end