Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
22dadba214
6 changed files with 42 additions and 11 deletions
|
|
@ -237,10 +237,7 @@ proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
||||||
var r = parseUrl(url)
|
var r = parseUrl(url)
|
||||||
|
|
||||||
var headers = copy($httpMethod, len("http"))
|
var headers = copy($httpMethod, len("http"))
|
||||||
if r.path != "":
|
headers.add(" /" & r.path & r.query)
|
||||||
headers.add(" /" & r.path & r.query)
|
|
||||||
else:
|
|
||||||
headers.add(" /")
|
|
||||||
headers.add(" HTTP/1.1\c\L")
|
headers.add(" HTTP/1.1\c\L")
|
||||||
|
|
||||||
add(headers, "Host: " & r.hostname & "\c\L")
|
add(headers, "Host: " & r.hostname & "\c\L")
|
||||||
|
|
|
||||||
|
|
@ -700,6 +700,18 @@ proc `$`*(node: PJsonNode): String =
|
||||||
result = ""
|
result = ""
|
||||||
toPretty(result, node, 1, False)
|
toPretty(result, node, 1, False)
|
||||||
|
|
||||||
|
iterator items*(node: PJsonNode): PJSonNode =
|
||||||
|
## Iterator for the items of `node`. `node` has to be a JArray.
|
||||||
|
assert node.kind == JArray
|
||||||
|
for i in items(node.elems):
|
||||||
|
yield i
|
||||||
|
|
||||||
|
iterator pairs*(node: PJsonNode): tuple[key: string, val: PJsonNode] =
|
||||||
|
## Iterator for the child elements of `node`. `node` has to be a JObject.
|
||||||
|
assert node.kind == JObject
|
||||||
|
for key, val in items(node.fields):
|
||||||
|
yield (key, val)
|
||||||
|
|
||||||
proc eat(p: var TJsonParser, tok: TTokKind) =
|
proc eat(p: var TJsonParser, tok: TTokKind) =
|
||||||
if p.tok == tok: discard getTok(p)
|
if p.tok == tok: discard getTok(p)
|
||||||
else: raiseParseErr(p, tokToStr[tok])
|
else: raiseParseErr(p, tokToStr[tok])
|
||||||
|
|
@ -711,7 +723,7 @@ proc parseJson(p: var TJsonParser): PJsonNode =
|
||||||
result = newJString(p.a)
|
result = newJString(p.a)
|
||||||
discard getTok(p)
|
discard getTok(p)
|
||||||
of tkInt:
|
of tkInt:
|
||||||
result = newJInt(parseInt(p.a))
|
result = newJInt(parseBiggestInt(p.a))
|
||||||
discard getTok(p)
|
discard getTok(p)
|
||||||
of tkFloat:
|
of tkFloat:
|
||||||
result = newJFloat(parseFloat(p.a))
|
result = newJFloat(parseFloat(p.a))
|
||||||
|
|
|
||||||
|
|
@ -1130,6 +1130,12 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1".} =
|
||||||
when defined(windows): return getEnv("APPDATA") & "\\"
|
when defined(windows): return getEnv("APPDATA") & "\\"
|
||||||
else: return getEnv("HOME") & "/.config/"
|
else: return getEnv("HOME") & "/.config/"
|
||||||
|
|
||||||
|
proc getTempDir*(): string {.rtl, extern: "nos$1".} =
|
||||||
|
## Returns the temporary directory of the current user for applications to
|
||||||
|
## save temporary files in.
|
||||||
|
when defined(windows): return getEnv("TEMP") & "\\"
|
||||||
|
else: return "/tmp/"
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
# Since we support GUI applications with Nimrod, we sometimes generate
|
# Since we support GUI applications with Nimrod, we sometimes generate
|
||||||
# a WinMain entry proc. But a WinMain proc has no access to the parsed
|
# a WinMain entry proc. But a WinMain proc has no access to the parsed
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ proc parse(x: var TXmlParser, errors: var seq[string]): PXmlNode =
|
||||||
of xmlElementOpen:
|
of xmlElementOpen:
|
||||||
result = newElement(x.elementName)
|
result = newElement(x.elementName)
|
||||||
next(x)
|
next(x)
|
||||||
result.attr = newStringTable()
|
result.attrs = newStringTable()
|
||||||
while true:
|
while true:
|
||||||
case x.kind
|
case x.kind
|
||||||
of xmlAttribute:
|
of xmlAttribute:
|
||||||
result.attr[x.attrKey] = x.attrValue
|
result.attrs[x.attrKey] = x.attrValue
|
||||||
next(x)
|
next(x)
|
||||||
of xmlElementClose:
|
of xmlElementClose:
|
||||||
next(x)
|
next(x)
|
||||||
|
|
|
||||||
|
|
@ -98,17 +98,17 @@ iterator items*(n: PXmlNode): PXmlNode {.inline.} =
|
||||||
assert n.k == xnElement
|
assert n.k == xnElement
|
||||||
for i in 0 .. n.len-1: yield n[i]
|
for i in 0 .. n.len-1: yield n[i]
|
||||||
|
|
||||||
proc attr*(n: PXmlNode): PXmlAttributes {.inline.} =
|
proc attrs*(n: PXmlNode): PXmlAttributes {.inline.} =
|
||||||
## gets the attributes belonging to `n`.
|
## gets the attributes belonging to `n`.
|
||||||
assert n.k == xnElement
|
assert n.k == xnElement
|
||||||
result = n.fAttr
|
result = n.fAttr
|
||||||
|
|
||||||
proc `attr=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} =
|
proc `attrs=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} =
|
||||||
## sets the attributes belonging to `n`.
|
## sets the attributes belonging to `n`.
|
||||||
assert n.k == xnElement
|
assert n.k == xnElement
|
||||||
n.fAttr = attr
|
n.fAttr = attr
|
||||||
|
|
||||||
proc attrLen*(n: PXmlNode): int {.inline.} =
|
proc attrsLen*(n: PXmlNode): int {.inline.} =
|
||||||
## returns the number of `n`'s attributes.
|
## returns the number of `n`'s attributes.
|
||||||
assert n.k == xnElement
|
assert n.k == xnElement
|
||||||
if not isNil(n.fAttr): result = len(n.fAttr)
|
if not isNil(n.fAttr): result = len(n.fAttr)
|
||||||
|
|
@ -262,3 +262,16 @@ macro `<>`*(x: expr): expr =
|
||||||
##
|
##
|
||||||
result = xmlConstructor(x)
|
result = xmlConstructor(x)
|
||||||
|
|
||||||
|
proc child*(n: PXmlNode, name: string): PXmlNode =
|
||||||
|
## Finds the first child element of `n` with a name of `name`.
|
||||||
|
## Returns `nil` on failure.
|
||||||
|
assert n.kind == xnElement
|
||||||
|
for i in items(n):
|
||||||
|
if i.kind == xnElement:
|
||||||
|
if i.tag == name:
|
||||||
|
return i
|
||||||
|
|
||||||
|
proc attr*(n: PXmlNode, name: string): string =
|
||||||
|
## Finds the first attribute of `n` with a name of `name`.
|
||||||
|
assert n.kind == xnElement
|
||||||
|
return n.attrs[name]
|
||||||
|
|
|
||||||
|
|
@ -1059,7 +1059,7 @@ type
|
||||||
TResponseType* = int32
|
TResponseType* = int32
|
||||||
PDialog* = ptr TDialog
|
PDialog* = ptr TDialog
|
||||||
TDialog* = object of TWindow
|
TDialog* = object of TWindow
|
||||||
vbox*: PWidget
|
vbox*: PBox
|
||||||
action_area*: PWidget
|
action_area*: PWidget
|
||||||
separator*: PWidget
|
separator*: PWidget
|
||||||
|
|
||||||
|
|
@ -16866,6 +16866,9 @@ proc set_do_overwrite_confirmation*(chooser: PFileChooser,
|
||||||
do_overwrite_confirmation: gboolean){.cdecl, dynlib: lib,
|
do_overwrite_confirmation: gboolean){.cdecl, dynlib: lib,
|
||||||
importc: "gtk_file_chooser_set_do_overwrite_confirmation".}
|
importc: "gtk_file_chooser_set_do_overwrite_confirmation".}
|
||||||
|
|
||||||
|
proc get_realized*(w: PWidget): gboolean {.cdecl, dynlib: lib,
|
||||||
|
importc: "gtk_widget_get_realized".}
|
||||||
|
|
||||||
proc nimrod_init*() =
|
proc nimrod_init*() =
|
||||||
var
|
var
|
||||||
cmdLine{.importc: "cmdLine".}: array[0..255, cstring]
|
cmdLine{.importc: "cmdLine".}: array[0..255, cstring]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue