-
Notifications
You must be signed in to change notification settings - Fork 61
Updated templatemap_generator to remove dep on zend-console #67
Updated templatemap_generator to remove dep on zend-console #67
Conversation
…ap-generator Added template map generator as bin script
Usage: templatemap_generator.php [-h|--help] templatepath files... --help|-h Print this usage message. templatepath Path to templates relative to current working path; used to identify what to strip from template names. files... List of files to include in the template map, relative to the current working path. The script assumes that paths included in the template map are relative to the current working directory. The script will output a PHP script that will return the template map on successful completion. You may save this to a file using standard piping operators; use ">" to write to/ovewrite a file, ">>" to append to a file (which may have unexpected and/or intended results; you will need to edit the file after generation to ensure it contains valid PHP). We recommend you then include the generated file within your module configuration: 'template_map' => include __DIR__ . '/template_map.config.php', Examples: # Create a template_map.config.php file in the Application module's # config directory, relative to the view directory, and only containing # .phtml files; overwrite any existing files: $ cd module/Application/config/ $ ../../../vendor/bin/templatemap_generator.php ../view/**/*.phtml > template_map.config.php
@RalfEggert pinging for your review, as you started this whole thing. 😄 Does the use case as demonstrated above capture what you would most likely need? |
Sorry, guys, do we definitely need it? What is the advantage of this script over the @Ocramius library Let me quote @Ocramius:
@Ocramius Could you just update your library to support also PHP 5.6? Is there any problem with it? |
@webimpress As you've already noted, OcraCachedViewResolver currently requires PHP 7 (though you can install the v3 versions if you need 5.5 or 5.6 support); additionally, it requires usage of zend-cache, which adds a number of extra dependencies beyond what we require by default in zend-mvc, and which then requires setting up a cache storage backend. The approach of |
@weierophinney thanks for explanations. It makes sense. It would be nice to have both approaches described in documentation so developers could decide what they want use. Obviously |
? $matches['template'] | ||
: $template; | ||
|
||
$template = str_replace('\\', '/', $template); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that line redundant (because of line 86)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, thanks for the catch!
- Update example for help message to reflect actual arguments - Remove redundant line
- Needs a leading slash within the quotes
Distinct: - if first argument is not a path - if no files provided
I've incorporated your feedback; thanks, @webimpress ! |
@weierophinney thanks for fixes, but still I have the same results:
Maybe it will help:
Do you think it could be system dependent? I'm using OS X but the same results I've got on Windows. |
@weierophinney please update also docs above in PR description, these still is wrong: Do we definitely need the 2nd and 3rd parameter? Maybe will be enough if we pass only path to the view directory and generate templates map of all files in this directory (and subdirectories)? Now it looks a bit redundant. I know it gives us bigger capacities of use, but I wonder how important it is. Previous script has much more parameters, and you've already removed some. Thoughts? |
Yes - just got everything setup on my Windows VM to test, and can confirm. I suspect it's a difference in globbing support; I've been testing on zsh, but I know that in Windows, where I run Cygwin, I've got bash, which is also the default shell on Mac. If so, it's just a matter of documentation. |
Done. |
Yeah, but if we would like generate templates map for whole directory (with all subdirectories) it will be complicated, so maybe better as I've suggested above to pass only path to the |
What I tried to do for this iteration of the script is follow the Unix philosophy, along with poka-yoke principles. The idea is to keep usage to a specific pattern; if you go outside that, you need to use another tool or manually create the map. Part of this was due to wanting to remove dependencies; I see no reason why zend-view should require zend-console, particularly if it's only for this script. The other part is because the previous version had a ton of execution paths, and I'm positive not all of them were tested. Reducing the use cases helps keep it focused and ensure it works correctly.
I discovered two ways to make this work in bash. First, and most portable across all shells, replace Second, Bash 4 introduced a shopt -s globstar This can be done in either your bash profile, or on the command line. Once enabled, the I'll update the help doc to indicate these various forms. |
@weierophinney one more suggestion: maybe the 3rd parameter shouldn't be mandatory, so it will be possible generate templates map for all files in provided view |
This would require adding a flag to indicate what view script extension to use. Using globbing means we don't need to add that flag, or assume Let me think about it for a bit; I definitely see your point, and we could assume that if no files are given, |
…iles Simplifies usage for the default use case. If developers want to specify an alternate extension, they can use file globbing.
@webimpress — just pushed a commit that allows the following: $ templatemap_generator.php ../view > template_map.config.php This uses a leaves-only recursive directory search to find all |
Sorry for the delay. I only find time now to look at this. Looks really great. I just notices one little issue so far. I used the template map generator for a Zend Skeleton Application project like mentioned in the docs:
That created this file:
When I use this
I get that file:
I guess this is because of the extra directory level for the |
@RalfEggert please read PR description or help of the script - @weierophinney described two approaches to resolve that issue |
@webimpress Well, to be honest, I only looked in the examples of the inline docs of that file. And that caused the missunderstanding. Maybe needs to be updated? |
@RalfEggert yeah, I had the same feelings, so I've asked @weierophinney to change files list to be not mandatory parameter... Please have a look on @weierophinney comment: #67 (comment) |
👍 |
This patch builds on #65, incorporating the feedback I provided via a comment on the original ZendSkeletonApplication issue that began the change.
Essentially, I want to avoid adding zend-console as a dependency of zend-view.
What this patch does is remove the usage of
Zend\Console\Getopt
, and simplifies the usage to a single, narrow use case:cd module/ModuleName/config && ../../../vendor/bin/templatemap_generator.php ../view ../view/**/*.phtml > template_map.config.php
. This command will create the filemodule/ModuleName/config/template_map.config.php
, which will map templates to.phtml
view scripts located inmodule/ModuleName/view/
. Users would then define the template map entry inmodule.config.php
as follows:This allows regeneration of the template map on-demand using the same command, without requiring parsing and updating the main module configuration file.
I believe this is the 80% use case, and developers can build out their own solutions for anything needing more customization.
Full usage is: