joy-framework / joy

A full stack web framework written in janet
https://joy.swlkr.com
MIT License
537 stars 30 forks source link

"error: expected <type>, got nil" when creating a new route from CLI #67

Closed ghost closed 4 years ago

ghost commented 4 years ago

Everytime I run the create route command I get something like:

➜  anoni joy create route about
error: expected string|symbol|keyword|array|tuple|table|struct|buffer, got nil
  in map [boot.janet] on line 839, column 14
  in data [/usr/lib/janet/joy/cli/route.janet] on line 21, column 16
  in render [/usr/lib/janet/joy/cli/route.janet] on line 35, column 28
  in create [/usr/lib/janet/joy/cli/route.janet] (tailcall) on line 55, column 22

Running the latest Janet version.

swlkr commented 4 years ago

I should probably mention in the readme that routes map to database tables...

I could probably make a version of the route generator that doesn't rely on a database table too

swlkr commented 4 years ago

Currently you need to write out handlers without database tables by hand:

(route :get "/about" :about)
(defn about [req]
  [:h1 "/about"])
swlkr commented 4 years ago

Oh I think I get the confusion now, this is my fault for confusing the two terms.

I should do two things here:

  1. the joy create route x generator to just generate new files with single route functions in them like above
  2. rename the current route generator to joy create controller x

and then get rid of any docs that talk about joy having "no controllers" 😅

ghost commented 4 years ago

Yeah, I guess that's better! Keep it up, this is getting pretty good and usable

swlkr commented 4 years ago

So now this:

joy create route about

Will create (or update) a file named routes/pages.janet and put this in there:

(route :get "/about" :pages/about)
(defn pages/about [req]
  [:h1 "/about"])

oh and it also updates the main.janet file with an import statement:

(use joy)
(use ./routes/pages)