summary refs log tree commit diff stats
path: root/tests/stdlib/tcritbits.nim
Commit message (Collapse)AuthorAgeFilesLines
* tests: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-041-1/+1
| | | | via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
* new tester; all tests categorizedAraq2014-01-131-0/+28
Dominik Picheta <dominikpicheta@googlemail.com> 2014-04-12 00:09:03 +0100 Implemented babel package list in lib.html.' href='/ahoang/Nim/commit/web/babelpkglist.nim?h=devel&id=58e583e39be138a98dd66ea46750d40b44a7352a'>58e583e39 ^
a9a5766c6 ^
ca937cdba ^
58e583e39 ^





e21999c2c ^

58e583e39 ^


53538da04 ^
58e583e39 ^


e21999c2c ^

9fd6464a7 ^
e21999c2c ^
53538da04 ^
1dd9fbf70 ^
58e583e39 ^








bddfe007b ^
58e583e39 ^
1dd9fbf70 ^
58e583e39 ^
58e583e39 ^


bddfe007b ^
58e583e39 ^
1dd9fbf70 ^
58e583e39 ^
58e583e39 ^











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80


         











                                                      
                                                  








                                      
                                          
                                                        





                       

                        


                              
                                    


                                          

                                   
                                                                         
                                                                     
                                                                  
                                                                








                                                                     
                                
                                               
                                                               
                    


                                                                         
                                  
                                                 
                                                                 
                      











                                                                           
#[
deadcode?
]#
import base64, strutils, json, htmlgen, dom, algorithm

type
  TData = object
    content {.importc.}: cstring

proc decodeContent(content: string): string =
  result = ""
  for line in content.splitLines:
    if line != "":
      result.add decode(line)

proc contains(x: seq[JSonNode], s: string): bool =
  for i in x:
    assert i.kind == JString
    if i.str == s: return true

proc processContent(content: string) =
  var jsonDoc = parseJson(content)
  assert jsonDoc.kind == JArray
  var jsonArr = jsonDoc.elems

  jsonArr.sort do (x, y: JsonNode) -> int:
    strutils.cmpIgnoreCase(x["name"].str, y["name"].str)

  var
    officialList = ""
    officialCount = 0
    unofficialList = ""
    unofficialCount = 0
  let
    endings = {'.', '!'}

  for pkg in jsonArr:
    assert pkg.kind == JObject
    if not pkg.hasKey"url": continue
    let pkgWeb =
      if pkg.hasKey("web"): pkg["web"].str
      else: pkg["url"].str
    let
      desc = pkg["description"].str
      dot = if desc.high > 0 and desc[desc.high] in endings: "" else: "."
      listItem = li(a(href=pkgWeb, pkg["name"].str), " ", desc & dot)
    if pkg["url"].str.startsWith("https://github.com/nim-lang") or
       pkg["url"].str.startsWith("git://github.com/nim-lang") or
       "official" in pkg["tags"].elems:
      officialCount.inc
      officialList.add listItem & "\n"
    else:
      unofficialCount.inc
      unofficialList.add listItem & "\n"

  var officialPkgListDiv = document.getElementById("officialPkgList")

  officialPkgListDiv.innerHTML =
    p("There are currently " & $officialCount &
      " official packages in the Nimble package repository.") &
    ul(officialList)

  var unofficialPkgListDiv = document.getElementById("unofficialPkgList")

  unofficialPkgListDiv.innerHTML =
    p("There are currently " & $unofficialCount &
      " unofficial packages in the Nimble package repository.") &
    ul(unofficialList)

proc gotPackageList(apiReply: TData) {.exportc.} =
  let decoded = decodeContent($apiReply.content)
  try:
    processContent(decoded)
  except:
    var officialPkgListDiv = document.getElementById("officialPkgList")
    var unofficialPkgListDiv = document.getElementById("unofficialPkgList")
    let msg = p("Unable to retrieve package list: ",
      code(getCurrentExceptionMsg()))
    officialPkgListDiv.innerHTML = msg
    unofficialPkgListDiv.innerHTML = msg