Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide HTML web interface #8

Open
alcinnz opened this issue Jan 8, 2023 · 6 comments
Open

Provide HTML web interface #8

alcinnz opened this issue Jan 8, 2023 · 6 comments

Comments

@alcinnz
Copy link

alcinnz commented Jan 8, 2023

It'd be nice to be able to view the packages available on this service via a web browser! I certainly like doing so with the equivalent tools for other languages.

Also, I'm curious what you'd design here?

@alcinnz
Copy link
Author

alcinnz commented Jan 8, 2023

Mostly I just opened this issue to share some code you expressed interest in during the Vala meetup. I've now successfully extracted it from my defunct project and put it in its own GitHub repository: https://github.com/alcinnz/Prosody

Its not packaged very well, but I do have it building a library & demoscript which sucessfully passes its testsuite. Also: I'll be happy to transfer repository ownership over to you if you want it!

This templating language is heavily inspired by Django's and includes several useful features:

  • Autoescaping common webformats
  • Internationalization (custom tooling, integrating Gettext was a struggle atleast at the time I wrote this)
  • XML, JSON, & TSV input integration
  • Silent failures
  • Cached GIO Resources integration (bundle your templates in your executable)
  • Extensible syntax
  • Infix expressions for conditions

All written in pure Vala! Would this be useful?

@aleksrutins
Copy link
Owner

Yep! I've started to try to integrate it, but I can't seem to figure out how to render a template to a response. Here's my current attempt:

valapkg/server/main.vala

Lines 66 to 72 in fdff1f1

Prosody.ErrorData error_data = null;
var release_list = API.all_releases().map<Prosody.Data.Data>((release) => release.to_data());
var list_data = new Prosody.Data.List(iterator_to_list(release_list));
var map = new Gee.HashMap<Slice, Prosody.Data.Data>();
map.set(new Slice.s("releases"), list_data);
render_template(msg, "templates/index.html", new Prosody.Data.Mapping(map), ref error_data);
return;

However, it doesn't work:

ERROR:streamiterator.c:557:gee_stream_iterator_real_get: assertion failed: (_current != null)
Bail out! ERROR:streamiterator.c:557:gee_stream_iterator_real_get: assertion failed: (_current != null)
Aborted

What am I doing wrong?

@aleksrutins
Copy link
Owner

Oh gosh, sorry, I already extracted it: https://github.com/aleksrutins/Prosody

@alcinnz
Copy link
Author

alcinnz commented Jan 29, 2023

Yes, I noticed I had something lacking there as I did my own extraction.

The story is I was rendering directly into WebKitGTK, so I needed something a bit more convoluted to write into an OutputStream rather than an InputStream. I fixed that in my extraction work.

P.S. I find a bit more code to extract sometime, and I'm tempted to try implementing template inheritance again akin to Django.

@alcinnz
Copy link
Author

alcinnz commented Jan 29, 2023

But at first glance, looking at your code, it looks fine!

@aleksrutins
Copy link
Owner

I actually figured it out finally a couple of hours ago, when I realized looking at your example that I can pass data as JSON. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants