Skip to content

Commit 6d9a168

Browse files
committed
Re-factored Virtual FileSystem to include ParentDirectory/CWD
Changed AppHost to maintain a list of IViewEngines instead of delegates Added default templates for ContentPages
1 parent 506d8ab commit 6d9a168

33 files changed

Lines changed: 545 additions & 291 deletions

src/ServiceStack.Razor/RazorFormat.cs

Lines changed: 227 additions & 155 deletions
Large diffs are not rendered by default.

src/ServiceStack.Razor/Templating/TemplateService.ServiceStack.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,29 @@ public IRazorTemplate ExecuteTemplate<T>(T model, string name, string templatePa
3131

3232
instance.Execute();
3333

34-
if (templatePath != null && !razorTemplate.Layout.IsNullOrEmpty())
34+
if (templatePath == null && !razorTemplate.Layout.IsNullOrEmpty())
3535
templatePath = razorTemplate.Layout.MapServerPath();
3636

37-
if (templatePath != null)
37+
var layoutTemplate = GetTemplate(templatePath ?? RazorFormat.DefaultTemplate);
38+
if (layoutTemplate != null)
3839
{
39-
var layoutTemplate = GetTemplate(templatePath);
40-
if (layoutTemplate == null)
41-
throw new ArgumentException(
42-
"No template exists with the specified Layout: " + templatePath);
43-
4440
layoutTemplate.ChildTemplate = razorTemplate;
4541
SetService(layoutTemplate, this);
4642
SetModel(layoutTemplate, model);
4743
layoutTemplate.Execute();
4844

4945
return layoutTemplate;
5046
}
47+
else if (templatePath != null)
48+
{
49+
throw new ArgumentException(
50+
"No template exists with the specified Layout: " + templatePath);
51+
}
5152

5253
return razorTemplate;
5354
}
5455

55-
Dictionary<string, string> pagePathAndNames = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
56+
readonly Dictionary<string, string> pagePathAndNames = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
5657

5758
public void RegisterPage(string pagePath, string pageName)
5859
{

src/ServiceStack.Razor/ViewPageRef.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ViewPageRef
2323
public string Contents { get; set; }
2424

2525
public RazorPageType PageType { get; set; }
26-
public string TemplatePath { get; set; }
26+
public string Template { get; set; }
2727
public string DirectiveTemplatePath { get; set; }
2828
public DateTime? LastModified { get; set; }
2929
public List<IExpirable> Dependents { get; private set; }
@@ -65,7 +65,7 @@ public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string
6565

6666
public string GetTemplatePath()
6767
{
68-
return this.DirectiveTemplatePath ?? this.TemplatePath;
68+
return this.DirectiveTemplatePath ?? this.Template;
6969
}
7070

7171
public string PageName
@@ -143,7 +143,7 @@ public string RenderToHtml<T>(T model)
143143

144144
public string RenderToString<T>(T model)
145145
{
146-
var template = RazorFormat.ExecuteTemplate(model, this.PageName, this.TemplatePath);
146+
var template = RazorFormat.ExecuteTemplate(model, this.PageName, this.Template);
147147
return template.Result;
148148
}
149149
}

src/ServiceStack.ServiceInterface/Testing/BasicAppHost.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Reflection;
55
using Funq;
6+
using ServiceStack.Html;
67
using ServiceStack.ServiceHost;
78
using ServiceStack.WebHost.Endpoints;
89

@@ -15,7 +16,7 @@ public BasicAppHost()
1516
this.Container = new Container();
1617
this.RequestFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
1718
this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
18-
this.HtmlProviders = new List<StreamSerializerResolverDelegate>();
19+
this.ViewEngines = new List<IViewEngine>();
1920
this.CatchAllHandlers = new List<HttpHandlerResolverDelegate>();
2021
}
2122

@@ -46,7 +47,7 @@ public T TryResolve<T>()
4647

4748
public List<Action<IHttpRequest, IHttpResponse, object>> ResponseFilters { get; set; }
4849

49-
public List<StreamSerializerResolverDelegate> HtmlProviders { get; set; }
50+
public List<IViewEngine> ViewEngines { get; set; }
5051

5152
public List<HttpHandlerResolverDelegate> CatchAllHandlers { get; set; }
5253

src/ServiceStack.ServiceInterface/Testing/TestAppHost.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using Funq;
66
using ServiceStack.Common.Web;
7+
using ServiceStack.Html;
78
using ServiceStack.ServiceHost;
89
using ServiceStack.WebHost.Endpoints;
910

@@ -31,7 +32,7 @@ public TestAppHost(Funq.Container container, params Assembly[] serviceAssemblies
3132
this.ContentTypeFilters = new HttpResponseFilter();
3233
this.RequestFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
3334
this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
34-
this.HtmlProviders = new List<StreamSerializerResolverDelegate>();
35+
this.ViewEngines = new List<IViewEngine>();
3536
this.CatchAllHandlers = new List<HttpHandlerResolverDelegate>();
3637
}
3738

@@ -60,7 +61,7 @@ public T TryResolve<T>()
6061

