I added a very basic test to the test suite for the intended working of a fix for #290.

Issue #290:
https://github.com/habari/habari/issues/290

The added test:
http://asym.us/VeyBrM

There is a branch for the solution in-progress, and a branch for the new test in the suite.

The basic idea is to have this new class, StackItem, represent a thing that can be added to a Stack. You would register new StackItems with Habari when you had some standard, named library that you wanted to make common use of. A StackItem can optionally be registered with a version number, which would help satisfy specific version requirements. Plugins and themes could register new StackItems or override existing ones (to make use of CDN-hosted or compressed versions, or what-have-you).

Habari itself would register a named StackItem for each vendor script that it provides. Instead of providing the full URL of a script (CSS would work similarly) to Stack::add(), you would use StackItem::get() to return a registered StackItem object with a specific name (and possibly version) to be added to the Stack. For example:

Stack::add( 'test_stack', StackItem::get('jquery') );

A StackItem will already have been assigned a name and dependencies when it is registered, so there is no need to include those in the call to Stack::add(). Current code that passes a string or array as an item to Stack::add() as the $value parameter will simply be registered as a new StackItem at that time, and added to the stack.

New functionality could also allow lambdas to be passed as the $value parameter in Stack::add() or the $resource parameter to StackItem::register(). These lambdas would be called when the stack is built, and their return values would be used in the stack. This would make it possible to define StackItems that have conditions, so that you would always add them to the stack using the simple Stack::add() call above, but they would only appear in output or contain different output based on internal criteria checked at runtime.

I know that one thing that seemed ideal was to target a specific directory to register all of the scripts in it as StackItems. For example, StackItem::register_dir($path) could glob() the whole $path and register each file there as a StackItem under its filename. This would make StackItem registration pretty simple, and similar to the use of the assets directory in themes. Yet, I'm not sure how or if this would accumulate version numbers on those resources.

Some thoughts as to the workings of this would be appreciated, as I am in the middle of implementation and don't want it to fail to address the issues presented.

Owen

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/habari-dev

Reply via email to