aquametalabs / aquameta

Web development platform built entirely in PostgreSQL
GNU General Public License v3.0
1.1k stars 52 forks source link

endpoint: sub-templates #184

Closed erichanson closed 5 years ago

erichanson commented 5 years ago

Right now templates can only be instantiated through a template_route, and there's no possibility for sub-templates, aka templates (or widgets I suppose?) instantiating another template. Fix that.

  1. Create database procedure endpoint.bundled_template(bundle_name text, template_name text) which returns a un-rendered template, looked up by bundle name + name.
  2. Create database procedure endpoint.template_render(bundle_name text, template_name text, args json) in language plv8 that grabs the template, renders it using supplied args, and returns its rendered string.
  3. Since templates can call other templates, implement a Javascript function template(bundle_name, template_name, args) which kicks off to the database procedure in 1 via plv8. This function needs to be in plv8's scope. Which means we have to figure out how to do that. Right now template_render just one-off pulls in the required Javascript functions per-call, which is awful. Need a pattern here.
erichanson commented 5 years ago

I made #185 for figuring out a general pattern for loading Javascript modules into plv8.