当前位置: 首页>>代码示例>>C#>>正文


C# ViewEngines.ViewLocationResult类代码示例

本文整理汇总了C#中Nancy.ViewEngines.ViewLocationResult的典型用法代码示例。如果您正苦于以下问题:C# ViewLocationResult类的具体用法?C# ViewLocationResult怎么用?C# ViewLocationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ViewLocationResult类属于Nancy.ViewEngines命名空间,在下文中一共展示了ViewLocationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderView

        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            var response = new HtmlResponse();

            var html = renderContext.ViewCache.GetOrAdd(viewLocationResult, result =>
                                                                                {
                                                                                    string markDown =
                                                                                        viewLocationResult.Contents()
                                                                                                          .ReadToEnd();


                                                                                    var parser = new Markdown();
                                                                                    return parser.Transform(markDown);
                                                                                });


            var serverHtml = ParagraphSubstitution.Replace(html, "$1");

            var renderHtml = this.engineWrapper.Render(serverHtml, model, new MarkdownViewEngineHost(new NancyViewEngineHost(renderContext), renderContext));

            response.Contents = stream =>
            {
                var writer = new StreamWriter(stream);
                writer.Write(renderHtml);
                writer.Flush();
            };

            return response;
        }
开发者ID:jchannon,项目名称:Nancy.ViewEngines.Markdown,代码行数:29,代码来源:MarkDownEngine.cs

