jjn1056 / Template-Pure

Logic-less, markup driven HTML templates inspired by pure.js
2 stars 2 forks source link

Support 'deferred' directives #3

Open jjn1056 opened 8 years ago

jjn1056 commented 8 years ago

In the Catalyst view prototype (https://github.com/jjn1056/RangersCCG/blob/master/lib/Catalyst/View/Pure.pm) we allowed that directives could be a code ref instead of an array ref, so that you could generate the directives dynamically at render time based on dependencies and logic that is pre cooked. It feel like a nice feature that belongs in core, would work like

my $pure = Template::Pure->new(
  template=> $template,
  directives=> sub {
    my ($pure, @args) = @_;
    # directives
  });

and then invoke like:

$pure->render($data, \@extra_directives, @args)

so allows you to parameterize render a bit.

Things I don't love is positional params in this case, since @extra_directives needs to be undef if you don't need them. Also I sometimes find making things polymorphic like that can lead to confusion down the road. Ideally a deferred directives would be required to declare explicitly its required interface as well. In theory you can do this with something like a Type::Tiny Tuple...

jjn1056 commented 8 years ago

I'm still wondering about this... because it prevents us from optimizing the directives once at instance creation time (and any possible hope of exposing a reflections API) and also I hate to have two ways to do the same thing (one can defer the values of directives via the data that gets passed at render.

jjn1056 commented 8 years ago

Now that you can stick template includes in via $self or $data this is a lot less needed. Putting this one on hold while I ponder what the nicest interface is.

jjn1056 commented 8 years ago

I'm going to leave this on the table for now but I don't think we need it