/** * Run request to get homepage * * @param \Duality\Structure\Http\Request $req The HTTP request * @param \Duality\Structure\Http\Response $res The HTTP response * @param array $params The uri params */ public function doIndex(Request &$req, Response &$res, $params = array()) { // Set heading $this->view->addHeading('Welcome to Duality!'); // Set response $res->setContent($this->view->save()); }
/** * Create the home view */ public function __construct() { parent::__construct(); $template = new TextFile('./data/template.html'); $template->load(); $this->loadFile($template); }
/** * Test html doc structure */ public function testHtmlDoc() { $filename = DATA_PATH . '/doc.html'; $file = new TextFile($filename); $file->load(); $doc = new HtmlDoc(); $doc->loadFile($file); $doc2 = HtmlDoc::createFromFilePath($filename); $this->assertInstanceOf('\\Duality\\Structure\\HtmlDoc', $doc2); $doc->setTitle('Duality dummy doc title'); $result = (string) $doc; $expected = "<!DOCTYPE html>\n<html><head><title>Duality dummy doc title</title></head><body></body></html>\n"; $this->assertEquals($expected, $result); $doc = HtmlDoc::createFromFilePath($filename); $doc->setAttribute('body', 'id', 'dummy'); $result = (string) $doc; $expected = "<!DOCTYPE html>\n<html><head><title></title></head><body id=\"dummy\"></body></html>\n"; $this->assertEquals($expected, $result); $doc = HtmlDoc::createFromFilePath($filename); $expected = "<!DOCTYPE html>\n<html><head><title></title></head><body><p>Dummy content</p></body></html>\n"; $doc->appendTo('body', '<p>Dummy content</p>'); $result = (string) $doc; $this->assertEquals($expected, $result); }
/** * Creates an HTML document from file path * * @param string $path Give the file to load the HTML into DOM document * * @return \Duality\Structure\HtmlDoc A new HtmlDoc instance */ public static function createFromFilePath($path) { $doc = new HtmlDoc(); $template = new TextFile($path); $template->load(); $template->getContent(); $doc->loadFile($template); return $doc; }