/*
 * grunt-css-url-replace
 * https://github.com/NanJingBoy/grunt-css-url-replace
 *
 * Copyright (c) 2013 NanJingBoy
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  // Please see the Grunt documentation for more information regarding task
  // creation: http://gruntjs.com/creating-tasks

  grunt.registerMultiTask('css_url_replace', 'Grunt task to replace css urls with absolute path', function() {
    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
      punctuation: '.',
      separator: ', '
    });

    // Iterate over all specified file groups.
    this.files.forEach(function(f) {
      // Concat specified files.
      var src = 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) {
        // Read file source.
        return grunt.file.read(filepath);
      }).join(grunt.util.normalizelf(options.separator));

      // Handle options.
      src += options.punctuation;

      // Write the destination file.
      grunt.file.write(f.dest, src);

      // Print a success message.
      grunt.log.writeln('File "' + f.dest + '" created.');
    });
  });

};

@@ -165,16 +165,57 @@
 strict';
+%0Avar Replace = require('../lib/replace');
 %0A%0Amodule
@@ -613,17 +613,16 @@
 ation: '
-.
 ',%0A     
@@ -634,18 +634,46 @@
 rator: '
-, 
+%5Cn',%0A      staticRoot: 'public
 '%0A    %7D)
@@ -1168,49 +1168,115 @@
 urce
-.%0A        return grunt.file.read(filepath
+ and replace relative url with absolute ones.%0A        return new Replace(filepath, options.staticRoot).run(
 );%0A 

organize the url replace task