Commit 1f8edc32 authored by totten's avatar totten
Browse files

Generate partials via callback

Technically, it's two changes:

1. Changing `snippets` to `partialsCallback` to reduce the amount of upfront IO/memory.
2. Changing the mocked-up filename to start with `~/theAngModule/`. So modules implemented in
   afform look more look other modules. Makes it work with `cv ang:html:list` and `cv ang:html:show`.
parent d3f4ea69
......@@ -165,15 +165,13 @@ function afform_civicrm_angularModules(&$angularModules) {
$names = array_keys($scanner->findFilePaths());
foreach ($names as $name) {
$meta = $scanner->getMeta($name);
$layout = $scanner->getLayout($name);
$angularModules[_afform_angular_module_name($name, 'camel')] = [
'ext' => E::LONG_NAME,
'js' => ['assetBuilder://afform.js?name=' . urlencode($name)],
'requires' => $meta['requires'],
'basePages' => [],
'snippets' => [
"~/afform/$name.aff.html" => $layout,
],
'partialsCallback' => '_afform_get_partials',
'_afform' => $name,
'exports' => [
_afform_angular_module_name($name, 'dash') => 'AE',
],
......@@ -181,6 +179,24 @@ function afform_civicrm_angularModules(&$angularModules) {
}
}
/**
* Construct a list of partials for a given afform/angular module.
*
* @param string $moduleName
* The module name.
* @param array $module
* The module definition.
* @return array
* Array(string $filename => string $html).
*/
function _afform_get_partials($moduleName, $module) {
/** @var CRM_Afform_AfformScanner $scanner */
$scanner = Civi::service('afform_scanner');
return [
"~/$moduleName/$moduleName.aff.html" => $scanner->getLayout($module['_afform']),
];
}
/**
* Scan the list of Angular modules and inject automatic-requirements.
*
......@@ -406,13 +422,14 @@ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
/** @var \CRM_Afform_AfformScanner $scanner */
$scanner = Civi::service('afform_scanner');
$meta = $scanner->getMeta($name);
$moduleName = _afform_angular_module_name($name, 'camel');
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('afform', [
'camel' => _afform_angular_module_name($name, 'camel'),
'camel' => $moduleName,
'meta' => $meta,
'metaJson' => json_encode($meta),
'templateUrl' => "~/afform/$name.aff.html",
'templateUrl' => "~/$moduleName/$moduleName.aff.html",
]);
$mimeType = 'text/javascript';
$content = $smarty->fetch('afform/AfformAngularModule.tpl');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment