Sha256: 7aca6e3c2638e2859df260048f67330637801edefc2e99189b1f650fe677069b

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

# Core Pathname library used for traversal
require 'pathname'

module Sculptor
  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

          unless File.exist?(ENV['BUNDLE_GEMFILE'])
            git_gemfile = Pathname.new(__FILE__).expand_path.parent.parent.parent + 'Gemfile'
            ENV['BUNDLE_GEMFILE'] = git_gemfile.to_s
          end

          if File.exist?(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

14 entries across 14 versions & 1 rubygems

Version Path
sculptor-0.0.11.1 lib/sculptor/load_paths.rb
sculptor-0.0.11 lib/sculptor/load_paths.rb
sculptor-0.0.10 lib/sculptor/load_paths.rb
sculptor-0.0.9.3 lib/sculptor/load_paths.rb
sculptor-0.0.9.2 lib/sculptor/load_paths.rb
sculptor-0.0.9.1 lib/sculptor/load_paths.rb
sculptor-0.0.9 lib/sculptor/load_paths.rb
sculptor-0.0.8 lib/sculptor/load_paths.rb
sculptor-0.0.7 lib/sculptor/load_paths.rb
sculptor-0.0.6 lib/sculptor/load_paths.rb
sculptor-0.0.5 lib/sculptor/load_paths.rb
sculptor-0.0.4 lib/sculptor/load_paths.rb
sculptor-0.0.3 lib/sculptor/load_paths.rb
sculptor-0.0.2 lib/sculptor/load_paths.rb