Sha256: 8e063c65814b96dea8dca84f174c712361d0db03915993059d268adb30dda0fe

Contents?: true

Size: 784 Bytes

Versions: 3

Compression:

Stored size: 784 Bytes

Contents

module Sprockets
  module Directives
    class RequireDirective < Directive
      def self.pattern
        /(require)\s+(#{ANGLED_STRING})/
      end
      
      def evaluate_in(preprocessor)
        if source_file_path
          preprocessor.require(source_file_path.source_file)
        else
          raise_load_error
        end
      end
      
      def source_file_path
        @source_file_path ||= location_finder.find(normalize(require_location))
      end
      
      def require_location
        parse_angled_string(argument)
      end

      protected
        def location_finder
          environment
        end
        
        def normalize(location)
          File.join(File.dirname(location), File.basename(location, ".js") + ".js")
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sprockets-foo-0.0.4 ext/sprockets_with_directives/lib/sprockets/directives/require_directive.rb
sprockets-foo-0.0.3 ext/sprockets_with_directives/lib/sprockets/directives/require_directive.rb
sprockets-foo-0.0.2 ext/sprockets_with_directives/lib/sprockets/directives/require_directive.rb