_writers[] = $writer; if ( $this->_writing ) { $writer(); } return $this; } public function writes($string) { $this->calls(function() use($string) { echo $string; }); return $this; } public function script($src) { $this->_scripts[] = $src; return $this; } public function stylesheet($src) { $this->_styles[] = $src; return $this; } public function title($title = null) { if ( $title ) { $this->_title = $title; return $this; } else { return $this->_title; } } public function header($string = null) { if ( !$string ) $string = $this->title(); return $this->writes('

' . $string . '

'); } public function form($submit, callable $inner) { $this->writes('
'); $this->calls($inner); $this->writes('
'); return $this; } public function submit($text = 'Submit') { $this->writes(''); } public function div(callable $inner) { $this->writes('
'); $this->calls($inner); $this->writes('
'); return $this; } public function line_break() { $this->writes('
'); return $this; } public function table($nested_array) { if ( is_array($nested_array) ) { $this->calls(function() use($nested_array) { echo ''; foreach ( $nested_array as $row_idx => $row ) { echo ''; foreach ( $row as $col_idx => $col ) { $tag = $row_idx === 0 ? 'th' : 'td'; echo "<{$tag}>{$col}"; } echo ''; } echo '
'; }); } else { $this->writes(''); $this->calls($nested_array); $this->writes('
'); } return $this; } public function table_row_cell(callable $inner, $span = 1) { $this->table_row(function() use($inner, $span) { $this->writes(''); $this->calls($inner); $this->writes(''); }); return $this; } public function table_row($inner = null) { $this->writes(''); if ( $inner ) $this->calls($inner); $this->writes(''); return $this; } public function table_head(callable $inner) { $this->writes(''); $this->calls($inner); $this->writes(''); return $this; } public function table_cell($inner = null) { $this->writes(''); if ( $inner ) $this->calls($inner); $this->writes(''); return $this; } public function fail_to($message, $redirect_url) { $this->writes('

' . $message . '

') ->writes('

Try Again

') ->write(); exit; } public function preamble() { if ( $this->_wrote_pre ) return; $this->_styles[] = system_url('assets/common.css'); $styles = []; foreach ( $this->_styles as $style ) { $styles[] = ''; } ?> <?= $this->_title ?> _wrote_pre = true; } public function postamble() { if ( $this->_wrote_post ) return; $scripts = []; foreach ( $this->_scripts as $script ) { $scripts[] = ''; } ?> _wrote_post = true; } public function write() { $this->_writing = true; $this->preamble(); foreach ( $this->_writers as $writer ) { $writer(); } $this->postamble(); $this->_writing = false; } public function compile() { ob_start(); $this->_wrote_pre = false; $this->_wrote_post = false; $this->write(); $this->_wrote_pre = false; $this->_wrote_post = false; return ob_get_clean(); } }