Created
February 3, 2015 10:30
-
-
Save thefringeninja/29e4904ded45f38dbbed to your computer and use it in GitHub Desktop.
FSharp and DotLiquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Linq | |
let isSimpleType (typ:Type) = | |
typ.IsPrimitive || typ.IsEnum || primitiveTypes.Contains typ | |
open System.Collections | |
open System.Reflection | |
let rec private proxy(target : obj) = | |
let maybeTarget = Some target | |
let result = match maybeTarget with | |
| Some t -> | |
let flags = BindingFlags.Instance ||| BindingFlags.NonPublic ||| BindingFlags.Public | |
let properties = target.GetType().GetProperties(flags) | |
properties | |
|> Seq.map(fun property -> | |
match isSimpleType property.PropertyType with | |
| true -> property.Name, property.GetValue(target) | |
| false -> property.Name, proxy(property.GetValue(target)) :> obj) | |
|> dict | |
| None -> Seq.empty |> dict | |
Hash.FromDictionary(result) | |
let render(view : View) = | |
let template = getTemplate(view.route) | |
match view.model with | |
| null -> template.Render() | |
| _ -> | |
let liquidModel = proxy view | |
template.Render liquidModel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment