<commit_before>﻿using System;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using System.Web.UI;
using Microsoft.WebPages;
using Orchard.Localization;
using Orchard.Mvc.ViewEngines;
using Orchard.UI.PageClass;
using Orchard.UI.PageTitle;
using Orchard.UI.Resources;
using HtmlHelper = System.Web.Mvc.HtmlHelper;

namespace Orchard.Mvc.Html {
    public static class LayoutExtensions {
        public static HelperResult RenderOrchardBody(this HtmlHelper html) {
            LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);
            return new HelperResult(writer => writer.Write(layoutViewContext.BodyContent));
        }

        public static MvcHtmlString Body(this HtmlHelper html) {
            LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);

            return MvcHtmlString.Create(layoutViewContext.BodyContent);
        }

        public static void AddTitleParts(this HtmlHelper html, params string[] titleParts) {
            html.Resolve<IPageTitleBuilder>().AddTitleParts(titleParts);
        }

        public static void AppendTitleParts(this HtmlHelper html, params string[] titleParts) {
            html.Resolve<IPageTitleBuilder>().AppendTitleParts(titleParts);
        }

        public static MvcHtmlString Title(this HtmlHelper html, params string[] titleParts) {
            IPageTitleBuilder pageTitleBuilder = html.Resolve<IPageTitleBuilder>();

            html.AppendTitleParts(titleParts);

            return MvcHtmlString.Create(html.Encode(pageTitleBuilder.GenerateTitle()));
        }

        public static MvcHtmlString TitleForPage(this HtmlHelper html, params string[] titleParts) {
            if (titleParts == null || titleParts.Length < 1)
                return null;

            html.AppendTitleParts(titleParts);

            return MvcHtmlString.Create(html.Encode(titleParts[0]));
        }

        public static MvcHtmlString TitleForPage(this HtmlHelper html, params LocalizedString[] titleParts) {
            if (titleParts == null || titleParts.Length < 1)
                return null;

            html.AppendTitleParts(titleParts.Select(part=>part.ToString()).ToArray());

            return MvcHtmlString.Create(html.Encode(titleParts[0]));
        }

        public static void AddPageClassNames(this HtmlHelper html, params object[] classNames) {
            html.Resolve<IPageClassBuilder>().AddClassNames(classNames);
        }

        public static MvcHtmlString ClassForPage(this HtmlHelper html, params object[] classNames) {
            IPageClassBuilder pageClassBuilder = html.Resolve<IPageClassBuilder>();

            html.AddPageClassNames(classNames);
            //todo: (heskew) need ContentItem.ContentType
            html.AddPageClassNames(html.ViewContext.RouteData.Values["area"]);

            return MvcHtmlString.Create(html.Encode(pageClassBuilder.ToString()));
        }

        public static void RegisterLink(this HtmlHelper html, string rel, string type, string href) {
            RegisterLink(html, new LinkEntry {
                Rel = rel,
                Type = type,
                Href = href
            });
        }

        public static void RegisterLink(this HtmlHelper html, LinkEntry link) {
            html.Resolve<IResourceManager>().RegisterLink(link);
        }

        public static void SetMeta(this HtmlHelper html, string name, string content) {
            SetMeta(html, new MetaEntry { Name = name, Content = content });
        }

        public static void SetMeta(this HtmlHelper html, MetaEntry meta) {
            html.Resolve<IResourceManager>().SetMeta(meta);
        }

        public static void AppendMeta(this HtmlHelper html, string name, string content, string contentSeparator) {
            AppendMeta(html, new MetaEntry { Name = name, Content = content }, contentSeparator);
        }

        public static void AppendMeta(this HtmlHelper html, MetaEntry meta, string contentSeparator) {
            html.Resolve<IResourceManager>().AppendMeta(meta, contentSeparator);
        }

        public static IDisposable Capture(this ViewUserControl control, string name) {
            var writer = LayoutViewContext.From(control.ViewContext).GetNamedContent(name);
            return new HtmlTextWriterScope(control.Writer, writer);
        }

        class HtmlTextWriterScope : IDisposable {
            private readonly HtmlTextWriter _context;
            private readonly TextWriter _writer;

            public HtmlTextWriterScope(HtmlTextWriter context, TextWriter writer) {
                _context = context;
                _writer = _context.InnerWriter;
                _context.InnerWriter = writer;
            }

            public void Dispose() {
                _context.InnerWriter = _writer;
            }<commit_msg>Removed Html.RegisterLink/Meta helpers, these are on the base view instead (they aren't HTML helpers anymore)<commit_after>﻿using System;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using System.Web.UI;
using Microsoft.WebPages;
using Orchard.Localization;
using Orchard.Mvc.ViewEngines;
using Orchard.UI.PageClass;
using Orchard.UI.PageTitle;
using Orchard.UI.Resources;
using HtmlHelper = System.Web.Mvc.HtmlHelper;

namespace Orchard.Mvc.Html {
    public static class LayoutExtensions {
        public static HelperResult RenderOrchardBody(this HtmlHelper html) {
            LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);
            return new HelperResult(writer => writer.Write(layoutViewContext.BodyContent));
        }

        public static MvcHtmlString Body(this HtmlHelper html) {
            LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);

            return MvcHtmlString.Create(layoutViewContext.BodyContent);
        }

        public static void AddTitleParts(this HtmlHelper html, params string[] titleParts) {
            html.Resolve<IPageTitleBuilder>().AddTitleParts(titleParts);
        }

        public static void AppendTitleParts(this HtmlHelper html, params string[] titleParts) {
            html.Resolve<IPageTitleBuilder>().AppendTitleParts(titleParts);
        }

        public static MvcHtmlString Title(this HtmlHelper html, params string[] titleParts) {
            IPageTitleBuilder pageTitleBuilder = html.Resolve<IPageTitleBuilder>();

            html.AppendTitleParts(titleParts);

            return MvcHtmlString.Create(html.Encode(pageTitleBuilder.GenerateTitle()));
        }

        public static MvcHtmlString TitleForPage(this HtmlHelper html, params string[] titleParts) {
            if (titleParts == null || titleParts.Length < 1)
                return null;

            html.AppendTitleParts(titleParts);

            return MvcHtmlString.Create(html.Encode(titleParts[0]));
        }

        public static MvcHtmlString TitleForPage(this HtmlHelper html, params LocalizedString[] titleParts) {
            if (titleParts == null || titleParts.Length < 1)
                return null;

            html.AppendTitleParts(titleParts.Select(part=>part.ToString()).ToArray());

            return MvcHtmlString.Create(html.Encode(titleParts[0]));
        }

        public static void AddPageClassNames(this HtmlHelper html, params object[] classNames) {
            html.Resolve<IPageClassBuilder>().AddClassNames(classNames);
        }

        public static MvcHtmlString ClassForPage(this HtmlHelper html, params object[] classNames) {
            IPageClassBuilder pageClassBuilder = html.Resolve<IPageClassBuilder>();

            html.AddPageClassNames(classNames);
            //todo: (heskew) need ContentItem.ContentType
            html.AddPageClassNames(html.ViewContext.RouteData.Values["area"]);

            return MvcHtmlString.Create(html.Encode(pageClassBuilder.ToString()));
        }

        public static IDisposable Capture(this ViewUserControl control, string name) {
            var writer = LayoutViewContext.From(control.ViewContext).GetNamedContent(name);
            return new HtmlTextWriterScope(control.Writer, writer);
        }

        class HtmlTextWriterScope : IDisposable {
            private readonly HtmlTextWriter _context;
            private readonly TextWriter _writer;

            public HtmlTextWriterScope(HtmlTextWriter context, TextWriter writer) {
                _context = context;
                _writer = _context.InnerWriter;
                _context.InnerWriter = writer;
            }

            public void Dispose() {
                _context.InnerWriter = _writer;
            }
{'fraction_non_alphanumeric': 0.082830626450116, 'fraction_numerical': 0.0009280742459396752, 'mean_word_length': 2.791116974494283, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2544775', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2157, 'n_words': 502}