<commit_before>module Page.ModuleDocs where

import Basics (..)
import Color
import ColorScheme as C
import Debug
import Dict
import JavaScript as JS
import Graphics.Element (..)
import Http
import List
import List ((++))
import Maybe (..)
import Result
import Signal
import String
import Window

import Component.TopBar as TopBar
import Component.ModuleDocs as Docs


port context : { user : String, name : String, version : String, moduleName : String }

port title : String
port title =
    context.user ++ "/" ++ context.name ++ " " ++ context.moduleName ++ " " ++ context.version


documentationUrl : String
documentationUrl =
  let name = String.map (\c -> if c == '.' then '-' else c) context.moduleName
  in
      "/packages/" ++ context.user ++ "/" ++ context.name ++ "/"
      ++ context.version ++ "/docs/" ++ name ++ ".json"


documentation : Signal.Signal Docs.Documentation
documentation =
    Http.sendGet (Signal.constant documentationUrl)
      |> Signal.map handleResult


dummyDocs : Docs.Documentation
dummyDocs =
  Docs.Documentation context.moduleName "Loading documentation..." [] [] []


handleResult : Http.Response String -> Docs.Documentation
handleResult response =
  case response of
    Http.Success string ->
      case Result.andThen (JS.fromString string) (JS.get Docs.documentation) of
        Result.Ok docs -> docs
        Result.Err msg -> { dummyDocs | comment <- Debug.log "error" msg }

    _ -> dummyDocs


main : Signal.Signal Element
main =
    Signal.map2 view Window.dimensions documentation


search : Signal.Channel TopBar.Update
search =
    Signal.channel TopBar.NoOp


view : (Int,Int) -> Docs.Documentation -> Element
view (windowWidth, windowHeight) docs =
  color C.background <|
  flow down
  [ TopBar.view windowWidth search (TopBar.Model TopBar.Global "map" TopBar.Normal)
  , flow right
    [ spacer ((windowWidth - 980) // 2) (windowHeight - TopBar.topBarHeight)
    , Docs.view 980 "elm-lang" "core" docs
    ]
  ]
<commit_msg>Nicer error message when docs are bad<commit_after>module Page.ModuleDocs where

import Basics (..)
import Color
import ColorScheme as C
import Debug
import Dict
import JavaScript as JS
import Graphics.Element (..)
import Http
import List
import List ((++))
import Maybe (..)
import Result
import Signal
import String
import Window

import Component.TopBar as TopBar
import Component.ModuleDocs as Docs


port context : { user : String, name : String, version : String, moduleName : String }

port title : String
port title =
    context.user ++ "/" ++ context.name ++ " " ++ context.moduleName ++ " " ++ context.version


documentationUrl : String
documentationUrl =
  let name = String.map (\c -> if c == '.' then '-' else c) context.moduleName
  in
      "/packages/" ++ context.user ++ "/" ++ context.name ++ "/"
      ++ context.version ++ "/docs/" ++ name ++ ".json"


documentation : Signal.Signal Docs.Documentation
documentation =
    Http.sendGet (Signal.constant documentationUrl)
      |> Signal.map handleResult


dummyDocs : Docs.Documentation
dummyDocs =
  Docs.Documentation context.moduleName "Loading documentation..." [] [] []


handleResult : Http.Response String -> Docs.Documentation
handleResult response =
  case response of
    Http.Success string ->
      case Result.andThen (JS.fromString string) (JS.get Docs.documentation) of
        Result.Ok docs -> docs
        Result.Err msg ->
            { dummyDocs |
                comment <- "There was an error loading these docs! They may be corrupted."
            }

    _ -> dummyDocs


main : Signal.Signal Element
main =
    Signal.map2 view Window.dimensions documentation


search : Signal.Channel TopBar.Update
search =
    Signal.channel TopBar.NoOp


view : (Int,Int) -> Docs.Documentation -> Element
view (windowWidth, windowHeight) docs =
  color C.background <|
  flow down
  [ TopBar.view windowWidth search (TopBar.Model TopBar.Global "map" TopBar.Normal)
  , flow right
    [ spacer ((windowWidth - 980) // 2) (windowHeight - TopBar.topBarHeight)
    , Docs.view 980 "elm-lang" "core" docs
    ]
  ]

{'fraction_non_alphanumeric': 0.11402648357037763, 'fraction_numerical': 0.00392349190779794, 'mean_word_length': 3.280167890870934, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '5690154', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1156, 'n_words': 366}