got rid of id_override

This commit is contained in:
udo committed 2020-08-08 11:12:08 +02:00
1 parent 47191b5f2e
commit bf2b3d930c
3 files changed
+14 -20

No files matched your search

+1 -7
View File
@@ -51,7 +51,7 @@ This uses the idea of immediate components to render HTML. For example, a given
<body>
<?= component('nav/shortcut-bar') ?>
<?= component('nav/menu', 'menu') ?>
<?= component('nav/content', 'content') ?>
<?= component('nav/content', array('id' => 'content')) ?>
</body>
</html><? });
```
@@ -67,12 +67,6 @@ component($file_name, $id_override = false, $prop = array())
If the file returns a lambda function, that function gets called every time the component is invoked. If the
file returns a text, that text gets returned every time the component is invoked.
`$id_override` is an optional parameter intended to override the component's HTML element id.
As a rule, components should encapsulate themselves with an outer HTML element, like this:
`<div <?= ap($prop) ?> class="menu-bar">...</div>`. The call to `ap($prop)` generates an `id`
attribute automatically. The value of this `id` can be explicitly set by using the `$id_override`
parameter. This is useful when the elements later needs to be reloaded or regenerated dynamically.
`$prop` is an optional parameter to communicate further parameters to the component, and this
corresponds to the `$prop` parameter being passed to a component's lambda function.
+2 -2
View File
@@ -7,9 +7,9 @@
URL::MakeRoute();
ob_start();
print(component(first(URL::$route['l-path'], 'index'), $_REQUEST['attr']['id']));
print(component(first(URL::$route['l-path'], 'index'), array($prop['id'] => $_REQUEST['attr']['id'])));
$content = ob_get_clean();
include(cfg('theme/path').'/page.'.URL::$route['content-type'].'.php');
Log::audit('page:'.URL::$route['page'], URL::$route['l-path']);
Log::audit('page:'.URL::$route['page'], URL::$route['l-path']);
+11 -11
View File
@@ -50,10 +50,10 @@
}
}
function component_path($file_name, $id_override = false, $prop = array(), $opt = array())
function component_path($file_name, $prop = array(), $opt = array())
{
$f = Renderer::get_func($file_name, true);
if($f) return(component($file_name, $id_override, $prop, $opt));
if($f) return(component($file_name, $prop, $opt));
$fpath = array();
$seg = explode('/', $file_name);
array_unshift($seg, '');
@@ -83,26 +83,26 @@
}
}
function component_open($file_name, $id_override = false, $prop = array(), $opt = array())
function component_open($file_name, $prop = array(), $opt = array())
{
$prop['open'] = true;
return(component($file_name, $id_override, $prop, $opt));
return(component($file_name, $prop, $opt));
}
function component_close($file_name, $id_override = false, $prop = array(), $opt = array())
function component_close($file_name, $prop = array(), $opt = array())
{
$prop['close'] = true;
return(component($file_name, $id_override, $prop, $opt));
return(component($file_name, $prop, $opt));
}
function component_open_close($file_name, $id_override = false, $prop = array(), $opt = array())
function component_open_close($file_name, $prop = array(), $opt = array())
{
$prop['open'] = true;
$prop['close'] = true;
return(component($file_name, $id_override, $prop, $opt));
return(component($file_name, $prop, $opt));
}
function component($file_name, $id_override = false, $prop = array(), $opt = array())
function component($file_name, $prop = array(), $opt = array())
{
if($file_name == '')
{
@@ -110,7 +110,7 @@
return(error_banner('Component not found: '.htmlspecialchars($file_name)));
}
$f = Renderer::get_func($file_name);
$prop['id'] = $id_override ? $id_override : 'c'.(Renderer::$id_counter++);
$prop['id'] = $prop['id'] ? $prop['id'] : 'c'.(Renderer::$id_counter++);
$prop['filename'] = $file_name;
Renderer::$call_stack[] = &$prop;
$result = $f($prop, $opt);
@@ -132,4 +132,4 @@
function banner($s)
{
print('<div class="banner">'.$s.'</div>');
}
}