Easy migrating dolar selector to document.id (mootools 1.2.3)


I would like to show you a pair of easy command that will help you if you want to change all your dolar selectors ($) to the new defined document.id in mootools 1.2.3.

The first way can be executed from command line. All you need is having perl on your system. This is the command (change your_file.js to the filename that fits your needs):

perl -i -pe 's/([^\$])\$\(/$1document.id(/g;' your_file.js

Perhaps you will prefer to use -i.old instead -i that will copy your original file your_file.js to your_file.js.old. In this way, you get a backup of your original file.

Of course, this command can be used with others like find so you can migrate more files at once:

for i in $( find /path/to/your/js/files -iname '*.js' ); do perl -i -pe 's/([^\$])\$\(/$1document.id(/g;' $i; done

Finally, for those vim lovers like me, I would like to show you how to make this change inside vim. In command-mode (press <Esc> a pair of times) write:

:%s/\([^\$]\)\$(/\=submatch(1) . "document.id("/g

And that’s all! Enjoy your new brand cross-framework compliant code.

¿Te ha parecido útil este post? Puedes ayudarme con unas monedillas usando dropcoin

Leave a Reply