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 ||= ::Middleman::Util::Cache.new
end
defaults() click to toggle source

Access class-wide defaults

@private @return [Hash] Hash of default values

# File lib/middleman-core/application.rb, line 42
def defaults
  @defaults ||= {}
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 33
def 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 176
def initialize(&block)
  # Clear the static class cache
  cache.clear

  # Setup the default values from calls to set before initialization
  self.class.superclass.defaults.each { |k,v| set(k,v) }

  # Evaluate a passed block if given
  instance_exec(&block) if block_given?

  set :source, ENV["MM_SOURCE"] if ENV["MM_SOURCE"]

  super
end
set(key, value=nil, &block) click to toggle source

Set class-wide defaults

@param [Symbol] key Unique key name @param value Default value @return [void]

# File lib/middleman-core/application.rb, line 51
def set(key, value=nil, &block)
  @defaults ||= {}
  @defaults[key] = value

  @inst.set(key, value, &block) if @inst
end

Public Instance Methods

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 206
def build?; 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?; environment == :development; end
full_path(path) click to toggle source

Expand a path to include the index file if it’s a directory

@private @param [String] path Request path @return [String] Path with index file if necessary

# File lib/middleman-core/application.rb, line 237
def full_path(path)
  resource = sitemap.find_resource_by_destination_path(path)

  if !resource
    # Try it with /index.html at the end
    indexed_path = File.join(path.sub(%r{/$}, ''), index_file)
    resource = sitemap.find_resource_by_destination_path(indexed_path)
  end

  if resource
    '/' + resource.destination_path
  else
    '/' + Middleman::Util.normalize_path(path)
  end
end
root_path() click to toggle source

Pathname-addressed root

# File lib/middleman-core/application.rb, line 78
def root_path
  @_root_path ||= Pathname.new(root)
end
set(key, value=nil, &block) click to toggle source

Set attributes (global variables)

@param [Symbol] key Name of the attribue @param value Attribute value @return [void]

# File lib/middleman-core/application.rb, line 66
def set(key, value=nil, &block)
  setter = "#{key}=".to_sym
  self.class.send(:attr_accessor, key) if !respond_to?(setter)
  value = block if block_given?
  send(setter, value)
end
settings() click to toggle source

Backwards compatibilty with old Sinatra template interface

@return [Middleman::Application]

# File lib/middleman-core/application.rb, line 211
def settings
  self
end
source_dir() click to toggle source

The full path to the source directory

@return [String]

# File lib/middleman-core/application.rb, line 218
def source_dir
  File.join(root, 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 228
def to_s
  "#<Middleman::Application:0x#{object_id}>"
end