Sha256: 668b75f302634efd4ee408266abfbe3efe2b6281191b30969ea35193299fda38

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 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 = findup('config.rb'))
          ENV['MM_ROOT'] = found_path
        end

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

        true
      end
    end

    private

    # Set BUNDLE_GEMFILE and run Bundler setup. Raises an exception if there is no Gemfile
    def setup_bundler
      ENV['BUNDLE_GEMFILE'] ||= findup('Gemfile', ENV['MM_ROOT'])

      unless File.exist?(ENV['BUNDLE_GEMFILE'])
        ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
      end

      if File.exist?(ENV['BUNDLE_GEMFILE'])
        require 'bundler/setup'
        Bundler.require
      else
        raise "Couldn't find your Gemfile. Middleman projects require a Gemfile for specifying dependencies."
      end
    end

    # Recursive method to find a file in parent directories
    def findup(filename, cwd=Dir.pwd)
      cwd = Pathname(cwd)
      return cwd.to_s if (cwd + filename).exist?
      return false if cwd.root?
      findup(filename, cwd.parent)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
middleman-core-4.0.0 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.rc.3 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.rc.2 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.rc.1 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.beta.2 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.beta.1 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.alpha.6 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.alpha.5 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.alpha.4 lib/middleman-core/load_paths.rb
middleman-core-4.0.0.alpha.3 lib/middleman-core/load_paths.rb