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 ||= ::Middleman::Util::Cache.new end
Access class-wide defaults
@private @return [Hash] Hash of default values
# File lib/middleman-core/application.rb, line 42 def defaults @defaults ||= {} 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 33 def 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 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 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
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
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
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
Pathname-addressed root
# File lib/middleman-core/application.rb, line 78 def root_path @_root_path ||= Pathname.new(root) end
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
Backwards compatibilty with old Sinatra template interface
@return [Middleman::Application]
# File lib/middleman-core/application.rb, line 211 def settings self end
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
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