[Flow] TemplateBuilder (a developer's perspective)
Bastian Waidelich
bastian at typo3.org
Thu Aug 8 14:58:53 CEST 2013
Jacob Floyd wrote:
Hi Jacob,
> I've been thinking alot about programmatically modifying fluid
> templates, fluidifying html templates, and template building in general.
> [...]
> I'm not sure on the naming of a few Fluid-specific FlowQueryOperations
> (read: methods in the API), but I want some feedback on the API.
I had a first quick look through your examples and just write down what
comes to my mind (I didn't check the source code yet):
First, I think it's a great idea that you build this on top of an
existing library (QueryPath) and I really like the jQuery-like selector
syntax.
Ok, regarding your examples:
$derivative = new BlobQuery('Cognifire.SweetSitePackage');
It's not clear to me (at first glance) why you have to specify a package
key and what its function is (source/target for templates?)
$derivative->branch()->find('title')->replaceWithFluidViewHelper('base');
What is "branch()" for? (Ah, you explain that below. I'd vote for
removing it if possible)
And why do you replace a <title> tag with the base ViewHelper? (I
probably misinterpreted this!?)
$fluidTemplate = $derivative->branch()->selectBlob($sourceTemplateFilename);
I think you should extract I/O operations from the TemplateBuilder[1]
and instead pass the contents of the source template instead.
$fluidTemplate->addFluidNamespace('neos','TYPO3.Neos')->addFluidLayout('default')
what about "registerFluidNamespace" and "useFluidLayout"?
->replaceWithFluidRenderPartial('author')->first()->writeFluidPartial();
why "first()"? Wouldn't replaceWithFluidRenderPartial() always "point"
to the one created render ViewHelper? And - if not - I'd prefer the
jQuery kind of style to assume "first" if you call a method on a collection.
$derivative->branch()->cloneFromBoilerplate('Cognifire.EmptyBoilerplate:resources/templates/menu/vertical.html')
Again, I'd move I/O out of the package. But apart from that we should
try to avoid introducing new "magic strings". Why wouldn't
"resources://Cognifire.EmptyBoilerplate/Private/Templates/Menu/Vertical.html"
work here?
All in all it already looks quite straightforward to me, but I'm
wondering if you plan to use PHP as interchange format? I'd expect the
TemplateBuilder to spit out some declarative configuration based on YAML
for example.
Also (somewhat unrelated) I'm interested whether you found a way to
create the "best" QueryPath expression for a given DOM node (so that it
returns the shortest and most stable path to a part of the static source
template if you click on it).
[1] By keeping dependencies and responsibilities low you increase
testability and maintainability of a class drastically. In this case for
example by separating file operations from the actual BlobQuery features
by interacting with strings.
--
Bastian Waidelich
--
Core Developer Team
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the Flow
mailing list