soveran / toro

Tree oriented routing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App doesn't compile

gottlike opened this issue · comments

I was just trying to compile the readme's sample app and got the following error:

no overload matches 'App#on?' with type Nil
Overloads are:
 - Toro::Router#on?(cond : Bool)
 - Toro::Router#on?(str : String)
 - Toro::Router#on?(sym : Symbol)
================================================================================

Nil trace:

  macro root (in /Users/gottlike/Desktop/dev/example/page/libs/toro/toro.cr:130):1

          default {  } if root?
          ^

Even the most simple use case is not compiling.

Update: On Mac OS X El Capitan, Crystal 0.18.7

Hello @gottlike, can you show me the basic use case you are trying out? It's working fine for me, so I'll need more information to see what may be happening. Also, can you tell me which Crystal version you are running? Thanks!

Update: Nevermind about the version, I just saw your edit :-)
Update 2: I still need your example, as I'm running the exact same versions (OS X 10.11.5, Crystal 0.18.7)

Hi Soveran, sure. This very simple example is failing for me:

require "toro"

class App < Toro::Router
  def routes
    on "test" do
      text "test"
    end
  end
end

App.run

If you run that example (let's say it's called foo.cr and you try crystal run foo.cr), what error do you get? I just tried it and it works.

Oops.. never mind. I did a crystal init after playing around a bit at first and was modifying the wrong file all the time. Toro examples all work as intended, sorry!

I was/am trying to get https://github.com/jeromegn/slang to work with Toro, but am not successful so far.

Update: And now I got it working with Slang, too :)

OK! I haven't tried to integrate Slang, but by looking at the docs it seems like the way to do it would be to define a method that builds the string without Kilt (https://github.com/jeromegn/slang#without-kilt). Do you want me to give it a try to see if I can build an example?

Thanks a lot for your offer! 👍
However, I got it working now:

class App < Toro::Router
  def routes
    root do
      header "Content-Type", "text/html"
      write Kilt.render("src/index.slang")
    end
  end
end

Excellent :-)

You can also create a method slang to abstract that.

Hmm.. actually it seems that it's not that easy (for a Crystal noob). I tried doing something like this:

class App < Toro::Router
  def slang (template : String)
    Kilt.render("src/#{template}.slang")
  end

  def routes
    root do
      header "Content-Type", "text/html"
      write slang("index")
    end
  end
end

But I'm getting errors, because Kilt.render is a macro, I guess:

  1.     String.build do |__kilt_io__|
  2.       Kilt.embed("src/#{template}.slang", "__kilt_io__", )
  3.     end
  4.

      Kilt.embed("src/#{template}.slang", "__kilt_io__", )
                 ^

undefined macro method 'StringInterpolation#split'

I can't even use a variable there.. is it just not possible, or am I doing it wrong?

commented

@gottlike, maybe you can try https://github.com/f/temel. It's easier to integrate with toro and more flexible if you're building component based interfaces. I'm working on a new framework that should be extracted after a big deployment we have this month. The framework mounts over Toro and have full integration with Temel, Turbolinks, webpack, stylus css and babel, jwt sessions, respond to format, etc.

commented

Maybe try this:

NewToro.cr

class Toro::Router
  def slang (template : String)
    header "Content-Type", "text/html"
    write Kilt.render(template)
  end
end

Usage

def routes
    root do
      slang("src/index")
    end
end

@RayDF, thx for your suggestions. Unfortunately the code you posted throws the same errors. I'll have a look at temel instead. Are you going to open-source your framework? In case you do: Looking forward to it :)

@RayDF Great tips, and I also look forward to your framework!

commented

Hello @soveran, @gottlike :

Just for a sneak peek you could go to this repo:

https://github.com/raydf/warp-example

Working already:

  • Session handler.
  • Controller handler based on Toro Router.
  • A new view engine forked from temel. I liked more this block based templating and composition with crystal modules. The template engine use a super fast String Builder for components instantiating and rendering.
  • Webpack integration with a default watch config, including stylus, turbolinks and another little assets.
  • Hot reloading of http server on crystal code changes.

raydf

@RayDF That's excellent, great work!

@RayDF: Looking good! 👍