Sha256: 0b9aeee3e90076c4525ef2324782d2082d40641d7194da1e0cae0e506e9ce7d7

Contents?: true

Size: 847 Bytes

Versions: 2

Compression:

Stored size: 847 Bytes

Contents

require "sprockets/environment"

module Sprockets
  class Plugin
    module Aware
      def self.included(base)
        base.extend ClassMethods
      end
      
      module ClassMethods
        # Overrides .new to append Plugin paths after
        # initialization.
        #
        # Is there a better way to do this?
        def new(root = ".")
          super(root) do |env|
            env.append_plugin_paths
          end
        end
      end
      
      # Appends the paths from each Sprockets::Plugin
      # to the Sprockets::Environment.
      def append_plugin_paths
        Plugin.plugins.each do |plugin|
          plugin.paths.each do |path|
            self.append_path(path) unless self.paths.include?(path)
          end
        end
      end
    end
  end
end

Sprockets::Environment.send :include, Sprockets::Plugin::Aware

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sprockets-plugin-0.1.1 lib/sprockets/plugin/aware.rb
sprockets-plugin-0.1.0 lib/sprockets/plugin/aware.rb