View Single Post
Old 10-12-2022, 09:56 AM   #49
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,221
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
@capink: do you see a use for constructing your own python formatter context object and passing it to the formatter? One I thought of is what you mentioned in the development thread: adding "helper methods" to the context.

The mechanism would work like globals. If an instance isn't provided (a named parameter) then the formatter would construct one. If one is provided then it will be used, with the lifetime controlled by you.
Yes. Actually I was thinking about this. Before you mentioned this I thought of two ways:
  • Use the chain object that I would smuggle inside the globals dict for defining these methods. Your proposal is much cleaner way of doing this.
  • Monkey patching calibre's context class. I am not sure how clean/desirable this would be. But if offers me one thing none of the other options do; the ability to use any plugin defined helper functions in calibre's template search.
capink is offline   Reply With Quote