6162
public List<Action<IHttpRequest, IHttpResponse, object>> ResponseFilters { get; set; }
6263

63-
public List<StreamSerializerResolverDelegate> HtmlProviders { get; private set; }
64+
public List<IViewEngine> ViewEngines { get; private set; }
6465

6566
public List<HttpHandlerResolverDelegate> CatchAllHandlers { get; private set; }
6667

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
namespace ServiceStack.Html
1+
using ServiceStack.ServiceHost;
2+
3+
namespace ServiceStack.Html
24
{
35
public interface IViewEngine
46
{
5-
string RenderPartial(string pageName, object model, bool renderHtml);
7+
string RenderPartial(string pageName, object model, bool renderHtml);
8+
bool ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, object dto);
69
}
710
}

src/ServiceStack/VirtualPath/AbstractVirtualDirectoryBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace ServiceStack.VirtualPath
77
public abstract class AbstractVirtualDirectoryBase : IVirtualDirectory
88
{
99
protected IVirtualPathProvider VirtualPathProvider;
10-
protected IVirtualDirectory ParentDirectory;
10+
public IVirtualDirectory ParentDirectory { get; set; }
11+
public IVirtualDirectory Directory { get { return this; } }
1112

1213
public abstract DateTime LastModified { get; }
13-
public abstract string DirectoryName { get; }
1414
public virtual string VirtualPath { get { return GetVirtualPathToRoot(); } }
1515
public virtual string RealPath { get { return GetRealPathToRoot(); } }
1616

src/ServiceStack/VirtualPath/AbstractVirtualFileBase.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Security.Cryptography;
5+
using ServiceStack.Text;
46

57
namespace ServiceStack.VirtualPath
68
{
79
public abstract class AbstractVirtualFileBase : IVirtualFile
810
{
9-
public IVirtualPathProvider VirtualPathProvider { get; set; }
10-
protected IVirtualDirectory ParentDirectory;
11+
public IVirtualPathProvider VirtualPathProvider { get; set; }
12+
13+
public string Extension
14+
{
15+
get { return Name.SplitOnLast('.').LastOrDefault(); }
16+
}
17+
18+
public IVirtualDirectory Directory { get; set; }
1119

1220
public abstract string Name { get; }
13-
public abstract string DirectoryName { get; }
1421
public virtual string VirtualPath { get { return GetVirtualPathToRoot(); } }
1522
public virtual string RealPath { get { return GetRealPathToRoot(); } }
1623
public virtual bool IsDirectory { get { return false; } }
1724
public abstract DateTime LastModified { get; }
1825

19-
protected AbstractVirtualFileBase(IVirtualPathProvider owningProvider, IVirtualDirectory parentDirectory)
26+
protected AbstractVirtualFileBase(
27+
IVirtualPathProvider owningProvider, IVirtualDirectory directory)
2028
{
2129
if (owningProvider == null)
2230
throw new ArgumentNullException("owningProvider");
2331

24-
if (parentDirectory == null)
25-
throw new ArgumentNullException("parentDirectory");
32+
if (directory == null)
33+
throw new ArgumentNullException("directory");
2634

2735
this.VirtualPathProvider = owningProvider;
28-
this.ParentDirectory = parentDirectory;
36+
this.Directory = directory;
2937
}
3038

3139
public virtual string GetFileHash()
@@ -63,7 +71,7 @@ protected virtual string GetRealPathToRoot()
6371

6472
protected virtual string GetPathToRoot(string separator, Func<IVirtualDirectory, string> pathSel)
6573
{
66-
var parentPath = ParentDirectory != null ? pathSel(ParentDirectory) : string.Empty;
74+
var parentPath = Directory != null ? pathSel(Directory) : string.Empty;
6775
if (parentPath == separator)
6876
parentPath = string.Empty;
6977

src/ServiceStack/VirtualPath/FileSystemVirtualDirectory.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public override string Name
2424
get { return BackingDirInfo.Name; }
2525
}
2626

27-
public override string DirectoryName
28-
{
29-
get { return BackingDirInfo.FullName; }
30-
}
31-
3227
public override DateTime LastModified
3328
{
3429
get { return BackingDirInfo.LastWriteTime; }

src/ServiceStack/VirtualPath/FileSystemVirtualFile.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ public override DateTime LastModified
2121
{
2222
get { return BackingFile.LastWriteTime; }
2323
}
24-
25-
public override string DirectoryName
26-
{
27-
get { return BackingFile.DirectoryName; }
28-
}
2924

30-
public FileSystemVirtualFile(IVirtualPathProvider owningProvider, IVirtualDirectory parentDirectory, FileInfo fInfo)
31-
: base(owningProvider, parentDirectory)
25+
public FileSystemVirtualFile(IVirtualPathProvider owningProvider, IVirtualDirectory directory, FileInfo fInfo)
26+
: base(owningProvider, directory)
3227
{
3328
if (fInfo == null)
3429
throw new ArgumentNullException("fInfo");
3530

36-
this.BackingFile = fInfo;
31+
this.BackingFile = fInfo;
3732
}
3833

3934
public override Stream OpenRead()

0 commit comments

Comments
 (0)