<commit_before>﻿[<ReflectedDefinition>]
module Site.Samples

open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.JQuery
open IntelliFactory.WebSharper.Html

type Sample =
    private {
        FileName : string
        Keywords : list<string>
        Render : Dom.Element -> unit
        Title : string
    }

    static member Create(title, fileName, keywords, render) =
        {
            FileName = fileName
            Keywords = keywords
            Render = render
            Title = title
        }

type Builder =
    private {
        BFileName : string
        mutable BKeywords : list<string>
        mutable BRender : Dom.Element -> unit
        mutable BTitle : string
    }

    member b.Create() =
        Sample.Create(b.BTitle, b.BFileName, b.BKeywords, b.BRender)

    member b.Keywords(x) = b.BKeywords <- x; b
    member b.Render(x) = b.BRender <- x; b
    member b.Title(x) = b.BTitle <- x; b

let Build (fn: string) =
    {
        BFileName = fn
        BKeywords = []
        BRender = fun _ -> JavaScript.Log("RENDER/0")
        BTitle = "Sample"
    }

let private Clear (el: Dom.Element) =
    while el.HasChildNodes() do
        el.RemoveChild(el.FirstChild) |> ignore

type Sample with

    member s.Show() =
        let mainLeft = Dom.Document.Current.GetElementById("main-left")
        let mainRight = Dom.Document.Current.GetElementById("main-right")
        Clear mainLeft
        Clear mainRight
        s.Render(mainRight)
        let url = "http://gist-it.appspot.com/github/intellifactory/websharper.d3/blob/master/Site/" + s.FileName
        let s = Script [Attr.Src url]
        // s.AppendTo("main-left")
        ()

type Set =
    private
    | Set of list<Sample>

    static member Create(ss) = Set [for (Set xs) in ss do yield! xs]
    static member Singleton(s) = Set [s]

    member s.Show() =
        JQuery.JQuery.Of(fun () ->
            let (Set samples) = s
            let doc = Dom.Document.Current
            let select (s: Sample) (dom: Dom.Element) =
                let j = JQuery.Of("#sample-navs ul").Children("li").RemoveClass("active")
                JQuery.Of(dom).AddClass("active").Ignore
                s.Show()
            let rec navs =
                UL [Attr.Class "nav nav-pills"] -< (
                    samples<commit_msg>Display source [skip ci]<commit_after>﻿[<ReflectedDefinition>]
module Site.Samples

open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.JQuery
open IntelliFactory.WebSharper.Html

type Sample =
    private {
        FileName : string
        Keywords : list<string>
        Render : Dom.Element -> unit
        Title : string
    }

    static member Create(title, fileName, keywords, render) =
        {
            FileName = fileName
            Keywords = keywords
            Render = render
            Title = title
        }

type Builder =
    private {
        BFileName : string
        mutable BKeywords : list<string>
        mutable BRender : Dom.Element -> unit
        mutable BTitle : string
    }

    member b.Create() =
        Sample.Create(b.BTitle, b.BFileName, b.BKeywords, b.BRender)

    member b.Keywords(x) = b.BKeywords <- x; b
    member b.Render(x) = b.BRender <- x; b
    member b.Title(x) = b.BTitle <- x; b

let Build (fn: string) =
    {
        BFileName = fn
        BKeywords = []
        BRender = ignore
        BTitle = "Sample"
    }

let private Clear (el: Dom.Element) =
    while el.HasChildNodes() do
        el.RemoveChild(el.FirstChild) |> ignore

type Sample with

    member s.Show() =
        let mainLeft = Dom.Document.Current.GetElementById("main-left")
        let mainRight = Dom.Document.Current.GetElementById("main-right")
        Clear mainLeft
        Clear mainRight
        s.Render(mainRight)
        let url = "http://gist-it.appspot.com/github/intellifactory/websharper.d3/blob/master/Site/" + s.FileName
        let s = Script [Attr.Src url]
        s.AppendTo("main-left")

type Set =
    private
    | Set of list<Sample>

    static member Create(ss) = Set [for (Set xs) in ss do yield! xs]
    static member Singleton(s) = Set [s]

    member s.Show() =
        JQuery.JQuery.Of(fun () ->
            let (Set samples) = s
            let doc = Dom.Document.Current
            let select (s: Sample) (dom: Dom.Element) =
                let j = JQuery.Of("#sample-navs ul").Children("li").RemoveClass("active")
                JQuery.Of(dom).AddClass("active").Ignore
                s.Show()
            let rec navs =
                UL [Attr.Class "nav nav-pills"] -< (
                    samples
{'fraction_non_alphanumeric': 0.11270670147954744, 'fraction_numerical': 0.0006527415143603133, 'mean_word_length': 1.9467948717948718, 'pattern_counts': {'":': 0, '<': 19, '<?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': '568869', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1388, 'n_words': 345}