class Middleman::Application

Public Class Methods

cache() click to toggle source

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
helpers(*extensions, &block) click to toggle source

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
new(&block) click to toggle source

Initialize the Middleman project

Calls superclass method
# 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() click to toggle source

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
root_path() click to toggle source

Pathname-addressed root

# File lib/middleman-core/application.rb, line 65
def self.root_path
  Pathname(root)
end

Public Instance Methods

_hooks() click to toggle source

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
build?() click to toggle source

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
development?() click to toggle source

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
inspect()
Alias for: to_s
logger() click to toggle source

Reference to Logger singleton

# File lib/middleman-core/application.rb, line 166
def logger
  ::Middleman::Logger.singleton
end
source_dir() click to toggle source

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
to_s() click to toggle source

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
Also aliased as: inspect