Sha256: 277527c4af5f64a3eb444902893d9f52cf6ffc1cb2e3213251a1ba73c7e5b0b8

Contents?: true

Size: 843 Bytes

Versions: 1

Compression:

Stored size: 843 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(*args)
          super(*args) 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

1 entries across 1 versions & 1 rubygems

Version Path
sprockets-plugin-0.1.2 lib/sprockets/plugin/aware.rb