noahmorrison / chevron

A Python implementation of mustache
MIT License
505 stars 55 forks source link

implement #27 - Lambdas #31

Closed klorenz closed 6 years ago

klorenz commented 6 years ago

Hi @noahmorrison,

I have implemented request #27 as described in https://mustache.github.io/mustache.5.html. I have used @dunkelstern's examples as test items.

Hope you like it.

Best regards, Kiwi

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.554% when pulling 4a84576ba1e4be3a9ac6ea11d24bf9886df3619e on klorenz:master into bc7183d00f185cec75996ab6290d66567bc35d7a on noahmorrison:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.554% when pulling 4a84576ba1e4be3a9ac6ea11d24bf9886df3619e on klorenz:master into bc7183d00f185cec75996ab6290d66567bc35d7a on noahmorrison:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.561% when pulling 3aa1e2b3d72e0d392f24cfc85b98eb61defae5db on klorenz:master into bc7183d00f185cec75996ab6290d66567bc35d7a on noahmorrison:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.554% when pulling 4a84576ba1e4be3a9ac6ea11d24bf9886df3619e on klorenz:master into bc7183d00f185cec75996ab6290d66567bc35d7a on noahmorrison:master.

noahmorrison commented 6 years ago

Hey there!

I'd love to merge this in, I'm in the middle of a summer class right now so it might be a few weeks.

I took a quick look over your code and it seems really nice. One of my biggest concerns with adding lambdas was that it wasn't part of the necessary spec, so if it slowed down rendering I'd at least want it behind a flag. However it looks like if you don't use lambdas, it's just one if statement per token, which shouldn't be too much overhead but I'll have to play with it some.

I really appreciate you doing this, as I said your code looks great and thanks for the unit tests/readme updates as well. I'll play with this when I get the chance and hopefully merge it in :)

klorenz commented 6 years ago

Hi @noahmorrison ,

I have implemented a cache for lambdas for reducing your speed concerns. In case you do not manipulate the template text passed to lambda, the original tokens are fetched from cache.

Best regards, Kiwi

noahmorrison commented 6 years ago

Sorry for the long delay til merge, but I finally got time to check it out. It looks great and I'm very happy with it. Thanks a lot :smile: