module Middleman

Top-level Middleman namespace

Core Middleman Class

CLI Module

Namespace extensions module

Load helpers in helpers/

API for watching file change events

Rendering extension

Routing extension

Support rack/showexceptions during development

ERb renderer

Core Sitemap Extensions

Constants

EXTENSION_FILE

Where to look in gems for extensions to auto-register

VERSION

Current Version @return [String]

Public Class Methods

load_extensions_in_path() click to toggle source

Automatically load extensions from available RubyGems which contain the EXTENSION_FILE

@private

# File lib/middleman-core/extensions.rb, line 60
def load_extensions_in_path
  require "rubygems"

  begin
    require "middleman-more"
  rescue LoadError
  end

  extensions = rubygems_latest_specs.select do |spec|
    spec_has_file?(spec, EXTENSION_FILE)
  end

  extensions.each do |spec|
    require spec.name
  end
end
locate_root(cwd = Pathname.new(Dir.pwd)) click to toggle source

Recursive method to find config.rb

# File lib/middleman-core/load_paths.rb, line 48
def locate_root(cwd = Pathname.new(Dir.pwd))
  return cwd.to_s if (cwd + 'config.rb').exist?
  return false if cwd.root?
  locate_root(cwd.parent)
end
rubygems_latest_specs() click to toggle source

Backwards compatible means of finding all the latest gemspecs available on the system

@private @return [Array] Array of latest Gem::Specification

# File lib/middleman-core/extensions.rb, line 82
def rubygems_latest_specs
  # If newer Rubygems
  if ::Gem::Specification.respond_to? :latest_specs
    ::Gem::Specification.latest_specs
  else
    ::Gem.source_index.latest_specs
  end
end
setup_load_paths() click to toggle source
# File lib/middleman-core/load_paths.rb, line 7
def setup_load_paths
  @_is_setup ||= begin

    # Only look for config.rb if MM_ROOT isn't set
    if !ENV["MM_ROOT"] && found_path = locate_root
      ENV["MM_ROOT"] = found_path
    end

    is_bundler_setup = false

    # If we've found the root, try to setup Bundler
    if ENV["MM_ROOT"]

      root_gemfile = File.expand_path('Gemfile', ENV["MM_ROOT"])
      ENV['BUNDLE_GEMFILE'] ||= root_gemfile

      if !File.exists?(ENV['BUNDLE_GEMFILE'])
        git_gemfile = Pathname.new(__FILE__).expand_path.parent.parent.parent + "Gemfile"
        ENV['BUNDLE_GEMFILE'] = git_gemfile.to_s
      end

      if File.exists?(ENV['BUNDLE_GEMFILE'])
        is_bundler_setup = true
        require 'bundler/setup'
      end
    end

    # Automatically discover extensions in RubyGems
    require "middleman-core/extensions"

    if is_bundler_setup
      Bundler.require
    else
      ::Middleman.load_extensions_in_path
    end

    true
  end
end
spec_has_file?(spec, path) click to toggle source

Where a given Gem::Specification has a specific file. Used to discover extensions.

@private @param [Gem::Specification] spec @param [String] path Path to look for @return [Boolean] Whether the file exists

# File lib/middleman-core/extensions.rb, line 98
def spec_has_file?(spec, path)
  full_path = File.join(spec.full_gem_path, path)
  File.exists?(full_path)
end