Skip to content

Commit

Permalink
be lazy with the compiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Sep 29, 2014
1 parent 0f36c8f commit ef989da
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Common/Razor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ type RazorRender(layoutRoots, namespaces, templateName:string, ?model_type:Syste
viewBag.AddValue(k, v)
viewBag

do
handleCompile templateName (fun _ ->
let templateContent = templateResolver.Resolve templateName
match model_type with
| Some t -> Razor.Compile(templateContent, t, templateName)
| None ->
Razor.Compile(templateContent, templateName))

/// Global resolver (for use in 'DocPageTempalateBase')
static member val Resolver = null with get, set
/// Find file in one of the specified layout roots
Expand All @@ -117,22 +109,29 @@ type RazorRender(layoutRoots, namespaces, templateName:string, ?model_type:Syste
| Some f -> f
| None ->
failwith "Could not find template file: %s\nSearching in: %A" name layoutRoots

static member Run<'m>(name, model:'m, viewBag:DynamicViewBag) =
if Razor.Resolve<'m>(name, model) = null then
let templateContent = RazorRender.Resolver.Resolve(name)
Razor.Compile(templateContent, (if obj.ReferenceEquals(model, null) then typeof<'m> else model.GetType()), name)
Razor.Run<'m>(name, model, viewBag)

member internal x.HandleCompile source f = handleCompile source f
member internal x.TemplateName = templateName
member internal x.WithProperties properties = withProperties properties x.ViewBag

/// Dynamic object with more properties (?)
member val ViewBag = new DynamicViewBag() with get,set
member val ViewBag = new DynamicViewBag() with get, set
member x.ProcessFile(?properties) =
Razor.Run(templateName, null, x.WithProperties properties)
handleCompile templateName (fun _ ->
RazorRender.Run<obj>(templateName, null, x.WithProperties properties))
/// Process source file and return result as a string
member x.ProcessFileParse(?properties) =
handleCompile templateName (fun _ ->
Razor.Parse(templateResolver.Resolve templateName, null, x.WithProperties properties, templateName))

member x.ProcessFileModel(model:obj,?properties) =
Razor.Run(templateName, model, x.WithProperties properties)
handleCompile templateName (fun _ ->
RazorRender.Run<obj>(templateName, model, x.WithProperties properties))
/// Process source file and return result as a string
member x.ProcessFileParseModel(model:obj, ?properties) =
handleCompile templateName (fun _ ->
Expand All @@ -142,7 +141,8 @@ and RazorRender<'model>(layoutRoots, namespaces, templateName) =
inherit RazorRender(layoutRoots, namespaces, templateName, typeof<'model>)

member x.ProcessFile(model:'model, ?properties) =
Razor.Run<'model>(x.TemplateName, model, x.WithProperties properties)
x.HandleCompile x.TemplateName (fun _ ->
RazorRender.Run<'model>(x.TemplateName, model, x.WithProperties properties))
/// Process source file and return result as a string
member x.ProcessFileParse(model:'model, ?properties) =
x.HandleCompile x.TemplateName (fun _ ->
Expand Down

0 comments on commit ef989da

Please sign in to comment.