/*
 * grunt-import
 * http://gruntjs.com/
 *
 * Copyright (c) 2013 Marcin Rosinski, contributors
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  grunt.registerMultiTask('import', '@import - inline file import.', function() {

        var path = require('path');

        // Merge task-specific and/or target-specific options with these defaults.
        var options = this.options({
          separator: grunt.util.linefeed,
          banner: '',
          footer: ''
        });

        // Process banner and footer.
        var banner  = grunt.template.process(options.banner);
        var footer  = grunt.template.process(options.footer);
        var target  = this.target;

        var importRecursive = function(filepath)
        {
            var src = grunt.file.read(filepath);
            var importReg = src.match(/@import ['"](.*)['"]/g);
            
            if(importReg && importReg.length)
            {
                for(var i in importReg)
                {
                    var importpath = importReg[i].replace('@import ','').replace(/"/g,'').replace(/'/g,'');

                    if(importpath.indexOf('/')!==0)
                    {
                        importpath = path.resolve(path.dirname(filepath)+'/'+importpath);
                    }

                    if(grunt.file.exists(importpath))
                    {
                        var isrc = importRecursive(importpath);
                        src = src.split(importReg[i]+';').join(isrc);
                        src = src.split(importReg[i]).join(isrc);
                    }
                    else
                    {
                        grunt.log.warn('@import file "' + importpath + '" not found.');
                        src = src.split(importReg[i]+';').join('');
                        src = src.split(importReg[i]).join('');
                    }
                }
            }
            
            return src;
        };

        // Iterate over all src-dest file pairs.
        this.files.forEach(function(f) {

          // Prepend banner + @import + specified files + footer.
          var src = banner + f.src.filter(function(filepath) {

            // Warn on and remove invalid source files (if nonull was set).
            if (!grunt.file.exists(filepath)) {
              grunt.log.warn('Source file "' + filepath + '" not found.');
              return false;
            } else {
              return true;
            }

          }).map(function(filepath) {

            return importRecursive(filepath);

          }).join(options.separator) + footer;

          // Write the destination file.
          grunt.file.write(f.dest, src);
          grunt.event.emit('import', 'imported', f.dest, target);
          
          // Print a success message.
          grunt.log.writeln('File "' + f.dest + '" created.');
        });

        //Run tasks
        if(this.data.tasks){
          grunt.task.run(this.data.tasks);
        }
    });

};

@@ -717,16 +717,663 @@
 arget;%0A%0A
+        var explode  = function(delimiter, string, limit) %7B%0A%0A          delimiter += '';%0A          string += '';%0A%0A          var s = string.split( delimiter );%0A          if ( typeof limit === 'undefined' ) return s;%0A%0A          // Support for limit%0A          if ( limit === 0 ) limit = 1;%0A%0A          // Positive limit%0A          if ( limit %3E 0 )%7B%0A            if ( limit %3E= s.length ) return s;%0A            return s.slice( 0, limit - 1 ).concat( %5B s.slice( limit - 1 ).join( delimiter ) %5D );%0A          %7D%0A%0A          // Negative limit%0A          if ( -limit %3E= s.length ) return %5B%5D;%0A%0A          s.splice( s.length + limit );%0A          return s;%0A        %7D%0A%0A
         
@@ -1409,24 +1409,24 @@
 n(filepath)%0A
-
         %7B%0A  
@@ -2129,33 +2129,31 @@
       src = 
-src.split
+explode
 (importReg%5Bi
@@ -2153,24 +2153,30 @@
 rtReg%5Bi%5D+';'
+,src,2
 ).join(isrc)
@@ -2203,33 +2203,31 @@
       src = 
-src.split
+explode
 (importReg%5Bi
@@ -2223,24 +2223,30 @@
 importReg%5Bi%5D
+,src,2
 ).join(isrc)
@@ -2430,33 +2430,31 @@
       src = 
-src.split
+explode
 (importReg%5Bi
@@ -2458,16 +2458,22 @@
 g%5Bi%5D+';'
+,src,2
 ).join('
@@ -2510,17 +2510,15 @@
 c = 
-src.split
+explode
 (imp
@@ -2526,16 +2526,22 @@
 rtReg%5Bi%5D
+,src,2
 ).join('

Update import.js