PageRenderTime 41ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/themes/RazorHost/WidgetContainer.ascx

#
ASP.NET | 47 lines | 36 code | 11 blank | 0 comment | 4 complexity | 5cae3e68481d48acfa7e1339f95ba37f MD5 | raw file
 1<%@ Control Language="C#" AutoEventWireup="true" Inherits="App_Code.Controls.WidgetContainer" %>
 2<%@ Import Namespace="BlogEngine.Core" %>
 3
 4<script runat="server">
 5
 6    protected override void OnLoad(EventArgs e)
 7    {
 8        base.OnLoad(e);
 9
10        ParseAndInjectRazor();
11    }
12
13    public override void RenderContainer()
14    {
15        base.RenderContainer();
16        ParseAndInjectRazor();
17    }
18    
19    private bool _rendered;
20    private void ParseAndInjectRazor()
21    {
22        if (_rendered) { return; }
23        
24        string vPath = string.Format("~/themes/{0}/WidgetContainer.cshtml", BlogSettings.Instance.Theme);
25        string parsedRazor = RazorHelpers.ParseRazor(vPath, this);  // 'this' is WidgetContainer.
26
27        if (!string.IsNullOrWhiteSpace(parsedRazor))
28        {
29            int placeHolderPos = parsedRazor.IndexOf(RazorHelpers.WIDGET_CONTAINER_BODY_MARKER, StringComparison.OrdinalIgnoreCase);
30            if (placeHolderPos != -1)
31            {
32                string beforePlaceholderMarkup = parsedRazor.Substring(0, placeHolderPos);
33                string afterPlaceholderMarkup = parsedRazor.Substring(placeHolderPos + RazorHelpers.WIDGET_CONTAINER_BODY_MARKER.Length);
34
35                phBeforeContainerBody.Controls.Add(new LiteralControl(beforePlaceholderMarkup));
36                phAfterContainerBody.Controls.Add(new LiteralControl(afterPlaceholderMarkup));
37            }
38        }
39        
40        _rendered = true;
41    }
42        
43</script>
44
45<asp:PlaceHolder ID="phBeforeContainerBody" runat="server" />
46<asp:PlaceHolder ID="phWidgetBody" runat="server" />
47<asp:PlaceHolder ID="phAfterContainerBody" runat="server" />