mirror of
https://github.com/daylinmorgan/nimpkgs.git
synced 2024-12-22 02:50:44 -06:00
kcall
This commit is contained in:
parent
77dbe8af05
commit
00e38fe2a5
3 changed files with 63 additions and 33 deletions
44
src/lib.nim
44
src/lib.nim
|
@ -1,4 +1,4 @@
|
||||||
import std/[strutils, uri]
|
import std/[strutils, uri, macros]
|
||||||
import std/jsffi except `&`
|
import std/jsffi except `&`
|
||||||
import jsconsole
|
import jsconsole
|
||||||
export jsconsole
|
export jsconsole
|
||||||
|
@ -20,12 +20,46 @@ proc currentUri*(): Uri {.inline.} =
|
||||||
func replace*(c: kstring, sub: string, by = " "): kstring =
|
func replace*(c: kstring, sub: string, by = " "): kstring =
|
||||||
($c).replace(sub, by).jss
|
($c).replace(sub, by).jss
|
||||||
|
|
||||||
|
macro kcall*(p: typed) =
|
||||||
|
## make procedure return another procedure that takes no arguments
|
||||||
|
##
|
||||||
|
## used for generating more succint callbacks compatible with karax
|
||||||
|
runnableExamples:
|
||||||
|
proc example(a: string) {.kcall.} =
|
||||||
|
echo a
|
||||||
|
example("hello world")()
|
||||||
|
|
||||||
|
expectKind p, nnkProcDef
|
||||||
|
if p.params[0].kind != nnkEmpty:
|
||||||
|
error "proc must return void"
|
||||||
|
var updated = copy(p)
|
||||||
|
let returnType = nnkProcTy.newTree(nnkFormalParams.newTree(newEmptyNode()), newEmptyNode())
|
||||||
|
updated.params = nnkFormalParams
|
||||||
|
.newTree(returnType)
|
||||||
|
.add(p.params[1 ..^ 1])
|
||||||
|
updated.body = nnkStmtList.newTree(
|
||||||
|
nnkLambda.newTree(
|
||||||
|
newEmptyNode(),
|
||||||
|
newEmptyNode(),
|
||||||
|
newEmptyNode(),
|
||||||
|
nnkFormalParams.newTree(newEmptyNode()),
|
||||||
|
newEmptyNode(),
|
||||||
|
newEmptyNode(),
|
||||||
|
p.body,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
result = nnkStmtList.newTree()
|
||||||
|
result.add updated
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
SortMethod* = enum
|
SortMethod* = enum
|
||||||
smAlphabetical = "smAlphabetical", smCommitAge = "commit", smVersionAge = "version"
|
smAlphabetical = "smAlphabetical", smCommitAge = "commit", smVersionAge = "version"
|
||||||
|
|
||||||
proc setSearchUrl*(searchQuery: kstring, sortMethod = smAlphabetical): proc() =
|
proc setSearchUrl*(
|
||||||
proc() =
|
searchQuery: kstring,
|
||||||
|
sortMethod = smAlphabetical
|
||||||
|
) {.kcall.} =
|
||||||
var
|
var
|
||||||
url = currentUri()
|
url = currentUri()
|
||||||
params: seq[(string, string)]
|
params: seq[(string, string)]
|
||||||
|
@ -50,9 +84,7 @@ proc getSearchInput*() =
|
||||||
)
|
)
|
||||||
setSearchUrl(searchInput, sortMethod)()
|
setSearchUrl(searchInput, sortMethod)()
|
||||||
|
|
||||||
|
proc setSearchInput*(q: kstring) {.kcall.} =
|
||||||
proc setSearchInput*(q: kstring): proc() =
|
|
||||||
result = proc() =
|
|
||||||
let sortNode = getVNodeById("sort-select")
|
let sortNode = getVNodeById("sort-select")
|
||||||
let sortMethod = SortMethod(
|
let sortMethod = SortMethod(
|
||||||
if sortNode != nil: parseInt($sortNode.getInputText)
|
if sortNode != nil: parseInt($sortNode.getInputText)
|
||||||
|
|
|
@ -6,8 +6,7 @@ import ../components/[tag, package]
|
||||||
import ../lib
|
import ../lib
|
||||||
import notfound
|
import notfound
|
||||||
|
|
||||||
proc openLink(link: kstring): proc() =
|
proc openLink(link: kstring) {.kcall.} =
|
||||||
result = proc() =
|
|
||||||
discard open(window, link, "_self")
|
discard open(window, link, "_self")
|
||||||
|
|
||||||
proc versionTable(pkg: NimPackage): VNode =
|
proc versionTable(pkg: NimPackage): VNode =
|
||||||
|
|
|
@ -17,8 +17,7 @@ type
|
||||||
|
|
||||||
var pgCtx = PageContext()
|
var pgCtx = PageContext()
|
||||||
|
|
||||||
proc scrollToAnchor(a: string): proc() =
|
proc scrollToAnchor(a: string){.kcall.} =
|
||||||
result = proc() =
|
|
||||||
let d = getVNodeById(a)
|
let d = getVNodeById(a)
|
||||||
scrollIntoView(d.dom)
|
scrollIntoView(d.dom)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue