Rewrite template resolving
Rewrite template resolving

This rewrite has these purposes:

1. Add support for multiple extensions in the resolver.

2. Make matching from requested file to returned template file more
predictable.

3. Decrease complexity in matching code, especially in regard to
the "prefer" option.

DigitPaint/roger,DigitPaint/roger