<commit_before>module Page.PackageDocs where

import Basics (..)
import Color
import ColorScheme as C
import Dict
import Json
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.PackageDocs as Docs


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

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


descriptionUrl : String
descriptionUrl =
  "/description?name=" ++ context.user ++ "/" ++ context.name ++ "&version=" ++ context.version


description : Signal.Signal Docs.PackageInfo
description =
    Http.sendGet (Signal.constant descriptionUrl)
      |> Signal.map handleResult


packageInfo : [String] -> Docs.PackageInfo
packageInfo modules =
  Docs.PackageInfo context.user context.name context.version modules


handleResult : Http.Response String -> Docs.PackageInfo
handleResult response =
  case response of
    Http.Success string ->
      case Json.fromString string of
        Result.Ok (Json.Object dict) ->
          case Dict.get "exposed-modules" dict of
            Just (Json.Array modules) ->
                packageInfo (List.map (\(Json.String s) -> s) modules)
            _ -> packageInfo []

        _ -> packageInfo []

    _ -> packageInfo []


readme : Signal.Signal (Maybe String)
readme =
    Signal.constant Nothing

<commit_msg>Load README.md<commit_after>module Page.PackageDocs where

import Basics (..)
import Color
import ColorScheme as C
import Dict
import Json
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.PackageDocs as Docs


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

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


descriptionUrl : String
descriptionUrl =
  "/packages/" ++ context.user ++ "/" ++ context.name ++ "/" ++ context.version ++ "/elm_package.json"


description : Signal.Signal Docs.PackageInfo
description =
    Http.sendGet (Signal.constant descriptionUrl)
      |> Signal.map handleResult


packageInfo : [String] -> Docs.PackageInfo
packageInfo modules =
  Docs.PackageInfo context.user context.name context.version modules


handleResult : Http.Response String -> Docs.PackageInfo
handleResult response =
  case response of
    Http.Success string ->
      case Json.fromString string of
        Result.Ok (Json.Object dict) ->
          case Dict.get "exposed-modules" dict of
            Just (Json.Array modules) ->
                packageInfo (List.map (\(Json.String s) -> s) modules)
            _ -> packageInfo []

        _ -> packageInfo []

    _ -> packageInfo []


readmeUrl : String
readmeUrl =
  "/packages/" ++ context.user ++ "/" ++ context.name ++ "/" ++ context.version ++ "/README.md"


readme : Signal.Signal (Maybe String)
readme =
    Http.sendGet (Signal.constant readmeUrl)
      |> Signal.map extractReadme


extractReadme : Http.Response String -> Maybe String
extractReadme response =
  case response of
    Http.Success str -> Just str
    _ -> Nothing


{'fraction_non_alphanumeric': 0.10982658959537572, 'fraction_numerical': 0.0, 'mean_word_length': 3.141057934508816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '7562597', 'n_tokens_mistral': 934, 'n_tokens_neox': 895, 'n_words': 279}