Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added extension point for providing additional partial file locations…

… in ViewLoader
  • Loading branch information...
commit be654c96e906710692cc74b06e5f5c4f8b2fd465 1 parent 2cf1fbf
@bobpace bobpace authored RobertTheGrey committed
View
3  src/Spark.Tests/SparkServiceContainerTester.cs
@@ -40,6 +40,9 @@ public void ContainerCreatesDefaultServices()
var bindingProvider = container.GetService<IBindingProvider>();
Assert.IsInstanceOf(typeof(DefaultBindingProvider), bindingProvider);
+
+ var partialProvider = container.GetService<IPartialProvider>();
+ Assert.IsInstanceOf(typeof(DefaultPartialProvider), partialProvider);
}
[Test]
View
21 src/Spark/DefaultPartialProvider.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Spark
+{
+ public class DefaultPartialProvider : IPartialProvider
+ {
+ public IEnumerable<string> GetPaths(string viewPath)
+ {
+ do
+ {
+ viewPath = Path.GetDirectoryName(viewPath);
+
+ yield return viewPath;
+ yield return Path.Combine(viewPath, Constants.Shared);
+ }
+ while (!String.IsNullOrEmpty(viewPath));
+ }
+ }
+}
View
9 src/Spark/IPartialProvider.cs
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+
+namespace Spark
+{
+ public interface IPartialProvider
+ {
+ IEnumerable<string> GetPaths(string viewPath);
+ }
+}
View
25 src/Spark/Parser/ViewLoader.cs
@@ -37,6 +37,7 @@ public class ViewLoader
private readonly List<string> pending = new List<string>();
+ private IPartialProvider partialProvider;
public IViewFolder ViewFolder { get; set; }
@@ -54,6 +55,19 @@ public class ViewLoader
public IBindingProvider BindingProvider { get; set; }
+ public IPartialProvider PartialProvider
+ {
+ get
+ {
+ if (partialProvider == null)
+ {
+ partialProvider = new DefaultPartialProvider();
+ };
+ return partialProvider;
+ }
+ set { partialProvider = value; }
+ }
+
/// <summary>
/// Returns a value indicating whether this view loader is current.
/// </summary>
@@ -133,16 +147,9 @@ public IList<string> FindPartialFiles(string viewPath)
/// </summary>
/// <param name="viewPath">The view path for which to return partial view paths.</param>
/// <returns>The full list of possible partial view paths.</returns>
- private static IEnumerable<string> PartialViewFolderPaths(string viewPath)
+ private IEnumerable<string> PartialViewFolderPaths(string viewPath)
{
- do
- {
- viewPath = Path.GetDirectoryName(viewPath);
-
- yield return viewPath;
- yield return Path.Combine(viewPath, Constants.Shared);
- }
- while (!String.IsNullOrEmpty(viewPath));
+ return this.PartialProvider.GetPaths(viewPath);
}
/// <summary>
View
2  src/Spark/Spark.csproj
@@ -110,6 +110,8 @@
<Compile Include="ICacheSignal.cs" />
<Compile Include="NullCacheService.cs" />
<Compile Include="Compiler\NodeVisitors\BindingExpansionVisitor.cs" />
+ <Compile Include="DefaultPartialProvider.cs" />
+ <Compile Include="IPartialProvider.cs" />
<Compile Include="Parser\Offset\OffsetGrammar.cs" />
<Compile Include="SparkViewBase.cs" />
<Compile Include="CompiledViewEntry.cs" />
View
1  src/Spark/SparkServiceContainer.cs
@@ -53,6 +53,7 @@ public SparkServiceContainer(ISparkSettings settings)
{typeof (IBindingProvider), c => new DefaultBindingProvider()},
{typeof (IViewFolder), CreateDefaultViewFolder},
{typeof (ICompiledViewHolder), c => new CompiledViewHolder()},
+ {typeof (IPartialProvider), c => new DefaultPartialProvider()},
};
View
18 src/Spark/SparkViewEngine.cs
@@ -53,6 +53,7 @@ public void Initialize(ISparkServiceContainer container)
ResourcePathManager = container.GetService<IResourcePathManager>();
TemplateLocator = container.GetService<ITemplateLocator>();
CompiledViewHolder = container.GetService<ICompiledViewHolder>();
+ PartialProvider = container.GetService<IPartialProvider>();
SetViewFolder(container.GetService<IViewFolder>());
}
@@ -93,6 +94,18 @@ public IBindingProvider BindingProvider
set { _bindingProvider = value; }
}
+ private IPartialProvider _partialProvider;
+ public IPartialProvider PartialProvider
+ {
+ get
+ {
+ if (_partialProvider == null)
+ _partialProvider = new DefaultPartialProvider();
+ return _partialProvider;
+ }
+ set { _partialProvider = value; }
+ }
+
private static IViewFolder CreateDefaultViewFolder()
{
if (HostingEnvironment.IsHosted && HostingEnvironment.VirtualPathProvider != null)
@@ -295,7 +308,8 @@ private ViewLoader CreateViewLoader()
Prefix = Settings.Prefix,
BindingProvider = BindingProvider,
ParseSectionTagAsSegment = Settings.ParseSectionTagAsSegment,
- AttributeBehaviour = Settings.AttributeBehaviour
+ AttributeBehaviour = Settings.AttributeBehaviour,
+ PartialProvider = PartialProvider
};
}
@@ -358,7 +372,7 @@ public IList<SparkViewDescriptor> LoadBatchCompilation(Assembly assembly)
var entry = new CompiledViewEntry
{
Descriptor = descriptor,
- Loader = new ViewLoader(),
+ Loader = new ViewLoader { PartialProvider = PartialProvider },
Compiler = new CSharpViewCompiler { CompiledType = type },
Activator = ViewActivatorFactory.Register(type)
};
Please sign in to comment.
Something went wrong with that request. Please try again.