haxetink / tink_web

Tinkerbell Web Framework
https://haxetink.github.io/tink_web
43 stars 14 forks source link

routes won't return Promise<Tink.template.Html> as it used to.. #118

Open postite opened 3 years ago

postite commented 3 years ago
 @:get("/")
@:produces("text/html")
public function index(){
    return Promise.NOISE.next(n->
    Home.render() //tink.template 
    );
}

compiles with error. tink.core.Promise should be tink.io.RealSource

workaround :

Home.render().toString() // works fine. 

but it shouldn't behave like this huh ?

kevinresol commented 3 years ago

what haxe version?

postite commented 3 years ago

hello kevin . I run haxe 4.1.4

kevinresol commented 3 years ago

I reckon this is about transitivity. Can you try adding @:transitive to tink.template.Html?

postite commented 3 years ago
@:transitive
(:public static function render():)
<div id="home" class="page">
    <p>oh!</p> 
</div> 
(:end:)

is it where @:transition should be placed ? because it's causing compiler to not compile and stays forever at "building" status . I hate when it does this...

kevinresol commented 3 years ago

it is for the abstract Html

postite commented 3 years ago

ah ! oh !

package tink.template;

import tink.HtmlString;
import tink.htmlstring.HtmlBuffer as Buf;
@:transitive
abstract Html(HtmlString) from HtmlString to HtmlString { ...

I've done this ... but no change ... I don't get what @:transitive does ... so I'm completely lost here :)

kevinresol commented 3 years ago

Anyway, if this problem is particular for tink_web, I suggest you use the @:html metadata instead

@:get("/")
@:html(_ -> Home.render())
public function index(){
    return Promise.NOISE;
}
postite commented 3 years ago

ok nice to know. It doesn't work in my case cause i'm using static extensions ( like : Home.render().withLayout().addAction(Command1).render() ) but i'll go without. btw , your exemple doesn't not render anything. It seems This one does :

@:get("/")
@:html(_ -> views.Home.render()) // full path
public function index(){
    return Promise.NOISE.next(n->{hip:"hop"}); // need a next ! ? 
}

thx for your efforts :) .

kevinresol commented 3 years ago

I think this is a bug because Noise will produce empty http response but I think it should respect the html request.

kevinresol commented 3 years ago

Code pointer for contributors:

https://github.com/haxetink/tink_web/blob/62a26b959cc839403dcdfe2f615afd9ecb35a615/src/tink/web/macros/Routing.hx#L379-L390