Added template map generator #3106

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Member

Hounddog commented Nov 29, 2012

I have basically copied the classmap generator for this. Need to still clean it up but wanted to know if it was something required. I just think that if you have many templates it is tedious to write a template map manually for every template... Same as writing a classmap.

Module Config example

'view_manager' => array(
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
        'template_map' => include __DIR__  . '../template_map.php',
),

To generate a classmap you can then just call php templatemap_generator.php from the root of your module and by default it would map all the templates within view.

I have also added the option to specify where the views are so you can also provide the library path aswell as the view path to generate the template map.

php templatemap_generator.php --view viewpath --librarypath modulepath

@weierophinney weierophinney added a commit that referenced this pull request Dec 11, 2012

@weierophinney weierophinney [#3106] Cleanup
- Was raising an exception of "view" directory did not exist; modified
  to show error message + usage message
- Removed import for ClassFileLocator
- Changed references from "classmap" to simply "map"
- Changed references from "autoload" to "map"
bed4469
Contributor

ThaDafinser commented Jul 8, 2013

@Hounddog shouldn't the "view" perfix be left away? Or is that intended?

Example:

<?php
// Generated by ZF2's ./bin/templatemap_generator.php
return array(
    'view/error/404'   => __DIR__ . '/view/error/404.phtml',
    'view/error/index' => __DIR__ . '/view/error/index.phtml',
);

Until yet i always used "error/404" and not "view/error/404" and i think the first one is more "common".
Maybe for BC compability just a parameter to include the "view" perfix or not?

If that's fine for you, maybe i can take also a look into it...shouldn't be much work.

Contributor

ThaDafinser commented Jul 8, 2013

@Hounddog it's really easy (see gist: https://gist.github.com/ThaDafinser/5949020)

Would it be okay for you? And suggestion for the parameter?

Modifications:

$rules = array(
    'help|h'      => 'Get usage message',
    'library|l-s' => 'Library to parse; if none provided, assumes current directory',
    'view|v-s'    => 'View path to parse; if none provided, assumes view as template directory',
    'useViewPath' => 'Use the view path to overwrite the key path mapping (instead of library path)',
    'output|o-s'  => 'Where to write map file; if not provided, assumes "template_map.php" in library directory',
    'append|a'    => 'Append to map file if it exists',
    'overwrite|w' => 'Whether or not to overwrite existing map file',
);

///.....after if (isset($opts->v)) { block

$replacePath = $libraryPath;
if(isset($opts->useViewPath)){
    $replacePath = $viewPath;
},

//more down
$map = new stdClass;
foreach ($l as $file) {
    if (!$file->isFile()) {
        continue;
    }
    $filename  = str_replace($replacePath . '/', '', str_replace(DIRECTORY_SEPARATOR, '/', $file->getPath()) . '/' . $file->getFilename());


//...
Member

Hounddog commented Jul 8, 2013

It would be easier if you just created a pull request where we could view the changes :)

Contributor

ThaDafinser commented Jul 8, 2013

Yes you are right....i'm currently at work, so i can't use git....don't ask why :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment