Sha256: e478fb44c98256b92697f3f1931cbc6b559fe9ef41db14c6ab1490d1b93eb9ca

Contents?: true

Size: 1.36 KB

Versions: 51

Compression:

Stored size: 1.36 KB

Contents

# Core Pathname library used for traversal
require "pathname"

module Middleman

  class << self
    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

    # Recursive method to find config.rb
    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

  end

end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
middleman-core-3.2.1 lib/middleman-core/load_paths.rb
middleman-core-3.2.0 lib/middleman-core/load_paths.rb
middleman-core-3.1.6 lib/middleman-core/load_paths.rb
middleman-core-3.1.5 lib/middleman-core/load_paths.rb
middleman-core-3.1.4 lib/middleman-core/load_paths.rb
middleman-core-3.1.3 lib/middleman-core/load_paths.rb
middleman-core-3.1.2 lib/middleman-core/load_paths.rb
middleman-core-3.1.1 lib/middleman-core/load_paths.rb
middleman-core-3.1.0 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.rc.4 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.rc.3 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.rc.2 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.rc.1 lib/middleman-core/load_paths.rb
middleman-core-x86-mingw32-3.0.14 lib/middleman-core/load_paths.rb
middleman-core-3.0.14 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.beta.3 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.beta.2 lib/middleman-core/load_paths.rb
middleman-core-3.1.0.beta.1 lib/middleman-core/load_paths.rb
middleman-core-x86-mingw32-3.0.13 lib/middleman-core/load_paths.rb
middleman-core-3.0.13 lib/middleman-core/load_paths.rb