mudrd8mz / moodle-tool_pluginskel

Generator of Moodle plugins skeletons
https://moodle.org/plugins/tool_pluginskel
Other
51 stars 46 forks source link

Boilerplate_php.mustache path_to_config #28

Closed alexandru-elisei closed 8 years ago

alexandru-elisei commented 8 years ago

In classes/local/util/manager.php, at line 193: $data['self']['pathtoconfig'] = "__DIR__.'/".str_repeat('../', substr_count($data['self']['relpath'], '/') - 1)."config.php'";

In skel/common/boilerplate_php.mustache, at line 46: {{^ is_moodle_internal }}require({{$ path_to_config }}__DIR__.'/../../config.php'{{/ path_to_config}});{{/ is_moodle_internal }} You're using two different names for path to config.

Waiting the result of #19 to propose a fix.

alexandru-elisei commented 8 years ago

I understand what you are doing. You are expecting that each template that requires the config.php file to overwrite the path_to_config block like this: {{$ path_to_config }}{{{ self.pathtoconfig }}}{{/ path_to_config }}

I find this cumbersome. The path to the config.php file is generated for each file in the function manager::prepare_file_skeleton(), why not include it directly?

mudrd8mz commented 8 years ago

I think I tried to do it directly. But it did not work for me, given how blocks work in Mustache (https://github.com/bobthecow/mustache.php/wiki/BLOCKS-pragma). If you find a way how to nicely inject variables values into the block without this assignment-in-the-middle, I'll be happy to be taught.

alexandru-elisei commented 8 years ago

It worked for me. I simply used the self.pathtoconfig variable.

mudrd8mz commented 8 years ago

Hmm, interesting. So I guess we can remove path_to_config computation completely from all the templates that use the boilerplate?

mudrd8mz commented 8 years ago

And also use it in the {{# is_cli_file }} section, I suppose.

alexandru-elisei commented 8 years ago

I've tested it by using php_cli_file skel class for one the features, it generates the path to config.php correctly.