vibed: how to use pure HTML instead of template engine?

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 8 03:49:28 PDT 2015


On Friday, 8 May 2015 at 10:20:35 UTC, Rikki Cattermole wrote:
> On 8/05/2015 10:17 p.m., Chris wrote:
>> On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote:
>>>
>>> On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
>>>> 1. Do I need write "./public/" ? In examples often simply 
>>>> "public/"
>>> will work too. even "public"
>>> it goes trough Path struct, see:
>>> https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/path.d
>>>
>>>
>>>
>>>> 2. What incoming parameters ("HTTPServerRequest req,
>>>> HTTPServerResponse res") mean? Why I should to specify them?
>>>
>>> HTTPServerRequest contains all data that the client sends, 
>>> e.g.
>>> headers, cookies, source ip etc.
>>> see:
>>> https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L584
>>>
>>>
>>> HTTPServerResponse is the response you send back.
>>> https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L788
>>>
>>>
>>> you woud want to set at least its body, as you do below
>>>
>>>> 3. Why code with: "res.writeBody("Hello, World!", 
>>>> "text/plain");"
>>>> and "router.get("*", serveStaticFiles("./public/"));" also 
>>>> work, but
>>>> my variant (see code above) do not load say that page not 
>>>> found?
>>>
>>> what exactely does not work? please link code (ideally
>>> https://gist.github.com/ )
>>>
>>>> 4. How to specify page that I need to load, why in examples 
>>>> there is
>>>> only link to folder like public? But what if I want to load
>>>> public/foo.html?
>>>
>>> public servers public files, its more or less a static 
>>> webserver which
>>> checks if a file exists and then serves that.
>>>
>>> if you want to dynamically modify content you send you need 
>>> to use the
>>> templating or do your own string magic.
>>>
>>>
>>> generally it seems you do not fully understand the concept of 
>>> how
>>> these web frameworks work. i think you should either read 
>>> vibe.d's
>>> source code or more read how other such frameworks work e.g.
>>> http://www.sinatrarb.com/documentation.html has pretty good
>>> documentations and books that explain the inner workings (but 
>>> mind,
>>> ruby is a dynamically typed language).
>>>
>>> then i also can recommend that you check out vibe.d's github
>>> repositories and read trough all the example projects that 
>>> come with
>>> it. e.g.
>>> https://github.com/rejectedsoftware/vibe.d/tree/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton
>>>
>>
>> I'd say it is a bit hard to get into vibe.d just like that. I 
>> had to
>> work out a lot of things myself simply because it's web server
>> technology cast in D. Most of the difficulties are not D but
>> understanding the whole web server thing. But I have to say 
>> vibe.d is
>> very very good once you know your way around. Maybe we should 
>> set up
>> some tutorials with common tasks so developers can concentrate 
>> on D
>> instead of the web.
>
> I was thinking maybe a vibe.d manual using leanpub's systems. 
> Assuming it was hosted on Github and set to be free. It would 
> work out rather well and because you can embed other files into 
> the book, examples can be made kinda like they are now in 
> vibe.d's repo runnable. But also contained in the manual 
> inline. All syntax highlighted and all.

Yeah, I think we need a dedicated page with tutorials (covering 
most use cases) for vibe.d. It's great, I love it, but nobody 
knows about it and it's hard to use. You have to go through all 
the examples/source code to do simple things - and things keep 
changing.

Maybe even powerful vibe.d boilerplate projects you can set up 
with dub, e.g. a project that already contains `serveStaticFiles` 
and stuff like that.

dub init myproject vibe.d --server=[minimal | query | noui]

Stuff like that. Maybe with DlangIDE support.

And stubs with explanations, e.g. "How do I handle queries?" 
(req.query) etc. A one stop shop for vibe.d. I'd hate to see it 
ignored only because it's not accessible. Maybe it's time to 
bundle things up anyway. dub/dvm/dlangIDE/dlangUI/vibe.d. It's 
right there in front of us and we all speak the same language :-)


More information about the Digitalmars-d-learn mailing list