|
@@ -5,7 +5,7 @@
|
|
|
use Juju\Data\{Response, Template};
|
|
|
|
|
|
abstract class View {
|
|
|
- private static $name;
|
|
|
+ protected static $name;
|
|
|
protected static $template;
|
|
|
public static function views() : array{
|
|
|
return array_filter(get_declared_classes(), function($class){
|
|
@@ -24,18 +24,32 @@
|
|
|
'view'=>get_called_class()
|
|
|
];
|
|
|
}
|
|
|
- final public static function render(array $data = []) : string{
|
|
|
+ final public static function template(){
|
|
|
if(is_null(static::$template) && method_exists(get_called_class(), 'setup')){
|
|
|
static::setup();
|
|
|
}
|
|
|
$template = static::$template ?? static::name();
|
|
|
- $data = array_merge(static::data(),$data);
|
|
|
if(is_string($template)){
|
|
|
- return Template::from($template, $data);
|
|
|
+ $template = Template::get($template);
|
|
|
}elseif(is_array($template)){
|
|
|
- $template = new Template($template['name'], $template['fn']);
|
|
|
+ $template = new Template($template['name'], $template['fn']);
|
|
|
+ }
|
|
|
+ return $template;
|
|
|
+ }
|
|
|
+ final public static function render(array $data = []) : string{
|
|
|
+ $data = array_merge(static::data(), $data);
|
|
|
+ return static::template()->run($data);
|
|
|
+ }
|
|
|
+ final public static function cache(){
|
|
|
+ foreach(self::views() as $view){
|
|
|
+ if(method_exists($view, 'setup')){
|
|
|
+ $view::setup();
|
|
|
+ }
|
|
|
+ $template = $view::template();
|
|
|
+ if(!is_null($template)){
|
|
|
+ $template->to_file();
|
|
|
+ }
|
|
|
}
|
|
|
- return $template->run($data);
|
|
|
}
|
|
|
}
|
|
|
?>
|