cloudhead/less.js — pull request #1005 by adorsk (2012-10-26 18:34:43+00:00)
Title: Rewrite url paths based on rewrite rules

I would like to add the ability to rewrite paths based on a set of rewrite rules.

For example, I would like to do the following:

```
lessText = 'body {background-image: url("path1");}';

less.rewriteRules = [
[/path1/, 'newPath1']
]

parser = new less.Parser();
parser.parse(lessText, function(err, tree){
console.log(tree.toCSS());
})
```

This would yield:

```
body {
background-image: url("newPath1")
}
```

### Use Case for This Feature
The ability to rewrite paths would make it possible to write modular CSS with less, by making it possible to annotate modules through the use of unique URIs.

For example, say I have a module 'common' that includes these files:
```
common/
buttons.less
tooltips.less
images/
cancel.png
...
...
```

I want to write another module, 'moduleA', that can access these files. However, I don't know yet where the 'common' module will be located yet in relation to 'moduleA'. So what I do is I use a path identifier for 'common', like this:

```
moduleA/style.less:

@import url('module:common:buttons.less');
```

Then, in my less.rewritePaths function, I can map the identifier path to the actual path when I know it:
```
less.rewritePaths = function(path){
return path.replace(/module:common:/, '/the/real/path/to/common');
}
```