/BlogEngine/BlogEngine.NET/themes/RazorHost/site.master.cs
C# | 62 lines | 50 code | 11 blank | 1 comment | 6 complexity | 9c4f025d4c35492ce8b5ca3e190558b3 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
- using System;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using BlogEngine.Core;
- using System.IO;
- using System.Web.Compilation;
- using System.Text.RegularExpressions;
-
- public partial class RazorHostSite : System.Web.UI.MasterPage
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- ParseAndInjectRazor();
-
- }
-
- private void ParseAndInjectRazor()
- {
- string parsedRazor = RazorHelpers.ParseRazor(RazorHelpers.RAZOR_HOST_PAGE_VPATH, null);
-
- if (!string.IsNullOrWhiteSpace(parsedRazor))
- {
- Regex headRgx = new Regex("<head\\b[^>]*>(.*?)</head>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
- Match headMatch = headRgx.Match(parsedRazor);
- if (headMatch.Success)
- {
- string headContent = headMatch.Groups[1].Value;
-
- // remove the <title> tag.
- headContent = new Regex("<title\\b[^>]*>(.*?)</title>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Replace(headContent, string.Empty);
-
- phRazorHead.Controls.Add(new LiteralControl(headContent));
- }
-
- Regex bodyRgx = new Regex("<body\\b([^>]*)>(.*?)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
- Match bodyMatch = bodyRgx.Match(parsedRazor);
- if (bodyMatch.Success)
- {
- string bodyAttributes = bodyMatch.Groups[1].Value.Trim();
- if (!string.IsNullOrWhiteSpace(bodyAttributes))
- {
- this.BodyAttributes = " " + bodyAttributes;
- }
-
- string body = bodyMatch.Groups[2].Value;
-
- int placeHolderPos = body.IndexOf(RazorHelpers.PAGE_BODY_MARKER, StringComparison.OrdinalIgnoreCase);
- if (placeHolderPos != -1)
- {
- string beforePlaceholderMarkup = body.Substring(0, placeHolderPos);
- string afterPlaceholderMarkup = body.Substring(placeHolderPos + RazorHelpers.PAGE_BODY_MARKER.Length);
-
- phBeforePageBody.Controls.Add(new LiteralControl(beforePlaceholderMarkup));
- phAfterPageBody.Controls.Add(new LiteralControl(afterPlaceholderMarkup));
- }
- }
- }
- }
-
- public string BodyAttributes { get; set; }
- }