Sha256: 03c13b966050dfe66af7465603ec020a9bb59fba2d65df4378433e772d304213

Contents?: true

Size: 1.45 KB

Versions: 9

Compression:

Stored size: 1.45 KB

Contents

module Middleman
  module Sprockets
    # A fake Sprockets environment that just exposes the
    # waits to create the environment until asked, but can still
    # service most of the interesting configuration methods. This
    # allows sprockets to be configured any time in config.rb, rather
    # than having to use an after_configuration block.
    class ConfigOnlyEnvironment
      attr_reader :imported_assets
      attr_reader :appended_paths
      attr_reader :prepended_paths

      def initialize(options={})
        @imported_assets = []
        @appended_paths = []
        @prepended_paths = []
      end

      def method_missing?(method)
        raise NoMethodError, "The Sprockets environment is not ready yet, so you can't call #{method} on it. If you need to call this method do it in a 'ready' block."
      end

      def apply_to_environment(environment)
        @imported_assets.each do |(path, directory)|
          environment.import_asset path, &directory
        end

        @appended_paths.each do |path|
          environment.append_path path
        end

        @prepended_paths.each do |path|
          environment.prepend_path path
        end
      end

      def import_asset(asset_logical_path, &output_directory)
        @imported_assets << [asset_logical_path, output_directory]
      end

      def append_path(path)
        @appended_paths << path
      end

      def prepend_path(path)
        @prepended_paths << path
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
middleman-sprockets-4.0.0.beta.1 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.4.2 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.4.1 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.3.10 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.3.9 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.3.8 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.3.7 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-cj-3.3.6 lib/middleman-sprockets/config_only_environment.rb
middleman-sprockets-3.3.6 lib/middleman-sprockets/config_only_environment.rb