Example #1
0
 /**
  * http://www.w3.org/TR/html5/semantics.html#the-html-element
  * 
  * Note: The w3c recommends always using
  * the `lang` attribute at this level;
  * therefore, it is the only required key.
  *
  * Required keys
  * lang: Value must be a valid BCP 47 language tag, 
  * or the empty string.
  *
  * Optional keys
  * useDoctype: true|false (default is false) Whether or not to open a document.
  * head: A configuration for the Head class.
  * body: A configuration for the Body class.
  *
  * See global optional keys above.
  * 
  */
 public static function html($config)
 {
     $opening = '';
     if (isset($config['useDoctype']) && $config['useDoctype']) {
         $opening = Html5Gen::doctype();
     }
     $content = Html::build($config);
     return $opening . $content;
 }
 public function testDir1()
 {
     $expected = '<p class="u1" dir="auto"><b><bdi>Student</bdi>:</b> How do you write "What\'s your name?" in Arabic?</p>' . '<p class="u2" dir="auto"><b><bdi>Teacher</bdi>:</b> ما اسمك؟</p>' . '<p class="u1" dir="auto"><b><bdi>Student</bdi>:</b> Thanks.</p>' . '<p class="u2" dir="auto"><b><bdi>Teacher</bdi>:</b> That\'s written "شكرًا".</p>' . '<p class="u2" dir="auto"><b><bdi>Teacher</bdi>:</b> Do you know how to write "Please"?</p>' . '<p class="u1" dir="auto"><b><bdi>Student</bdi>:</b> "من فضلك", right?</p>';
     $result = '';
     $process = function ($class, $user, $content) use(&$result) {
         $result .= Html5Gen::p(['dir' => 'auto', 'class' => [$class], 'content' => [['element' => 'b', 'config' => ['content' => [['element' => 'bdi', 'config' => ['content' => $user]], ':']]], $content]]);
     };
     $startTime = microtime(true);
     $process('u1', 'Student', ' How do you write "What\'s your name?" in Arabic?');
     $process('u2', 'Teacher', ' ما اسمك؟');
     $process('u1', 'Student', ' Thanks.');
     $process('u2', 'Teacher', ' That\'s written "شكرًا".');
     $process('u2', 'Teacher', ' Do you know how to write "Please"?');
     $process('u1', 'Student', ' "من فضلك", right?');
     $stopTime = microtime(true);
     // The performance anonymous function is inconsistent.
     // Max allowed is 11 - rarely is this number met, much less exceeded.
     $this->assertPerformance($startTime, $stopTime, 11);
     $this->assertEquality($expected, $result);
 }
Example #3
0
 protected static function prepare($config)
 {
     $caption = '';
     if (isset($config['caption'])) {
         $caption = \Eightfold\Html5Gen\Html5Gen::figcaption($config['caption']);
     }
     if (isset($config['content']) && is_array($config['content']) && isset($config['captionIsFirst']) && $config['captionIsFirst']) {
         // add caption to beginning of content
         array_unshift($config['content'], $caption);
     } elseif (isset($config['content']) && is_string($config['content']) && isset($config['captionIsFirst']) && $config['captionIsFirst']) {
         // add caption to string
         $config['content'] = $caption . $config['content'];
     } elseif (isset($config['content']) && is_array($config['content'])) {
         // add caption to beginning of content
         array_push($config['content'], $caption);
     } elseif (isset($config['content']) && is_string($config['content'])) {
         // add caption to string
         $config['content'] = $config['content'] . $caption;
     } else {
         $config['content'] = $caption;
     }
     return $config;
 }
 public function testHeadStyleEmpty()
 {
     $expected = '<head><title>Hello world!</title></head>';
     $result = Html5Gen::head(['title' => ['content' => 'Hello world!'], 'styles' => []]);
     $this->assertEquality($expected, $result);
 }
 public function testBodyAriaRoleCannotBeArticle()
 {
     $expected = '<body></body>';
     $result = Html5Gen::body(['role' => 'article']);
     $this->assertEquality($expected, $result);
 }
 public function testFieldsetWithLegend()
 {
     $expected = '<fieldset><legend></legend></fieldset>';
     $result = Html5Gen::fieldset(['legend' => [[]]]);
     $this->assertEquality($expected, $result);
 }
 public function testH6Base()
 {
     $expected = '<h6></h6>';
     $result = Html5Gen::h6();
     $this->assertEquality($expected, $result);
 }
 public function testMainBase()
 {
     $expected = '<main></main>';
     $result = Html5Gen::main();
     $this->assertEquality($expected, $result);
 }
 public function testHtmlGlobalAttributes2()
 {
     $expected = '<html id="primary" class="class1 class2 class3" style="background-color: red;" tabindex="1" accesskey="M" lang="en" dir="ltr" translate="yes" title="hello world" contenteditable="false" spellcheck="false"></html>';
     $result = Html5Gen::html(['accesskey' => 'M', 'class' => ['class1', 'class2', 'class3'], 'contenteditable' => 'false', 'dir' => 'ltr', 'hidden' => false, 'id' => 'primary', 'lang' => 'en', 'spellcheck' => 'false', 'style' => 'background-color: red;', 'tabindex' => 1, 'titleAttribute' => 'hello world', 'translate' => 'yes']);
     $this->assertEquality($expected, $result);
 }
 public function testDelBase()
 {
     $expected = '<del></del>';
     $result = Html5Gen::del();
     $this->assertEquality($expected, $result);
 }
 public function testCanvasBase()
 {
     $expected = '<canvas></canvas>';
     $result = Html5Gen::canvas();
     $this->assertEquality($expected, $result);
 }
 public function testWbrNoContent()
 {
     $expected = '<wbr>';
     $result = Html5Gen::wbr(['content' => 'hello']);
     $this->assertEquality($expected, $result);
 }
 public function testTableWithMultipleBodies()
 {
     $expected = '<table><caption></caption><colgroup><col span="2"><col span="1"></colgroup><thead><tr><th></th><th></th></tr></thead><tfoot><tr><th></th><td></td></tr></tfoot><tbody><tr><td></td><td></td></tr></tbody><tbody><tr><td></td><td></td></tr></tbody></table>';
     $result = Html5Gen::table(['colgroup' => ['cols' => [['span' => 2], ['span' => 1]]], 'caption' => [], 'bodies' => [['rows' => [['cells' => [[], []]]]], ['rows' => [['cells' => [[], []]]]]], 'head' => ['rows' => [['cells' => [['isHeader' => true], ['isHeader' => true]]]]], 'foot' => ['rows' => [['cells' => [['isHeader' => true], []]]]]]);
     $this->assertEquality($expected, $result);
 }
 public function testAreaBase()
 {
     $expected = '<area>';
     $result = Html5Gen::area();
     $this->assertEquality($expected, $result);
 }