<commit_before>﻿using AjaxControlToolkit.Reference.Core.Rendering;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace AjaxControlToolkit.Reference.Core {

    public class ExtenderDoc {
        IDocRenderer _renderer;
        StringBuilder _docStringBuilder = new StringBuilder();

        public ExtenderDoc(IDocRenderer renderer) {
            _renderer = renderer;
        }

        public string BuildDoc(IEnumerable<TypeDoc> typeDocs) {
            var sb = new StringBuilder();

            foreach(var typeDoc in typeDocs)
                sb.Append(BuildTypeDoc(typeDoc));

            return sb.ToString();
        }

        public string BuildTypeDoc(TypeDoc typeDoc) {
            _docStringBuilder.Clear();

            RenderTypeName(typeDoc.Name);
            RenderSampleSiteLink(typeDoc.Name);
            RenderTypeDescription(typeDoc.Summary);
            RenderTypeRemarks(typeDoc.Remarks);

            RenderMethods(typeDoc.Methods.OrderBy(m => m.Name), "Methods");
            RenderEvents(typeDoc.Events.OrderBy(e => e.Name));
            RenderProperties(typeDoc.Properties.OrderBy(p => p.Name));
            RenderClientProperties(typeDoc.ClientProperties.OrderBy(p => p.Name));
            RenderMethods(typeDoc.ClientMethods.OrderBy(m => m.Name), "Client methods");
            RenderClientEvents(typeDoc.ClientEvents.OrderBy(p => p.Name));

            return _docStringBuilder.ToString();
        }

        void RenderTypeRemarks(string typeRemarks) {
            _docStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderText(_renderer.Sanitize(typeRemarks)));
        }

        void RenderTypeName(string typeName) {
            _docStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderHeader(typeName));
        }

        void RenderSampleSiteLink(string typeName) {
            var url = LinkHelper.GetSampleSiteLink(typeName);
            _docStringBuilder.Append(String.Format(" ({0})", _renderer.RenderUrl("demo", url)));
        }

        void RenderTypeDescription(string typeDescription) {
            _docStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderText(_renderer.Sanitize(typeDescription)));
        }

        void RenderMethods(IEnumerable<MethodDoc> methods, string headerText) {
            if(methods.Count() <= 0)
                return;

            var methodsStringBuilder = new StringBuilder();
            methodsStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderHeader(headerText, level: 2));<commit_msg>Order of rendering changed<commit_after>﻿using AjaxControlToolkit.Reference.Core.Rendering;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace AjaxControlToolkit.Reference.Core {

    public class ExtenderDoc {
        IDocRenderer _renderer;
        StringBuilder _docStringBuilder = new StringBuilder();

        public ExtenderDoc(IDocRenderer renderer) {
            _renderer = renderer;
        }

        public string BuildDoc(IEnumerable<TypeDoc> typeDocs) {
            var sb = new StringBuilder();

            foreach(var typeDoc in typeDocs)
                sb.Append(BuildTypeDoc(typeDoc));

            return sb.ToString();
        }

        public string BuildTypeDoc(TypeDoc typeDoc) {
            _docStringBuilder.Clear();

            RenderTypeName(typeDoc.Name);
            RenderSampleSiteLink(typeDoc.Name);
            RenderTypeDescription(typeDoc.Summary);
            RenderTypeRemarks(typeDoc.Remarks);

            RenderProperties(typeDoc.Properties.OrderBy(p => p.Name));
            RenderMethods(typeDoc.Methods.OrderBy(m => m.Name), "Methods");
            RenderEvents(typeDoc.Events.OrderBy(e => e.Name));
            
            RenderClientProperties(typeDoc.ClientProperties.OrderBy(p => p.Name));
            RenderMethods(typeDoc.ClientMethods.OrderBy(m => m.Name), "Client methods");
            RenderClientEvents(typeDoc.ClientEvents.OrderBy(p => p.Name));

            return _docStringBuilder.ToString();
        }

        void RenderTypeRemarks(string typeRemarks) {
            _docStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderText(_renderer.Sanitize(typeRemarks)));
        }

        void RenderTypeName(string typeName) {
            _docStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderHeader(typeName));
        }

        void RenderSampleSiteLink(string typeName) {
            var url = LinkHelper.GetSampleSiteLink(typeName);
            _docStringBuilder.Append(String.Format(" ({0})", _renderer.RenderUrl("demo", url)));
        }

        void RenderTypeDescription(string typeDescription) {
            _docStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderText(_renderer.Sanitize(typeDescription)));
        }

        void RenderMethods(IEnumerable<MethodDoc> methods, string headerText) {
            if(methods.Count() <= 0)
                return;

            var methodsStringBuilder = new StringBuilder();
            methodsStringBuilder.Append(_renderer.RenderLineBreak() + _renderer.RenderHeader(headerText, level: 2));
{'fraction_non_alphanumeric': 0.09969088098918083, 'fraction_numerical': 0.00115919629057187, 'mean_word_length': 2.815033161385409, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '637230', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1337, 'n_words': 218}