00:59 Pe_Elle left 01:07 Pe_Elle joined 01:42 librasteve_ left 02:06 Pe_Elle left, Pe_Elle joined 09:02 Pe_Elle left 09:03 Pe_Elle joined, Pe_Elle left, Pe_Elle joined 09:40 sena_kun joined 10:13 Pe_Elle left 10:17 Pe_Elle joined 10:22 Pe_Elle left 10:31 Pe_Elle joined
SmokeMachine Is there a way (or any plan to make it possible) to have inline cro template on the route raku code? I think having something like that would make components easier… 11:18
librasteve does evaluate here github.com/librasteve/raku-Cro-WebApp-Evaluate do what you mean? 12:09
oh no - that's different, sorry ... keeps rootling around... 12:10
here's what I had in mind ... github.com/librasteve/raku-HTMX-Ex...it.rakumod ... ie the hydrate function (NB this is on the steve-02-fn branch) 12:17
ok - now I look at that I see that this pattern is not to have the template inline (since I am using my HTML::Functional module (which maybe does similar to your HTML::Component s) 12:19
the Cro Templates are generally placed in a template location - which is called a Repository in the code and then they are pre-rendered on server start to speed things up... 12:20
sooo - the way I suggest you do this is to ape the cro-webapp test pattern... github.com/croservices/cro-webapp/...c.rakutest ... 12:26
my constant $base = $*PROGRAM.parent.add('test-data'); #vvv so you need to spurt your template to a file, then call render-template on it is render-template($base.add('literal.crotmp'), {}), q:to/EXPECTED/, 'Literal text passed through'; <div> <strong>Hello, I'm a template!</strong> </div> EXPECTED 12:31
Obviously writing / reading to/from a file is suboptimal ... so this does beg having an interface that will take the actual template as a Str (and not just the file name), but that will bypass a lot of assumptions about what is there in the active repo (for example the compilation process sticks all the subs, macros and so on in a bit list of callables for the repo. And I guess we would want such an approach to be 12:38
general enough to support all the crotmp features so in that case, the callables are going to expect that after your new template is installed and compiled then all those items in the namespace are resident in the cache.
keeps digging...
oh - look what I just found 12:40
github.com/croservices/cro-webapp/...e.rakutest
so looks like Cro::WebApp already does that... 12:41
use Cro::WebApp::Template::Repository; parse-template('<.foo>, <.bar>').render({ foo => 'hello', bar => 'world', }); 12:42
.oO 12:43
but nothing is exported in Routes.rakumod to expose that - seems like this would be pretty easy to fix 12:44
one caveat is that this will add your new template to the repository - so it will cache is for faster speed, but this is not going to work for dynamical templates in that it cannot be deleted or updated (not sure what happens if you try this twice with eg the same sub name - that will likely error with a duplicate sub name) 12:47
SmokeMachine: sorry for the mystery tour - but I reckon I can do a PR to add this to the use Cro::WebApp::Template; code, how about this for syntax: 12:54
route { get -> { template-inline '<.foo>, <.bar>', { foo => 'hello', bar => 'world', }; } } 12:56
??
13:59 Pe_Elle left 14:01 Pe_Elle joined 14:07 Pe_Elle left
SmokeMachine librasteve: that looks great! Is there a way to use that template inside another template? (I know I’m asking too much… sorry for that) 14:11
14:20 Pe_Elle joined
librasteve let me check 14:33
15:22 Pe_Elle left
ok --- the test above works ^^^ 15:36
but this
route { get -> { template-inline '<.foo>, <.bar>, <:sub fn()>Inner Content</:>, <a href="/template_inline/call_sub">Call Me</a>', { foo => 'hello', bar => 'world', }; } get -> 'call_sub' { warn "ho:"; $*ERR.flush; template-inline 'Outer <&fn()> Content', {}; } }
gets an error Undeclared name: ⚠ examples __TEMPLATE_SUB__fn used at line 1
when you click the link
so the sub defined in the first call is not available on subsequent calls - which actually in my ,ind is best because there is no guarantee on which order routes will be called in, right? 15:37
this might work if you have a template repository defined ... but I guess that in general template-inline should work in the absence of a library ... 15:39
... in the spirit of _jnthn_s docs - if you are in raku code anyway, then just make crotmp $vars and compose them as you need on the server side 15:40
Geth cro-webapp: librasteve++ created pull request #95:
add template-inline
15:50
15:54 Pe_Elle joined
librasteve ok I have made a PR - meantime you can test drive via zef install github.com/librasteve/cro-webapp.git from my fork 16:01
PS. I have been wondering how to do this for my variants on HTML Components so hopefully this will server both our needs. Please do try using it and see if it does what you need - perhaps for a set of components to be precompiled and cached it may make more sense to write them as files as outlined above a couple of hours back. So all components could be asked to register when they are first used...? 16:12
17:00 Pe_Elle left 17:38 Pe_Elle joined 18:42 Pe_Elle left 19:11 Pe_Elle joined 20:15 Pe_Elle left 20:29 Pe_Elle joined 20:34 Pe_Elle left 21:02 Pe_Elle joined 21:07 Pe_Elle left 21:22 Pe_Elle joined 22:44 Pe_Elle left 22:58 sena_kun left 23:26 Pe_Elle joined 23:31 Pe_Elle left 23:55 Pe_Elle joined