stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.33k stars 221 forks source link

Allow context to be initialised with Any #281

Open adam-fowler opened 4 years ago

adam-fowler commented 4 years ago

Given Mirror is being used to serialize objects that are members of the Context dictionary, it only seems logical we shouldn't be limited to initializing a Context with a dictionary. This PR adds the ability to initialize a context with Any

Initialize Context with Any by converting to dictionary Allow Any to be pushed onto a Context in a similar way Change Environment functions to use these new functions

adam-fowler commented 4 years ago

This will fix https://github.com/stencilproject/Stencil/issues/223#issuecomment-411833557

adam-fowler commented 4 years ago

@ilyapuchka Is this getting merged in or do I need another approval?

adam-fowler commented 3 years ago

Can we possibly avoid the Mirror(...).asDictionary() bit? Stencil already has quite extensive reflection capabilities for multiple types (when rendering a template).

I'll have to have a good look at the code again. It was a wee while ago when I wrote this

adam-fowler commented 3 years ago

Can we possibly avoid the Mirror(...).asDictionary() bit? Stencil already has quite extensive reflection capabilities for multiple types (when rendering a template).

@djbe I had a look through the code again. None of the reflection code seems accessible at this point. Is there function that takes an object and converts it to a [String: Any] somewhere else?