[Karax] await for ajaxget

2020-05-02 Thread jjude
How to await ajaxget (or any ajax methods). I have this code:


import sugar, json, karax / [kajax, kdom], asyncjs

proc onGetObj(status: int, resp: kstring) =
let retVal = parseJson($resp)
echo retVal

proc getObj(sd: string) {.async} =
await ajaxGet("/api/v1/obj/" & sd & "/", @[state.header], onGetObj)


Run

I get an error:


Error: type mismatch: got 
but expected one of:
proc await[T](f`gensym271651: Future[T]): T


Run

What is the correct code?


Re: Video series: Making a WebSite with Nim

2020-04-20 Thread jjude
Great tutorial series. Thank you for this.

Are the code shown in the video somewhere in github?


Re: Nim Forum build error

2020-04-17 Thread jjude
` Verifying dependencies for nimforum@2.0.2 Reading official package list 
Checking for jester@#d8a03aa Info: Dependency on jester@#d8a03aa already 
satisfied Verifying dependencies for jester@#d8a03aa Reading official package 
list Checking for httpbeast@>= 0.2.2 Info: Dependency on httpbeast@>= 0.2.2 
already satisfied Verifying dependencies for httpbeast@0.2.2 Reading official 
package list Checking for 
https://github.com/timotheecour/asynctools@#pr_fix_compilation Info: Dependency 
on https://github.com/timotheecour/asynctools@#pr_fix_compilation already 
satisfied Verifying dependencies for asynctools@#pr_fix_compilation Reading 
official package list Checking for 
https://github.com/timotheecour/asynctools@#pr_fix_compilation Info: Dependency 
on https://github.com/timotheecour/asynctools@#pr_fix_compilation already 
satisfied Verifying dependencies for asynctools@#pr_fix_compilation Reading 
official package list Checking for bcrypt@#head Info: Dependency on 
bcrypt@#head already satisfied Verifying dependencies for bcrypt@#head Reading 
official package list Checking for hmac@#9c61ebe2fd134cf97 Info: Dependency on 
hmac@#9c61ebe2fd134cf97 already satisfied Verifying dependencies for 
hmac@#9c61ebe2fd134cf97 Reading official package list Checking for nimSHA2@any 
version Info: Dependency on nimSHA2@any version already satisfied Verifying 
dependencies for nimSHA2@0.1.1 Reading official package list Checking for 
sha1@any version Info: Dependency on sha1@any version already satisfied 
Verifying dependencies for sha1@1.1 Reading official package list Checking for 
recaptcha@#d06488e Info: Dependency on recaptcha@#d06488e already satisfied 
Verifying dependencies for recaptcha@#d06488e Reading official package list 
Checking for sass@#649e0701fa5c Info: Dependency on sass@#649e0701fa5c already 
satisfied Verifying dependencies for sass@#649e0701fa5c Reading official 
package list Checking for karax@#f6bda9a Installing karax@#f6bda9a Reading 
official package list Downloading https://github.com/pragmagic/karax using git 
Executing git clone --recursive https://github.com/pragmagic/karax 
/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a
 Finished with exit code 0 Output Cloning into 
'/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a'...
 Executing git checkout --force f6bda9a Finished with exit code 0 Output Note: 
switching to 'f6bda9a'. ... You are in 'detached HEAD' state. You can look 
around, make experimental ... changes and commit them, and you can discard any 
commits you make in this ... state without impacting any branches by switching 
back to a branch. ... If you want to create a new branch to retain commits you 
create, you may ... do so (now or later) by using -c with the switch command. 
Example: ... git switch -c  ... Or undo this operation with: 
... git switch - ... Turn off this advice by setting config variable 
advice.detachedHead to false ... HEAD is now at f6bda9a Reactive value (#129) 
Executing git submodule update --recursive Finished with exit code 0 Debug: 
Executing nim e --hints:off --verbosity:0 
-p:/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimblecache 
'/private/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a/karax_30468.nims'
 /var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468.out printPkgInfo 
Warning: Not removing temporary path because of debug verbosity: 
/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468.out Warning: Not 
removing temporary path because of debug verbosity: 
/private/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a/karax_30468.nims
 Info 
/private/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a/karax_30468.nims(5,
 22) Warning: imported and not used: 'strutils' [UnusedImport] Debug: Executing 
nim e --hints:off --verbosity:0 
-p:/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimblecache 
'/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a/karax_30468.nims'
 /var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468.out printPkgInfo 
Info 
/private/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468/githubcom_pragmagickarax_#f6bda9a/karax_30468.nims(5,
 22) Warning: imported and not used: 'strutils' [UnusedImport] Verifying 
dependencies for karax@#f6bda9a Installing karax@#f6bda9a Warning: Not removing 
temporary path because of debug verbosity: 
/var/folders/k_/013v486j1w98mvzh31dcwmvmgn/T/nimble_30468 Error: No 
binaries built, did you specify a valid binary name? `

Run


Re: Nim Forum build error

2020-04-17 Thread jjude
Tried both (verbose & individual command). Same error: No binaries built, did 
you specify a valid binary name?


Nim Forum build error

2020-04-17 Thread jjude
I used the latest code from github. Issued 


git submodule update --init --recursive
nimble frontend


Run

I get this error: Error: No binaries built, did you specify a valid binary 
name?.

Nim version: Nim Compiler Version 1.0.6 [MacOSX: amd64]

How to go further?


Re: Initializing a page with data from backend in Karax

2020-04-14 Thread jjude
while this works if I have only one object, it doesn't serve the purpose if I 
have multiple objects in different files - says sites in sites.nim, entries in 
entries.nim and so on. If I have these global ajaxGet in each of these files, 
they are all called at the start of the program which is undesirable. Also when 
user clicks on a different site, I want to fetch and display details of that 
site.

In react & vue there are lifecycle events with init which is called when the 
component is created. Is there something similar in Karax?

If not, how can this be done - fetching info for each object at the time of 
display. 


Initializing a page with data from backend in Karax

2020-04-14 Thread jjude
I'm using karax to write a SPA. I'm using routes as mentioned in the readme.

There is a signin form which gets a token from the backend api. Then the app 
has to display list of sites for that token


proc createDom(data: RouterData): VNode =
let uri = $data.hashPart
# it could be accessed / or #/
if uri.len == 0 or uri == "#/":
if state.token.len > 2: objectToShow = siteobj else: objectToShow = 
signinobj
elif uri.len > 2 and uri[0 .. 7] == "#/sites/": objectToShow = sitesobj
elif uri == "#/entries/": objectToShow = entryobj
result = buildHtml(tdiv(class="todomvc-wrapper")):
section(class = "todoapp"):
if uri.len > 8: state.siteId = uri[8 .. ^1]
case objectToShow:
of signinobj: signinForm()
of sitesobj:  sites()
else: entry()

setRenderer createDom


Run

In the signin form, I have this:


 tdiv(class="mt3"):
button(`type`="submit"):
text "Sign-In"
proc onclick(ev: Event; n: VNode) =
ajaxPost("/api/v1/signin/",@[],$( %* {"email": $email, 
"password": $password}), (s:int, r: kstring)=>onPost(s,r))
ev.preventDefault()


Run

So far so good.

Now I need to pull sites. I tried having it like this:


proc initSites() =


proc sites*():VNode =
initSites()
buildHtml(tdiv):
h1(id="title", class="tc ph4"): text "Olai - Static Blogging Tool"
header(class="tc mt4"):
h2(class="f6 gray fw2 ttu tracked"): text "Sites" & state.siteId


Run

This gets called repeatedly (which I suppose render funcition is called 
repeatedly). Need help in coding this piece. How to pull data from backend to 
initialise a page?


Re: Announcement: The Nim compiler is rewritten in Python with some modules optimized in C

2020-04-01 Thread jjude
 臘‍♂️ Nice one.


Re: Announcement: The Nim compiler is rewritten in Python with some modules optimized in C

2020-04-01 Thread jjude
All of NIM will be rewritten in Python or only machine learning part? Isn't 
rewriting all of the language into another language waste of time rather than 
spending it on improving either the language or the ecosystem? 


Re: Styling Karax app

2020-02-26 Thread jjude
@juancarlospaco: I am not looking for css themes. I use tachyons and am happy 
with it. I want to know how to use these within Karax during development.


Re: Styling Karax app

2020-02-26 Thread jjude
Thanks @Araq.

  1. I see that this forum uses Spectre.css. But there is no mention of this 
css in the codebase itself. How did you (or whoever is the author) did it? I 
see a mock folder. Is it that you mocked the htmls, generated css and linked it 
back to the generated html?
  2. If the process is more like #1 then how are the layouts and styling happen 
during development? Wouldn't it be a blind process without really knowing how 
the end result will look like? In js frameworks like vue and react, you can 
style within the components itself so during the development the developer can 
see the styles. Is that possible with Karax?




Styling Karax app

2020-02-26 Thread jjude
I'm starting with Karax apps. Gone through some of the introductory examples. 
How do you style these especially with things like Bootstrap or other CSS 
frameworks?


json confusion

2020-02-18 Thread jjude
I am writing an api sever in Nim. The output is of the form: 


{
code:"tk.01",
message: "Token in data field",
data:"12345"
}



Run

data field could be a string, single object (say a blog post), or an array 
(sequence) of objects (list of posts). I was successful in emitting the string 
without any trouble. But I want to make a generic object that I can use to hold 
these values around the application.


type retVal = object
code: string
message: string
data: ?


Run

I don't know what datatype data should be.

Also I am trying to create a proc that can output a json to the outside world 
(not just withing Nim application). Everything I tried with json module outputs 
as string rather than json (like the above) for objects.

The following code prints json correctly, but I'm lost how to pass json in and 
out of procs.


import marshal

type
  Person = object
age: int
name: string

var p = Person(age: 38, name: "Torbjørn")

echo($$p)


Run

Thanks


Is it possible to see sql executed?

2020-02-15 Thread jjude
I'm using Jester to create a web-application. It connects to sqlite using 
db_sqlite. For debugging purposes is it possible to see sqls executed during 
development?


Extended routes that return json doesn't compile

2020-02-06 Thread jjude
If I have all code in a single file:


import jester, json

routes:
  get "/":
var jsonResp = $(%*{"id": 2})
resp Http200, jsonResp


Run

This works well without any problem.

Now if I split this into two files:

main.nim


import jester
import api

routes:
  extend apiv1, "/api/v1"


Run

api.nim (in the same folder)


import jester, json

router apiv1:
  get "/":
var jsonResp = %*{"id": 2}
echo jsonResp
resp Http200, "hello"


Run

Then I get these errors:


jester.nim(1277, 9) Hint: Asynchronous route: apiv1. [User]
jester.nim(797, 9) Hint: 'settings' is declared but not used 
[XDeclaredButNotUsed]
jester.nim(1307, 26) Hint: 'apiv1ErrorHandler' is declared but not used 
[XDeclaredButNotUsed]
jester.nim(1280, 7) Hint: 'apiv1' is declared but not used 
[XDeclaredButNotUsed]
jester.nim(1277, 9) Hint: Asynchronous route: match. [User]
jester.nim(1283, 35) template/generic instantiation of `async` from here
/server/src/api.nim(5, 20) Error: undeclared identifier: '%*'


Run

I think it is a problem with creating json nodes. Can't understand how to 
resolve this.

Thanks for your help.


Re: Change server name in Jester

2020-02-06 Thread jjude
As a security measure it is advisable to hide the server name.

I don't know who to set it up by hand. I searched through Jester's settings 
document (and code) but couldn't find one that sets the server name. As an 
example, Beego (the framework I have used in Go) allows setting the servername 
using config: 
[https://beego.me/docs/mvc/controller/config.md](https://beego.me/docs/mvc/controller/config.md)


Change server name in Jester

2020-02-06 Thread jjude
I'm using Jester to write a REST server. Is it possible to change the server 
name from httpbeast?