示例2: ExtensionMatchesView

        private static bool ExtensionMatchesView(string viewName, ViewLocationResult viewLocationResult)
        {
            var extension = Path.GetExtension(viewName);

            return string.IsNullOrEmpty(extension) ||
                viewLocationResult.Extension.Equals(extension.Substring(1), StringComparison.OrdinalIgnoreCase);
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:7,代码来源:DefaultViewLocator.cs

示例3: NameMatchesView

        private static bool NameMatchesView(string viewName, ViewLocationResult viewLocationResult)
        {
            var name = Path.GetFileNameWithoutExtension(viewName);

            return (!string.IsNullOrEmpty(name)) &&
                viewLocationResult.Name.Equals(name, StringComparison.OrdinalIgnoreCase);
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:7,代码来源:DefaultViewLocator.cs

示例4: LocationMatchesView

        private static bool LocationMatchesView(string viewName, ViewLocationResult viewLocationResult)
        {
            var location = viewName
                .Replace(Path.GetFileName(viewName), string.Empty)
                .TrimEnd(new [] { '/' });

            return viewLocationResult.Location.Equals(location, StringComparison.OrdinalIgnoreCase);
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:8,代码来源:DefaultViewLocator.cs

示例5: LocationMatchesView

        private static bool LocationMatchesView(string viewName, ViewLocationResult viewLocationResult)
        {
            var filename = Path.GetFileName( viewName );
            var index = viewName.LastIndexOf(filename, System.StringComparison.OrdinalIgnoreCase );
            var location = index >= 0 ? viewName.Remove( index, filename.Length ) : viewName;
            location = location.TrimEnd( new[] { '/' } );

            return viewLocationResult.Location.Equals(location, StringComparison.OrdinalIgnoreCase);
        }
开发者ID:ryanki1,项目名称:Nancy,代码行数:9,代码来源:DefaultViewLocator.cs

示例6: RenderView

 /// <summary>
 /// Renders the view.
 /// </summary>
 /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
 /// <param name="model">The model that should be passed into the view</param>
 /// <returns>A delegate that can be invoked with the <see cref="Stream"/> that the view should be rendered to.</returns>
 public Action<Stream> RenderView(ViewLocationResult viewLocationResult, dynamic model)
 {
     return s =>
     {
         var writer = new StreamWriter(s);
         writer.Write(this.viewEngine.Render(viewLocationResult.Contents.Invoke().ReadToEnd(), model));
         writer.Flush();
     };
 }
开发者ID:justinsoliz,项目名称:Nancy,代码行数:15,代码来源:SuperSimpleViewEngineWrapper.cs

示例7: SafeInvokeViewEngine

 private static Action<Stream> SafeInvokeViewEngine(IViewEngine viewEngine, ViewLocationResult locationResult, dynamic model)
 {
     try
     {
         return viewEngine.RenderView(locationResult, model);
     }
     catch (Exception)
     {
         return EmptyView;
     }
 }
开发者ID:justinsoliz,项目名称:Nancy,代码行数:11,代码来源:DefaultViewFactory.cs

示例8: RenderView

        public Action<Stream> RenderView(ViewLocationResult viewLocationResult, dynamic model)
        {
            return stream => {
                var transformer = new MarkdownSharp.Markdown(_options);
                string markdown = viewLocationResult.Contents.ReadToEnd();
                string html = transformer.Transform(markdown);

                var writer = new StreamWriter(stream);
                writer.Write(html);
                writer.Flush();
            };
        }
开发者ID:serakrin,项目名称:presentations,代码行数:12,代码来源:MarkdownViewEngine.cs

示例9: Should_ignore_case_when_locating_view_based_on_name

        public void Should_ignore_case_when_locating_view_based_on_name(string viewName)
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var locator = CreateViewLocator(expectedView);

            // When
            var result = locator.LocateView(viewName, null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:12,代码来源:DefaultViewLocatorFixture.cs

示例10: ViewEngineFixture

        public ViewEngineFixture()
        {
            this.templateLocator = A.Fake<IViewLocator>();
            this.viewCompiler = A.Fake<IViewCompiler>();
            this.view = A.Fake<IView>();
            this.viewLocationResult = new ViewLocationResult(@"c:\some\fake\path", null);

            A.CallTo(() => templateLocator.GetTemplateContents("test")).Returns(viewLocationResult);
            A.CallTo(() => viewCompiler.GetCompiledView<object>(null)).Returns(view);
            A.CallTo(() => viewCompiler.GetCompiledView<MemoryStream>(null)).Returns(view);

            this.engine = new ViewEngine(templateLocator, viewCompiler);
        }
开发者ID:ryansroberts,项目名称:Nancy,代码行数:13,代码来源:ViewEngineFixture.cs

示例11: Should_be_able_to_locate_view_by_name_when_two_views_with_same_name_exists_at_different_locations

        public void Should_be_able_to_locate_view_by_name_when_two_views_with_same_name_exists_at_different_locations()
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", string.Empty, () => null);
            var additionalView = new ViewLocationResult("views", "index", string.Empty, () => null);
            var locator = CreateViewLocator(expectedView, additionalView);

            // When
            var result = locator.LocateView("views/sub/index", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:13,代码来源:DefaultViewLocatorFixture.cs

示例12: Should_be_able_to_locate_view_by_name_when_the_viewname_occures_in_the_location

        public void Should_be_able_to_locate_view_by_name_when_the_viewname_occures_in_the_location()
        {
            // Given
               var expectedView = new ViewLocationResult( "views/hello", "hello", "cshtml", () => null );
               //var additionalView = new ViewLocationResult( "views", "index", "spark", () => null );
               var locator = CreateViewLocator(expectedView);

               // When
               var result = locator.LocateView( "views/hello/hello", null );

               // Then
               result.ShouldBeSameAs( expectedView );
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:13,代码来源:DefaultViewLocatorFixture.cs

示例13: Should_throw_ambiguousviewsexception_when_locating_view_by_name_returns_multiple_results

        public void Should_throw_ambiguousviewsexception_when_locating_view_by_name_returns_multiple_results()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var locator = CreateViewLocator(expectedView1, expectedView2);

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.ShouldBeOfType<AmbiguousViewsException>();
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:13,代码来源:DefaultViewLocatorFixture.cs

示例14: Should_locate_view_when_only_name_is_provided

        public void Should_locate_view_when_only_name_is_provided()
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);

            var locator = CreateViewLocator(expectedView);

            // When
            var result = locator.LocateView("index", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:13,代码来源:DefaultViewLocatorFixture.cs

示例15: ViewLocationResult

        public void Should_be_able_to_locate_view_by_name_and_extension_when_two_view_with_same_name_but_different_extensions_exists_in_the_same_location()
        {
            // Given
            var expectedView = new ViewLocationResult("views", "index", "cshtml", () => null);
            var additionalView = new ViewLocationResult("views", "index", "spark", () => null);
            var locator = CreateViewLocator(expectedView, additionalView);

            // When
            var result = locator.LocateView("views/index.cshtml", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:13,代码来源:DefaultViewLocatorFixture.cs


注:本文中的Nancy.ViewEngines.ViewLocationResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。