diff --git a/src/Nancy.ViewEngines.Razor/HtmlHelpers.cs b/src/Nancy.ViewEngines.Razor/HtmlHelpers.cs index d5a8e190e9..5892d1fc71 100644 --- a/src/Nancy.ViewEngines.Razor/HtmlHelpers.cs +++ b/src/Nancy.ViewEngines.Razor/HtmlHelpers.cs @@ -2,30 +2,45 @@ { using System; using System.IO; + using System.Linq.Expressions; /// /// Helpers to generate html content. /// /// The type of the model. - public class HtmlHelpers : IHtmlHelpers + public class HtmlHelpers { - private readonly TModel model; - private readonly RazorViewEngine engine; - private readonly IRenderContext renderContext; - /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The razor view engine instance that the helpers are being used by. /// The that the helper are being used by. /// The model that is used by the page where the helpers are invoked. public HtmlHelpers(RazorViewEngine engine, IRenderContext renderContext, TModel model) { - this.engine = engine; - this.renderContext = renderContext; - this.model = model; + this.Engine = engine; + this.RenderContext = renderContext; + this.Model = model; } + /// + /// The model that is being used by the current view. + /// + /// An instance of the view model. + public TModel Model { get; set; } + + /// + /// The engine that is currently rendering the view. + /// + /// A instance. + public RazorViewEngine Engine { get; set; } + + /// + /// The context of the current render operation. + /// + /// An intance. + public IRenderContext RenderContext { get; set; } + /// /// Renders a partial with the given view name. /// @@ -44,9 +59,9 @@ public IHtmlString Partial(string viewName) /// An representation of the partial. public IHtmlString Partial(string viewName, dynamic modelForPartial) { - var view = this.renderContext.LocateView(viewName, modelForPartial); + var view = this.RenderContext.LocateView(viewName, modelForPartial); - var response = this.engine.RenderView(view, modelForPartial, this.renderContext); + var response = this.Engine.RenderView(view, modelForPartial, this.RenderContext); Action action = response.Contents; var mem = new MemoryStream(); @@ -74,7 +89,8 @@ public IHtmlString Raw(string text) /// An representation of the anti forgery token. public IHtmlString AntiForgeryToken() { - var tokenKeyValue = this.renderContext.GetCsrfToken(); + var tokenKeyValue = + this.RenderContext.GetCsrfToken(); return new NonEncodedHtmlString(String.Format("", tokenKeyValue.Key, tokenKeyValue.Value)); } diff --git a/src/Nancy.ViewEngines.Razor/IHtmlHelpers.cs b/src/Nancy.ViewEngines.Razor/IHtmlHelpers.cs deleted file mode 100644 index 77ea2b75a7..0000000000 --- a/src/Nancy.ViewEngines.Razor/IHtmlHelpers.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace Nancy.ViewEngines.Razor -{ - /// - /// Defines the functionality of a html helper. - /// - /// The type of the model. - public interface IHtmlHelpers - { - /// - /// Renders a partial with the given view name. - /// - /// Name of the view. - /// An representation of the partial. - IHtmlString Partial(string viewName); - - /// - /// Renders a partial with the given view name. - /// - /// Name of the view. - /// The model. - /// An representation of the partial. - IHtmlString Partial(string viewName, dynamic model); - - /// - /// Returns an html string composed of raw, non-encoded text. - /// - /// The text. - /// An representation of the raw text. - IHtmlString Raw(string text); - - /// - /// Creates an anti-forgery token. - /// - /// An representation of the anti forgery token. - IHtmlString AntiForgeryToken(); - } -} \ No newline at end of file diff --git a/src/Nancy.ViewEngines.Razor/IUrlHelpers.cs b/src/Nancy.ViewEngines.Razor/IUrlHelpers.cs deleted file mode 100644 index 697edda640..0000000000 --- a/src/Nancy.ViewEngines.Razor/IUrlHelpers.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Nancy.ViewEngines.Razor -{ - public interface IUrlHelpers - { - /// - /// Retrieves the absolute url of the specified path. - /// - /// The path. - string Content(string path); - } -} \ No newline at end of file diff --git a/src/Nancy.ViewEngines.Razor/Nancy.ViewEngines.Razor.csproj b/src/Nancy.ViewEngines.Razor/Nancy.ViewEngines.Razor.csproj index 19bc1b9b28..8f31d280a9 100644 --- a/src/Nancy.ViewEngines.Razor/Nancy.ViewEngines.Razor.csproj +++ b/src/Nancy.ViewEngines.Razor/Nancy.ViewEngines.Razor.csproj @@ -94,11 +94,9 @@ - - diff --git a/src/Nancy.ViewEngines.Razor/NancyRazorViewBase.cs b/src/Nancy.ViewEngines.Razor/NancyRazorViewBase.cs index 369215f6ab..e948813af7 100644 --- a/src/Nancy.ViewEngines.Razor/NancyRazorViewBase.cs +++ b/src/Nancy.ViewEngines.Razor/NancyRazorViewBase.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Globalization; using System.Text; - using Nancy.Helpers; /// @@ -45,10 +44,7 @@ public abstract class NancyRazorViewBase /// public bool HasLayout { - get - { - return !String.IsNullOrEmpty(this.Layout); - } + get { return !String.IsNullOrEmpty(this.Layout); } } /// @@ -225,7 +221,7 @@ public abstract class NancyRazorViewBase : NancyRazorViewBase /// /// Gets the Html helper. /// - public IHtmlHelpers Html { get; private set; } + public HtmlHelpers Html { get; private set; } /// /// Gets the model. @@ -235,7 +231,7 @@ public abstract class NancyRazorViewBase : NancyRazorViewBase /// /// Gets the Url helper. /// - public IUrlHelpers Url { get; private set; } + public UrlHelpers Url { get; private set; } /// /// Non-model specific data for rendering in the response diff --git a/src/Nancy.ViewEngines.Razor/NonEncodedHtmlString.cs b/src/Nancy.ViewEngines.Razor/NonEncodedHtmlString.cs index bd086b601f..d0ed49420b 100644 --- a/src/Nancy.ViewEngines.Razor/NonEncodedHtmlString.cs +++ b/src/Nancy.ViewEngines.Razor/NonEncodedHtmlString.cs @@ -24,5 +24,10 @@ public string ToHtmlString() { return value; } + + public static implicit operator NonEncodedHtmlString(string value) + { + return new NonEncodedHtmlString(value); + } } } \ No newline at end of file diff --git a/src/Nancy.ViewEngines.Razor/UrlHelpers.cs b/src/Nancy.ViewEngines.Razor/UrlHelpers.cs index 5212985457..5db11d7dec 100644 --- a/src/Nancy.ViewEngines.Razor/UrlHelpers.cs +++ b/src/Nancy.ViewEngines.Razor/UrlHelpers.cs @@ -4,11 +4,8 @@ namespace Nancy.ViewEngines.Razor /// Helpers for url related functions. /// /// The type of the model. - public class UrlHelpers : IUrlHelpers + public class UrlHelpers { - private readonly RazorViewEngine razorViewEngine; - private readonly IRenderContext renderContext; - /// /// Initializes a new instance of the class. /// @@ -16,17 +13,29 @@ public class UrlHelpers : IUrlHelpers /// The render context. public UrlHelpers(RazorViewEngine razorViewEngine, IRenderContext renderContext) { - this.razorViewEngine = razorViewEngine; - this.renderContext = renderContext; + this.RazorViewEngine = razorViewEngine; + this.RenderContext = renderContext; } + /// + /// The engine that is currently rendering the view. + /// + /// A instance. + public RazorViewEngine RazorViewEngine { get; set; } + + /// + /// The context of the current render operation. + /// + /// An intance. + public IRenderContext RenderContext { get; set; } + /// /// Retrieves the absolute url of the specified path. /// /// The path. public string Content(string path) { - return renderContext.ParsePath(path); + return this.RenderContext.ParsePath(path); } } } \ No newline at end of file