/**
  * Kod źródłowy w formacie HTML
  * 
  * @param StyleSheetResource $res
  * @param string $output
  */
 protected function render_html(StyleSheetResource $res, &$output)
 {
     foreach ($res->getUrl() as $url) {
         $tag = new HtmlElement('link');
         $tag->attr('href', $url);
         $tag->attr('rel', 'stylesheet');
         $tag->attr('type', 'text/css');
         $output .= $tag->render();
         $tag->destroy($tag);
     }
 }
예제 #2
0
 /**
  * @param string $name
  *
  * @throws \InvalidArgumentException
  */
 public function renameRoot($name)
 {
     if (!is_string($name)) {
         throw new \InvalidArgumentException('name is not string');
     }
     $newnode = new HtmlElement($name);
     foreach ($this->root->getElement()->attributes as $attrNode) {
         $newnode->getElement()->setAttribute($attrNode->name, $attrNode->value);
     }
     $this->root->destroy($this->root);
     $this->root = $newnode;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     // ten element na wyjściu będzie zamieniony na $this->body()
     $replaceBody = new HtmlElement('replace_body');
     $replaceBody->text('replace');
     $replaceBody->insertTo($this->root);
     $output = $this->prologRender();
     $output .= str_replace("<replace_body>replace</replace_body>", $this->body(), $this->root->render(false, true));
     // posprzątaj kod
     $replaceBody->destroy($replaceBody);
     return $output;
 }
예제 #4
0
 /**
  * testowanie atrybutu class
  */
 public function classTest()
 {
     $el = new HtmlElement('link');
     $el->addClass('test1');
     $el->addClass('test');
     $el->removeClass('test');
     $this->assertEquals('test1', $el->attr('class'));
     $el->destroy($el);
 }
 /**
  * Kod znacznika <picture>
  * 
  * @param ImageResource $res
  * @param string $output
  */
 protected function render_html_picture(ImageResource $res, &$output)
 {
     $data = $res->imageData();
     $tmp = '';
     $source = function (array &$arr) use(&$data, &$tmp) {
         $tag = new HtmlElement('source');
         $srcset = '';
         foreach ($arr as &$img) {
             $srcset .= $img['url'];
             $srcset .= !empty($img['data']['srcset_x']) ? ' ' . $img['data']['srcset_x'] . 'x' : '';
             $srcset .= ', ';
         }
         $tag->attr('srcset', substr($srcset, 0, -2));
         $index = $arr[0]['data']['media_index'];
         if (isset($data['media'][$index])) {
             $tag->attr('media', $data['media'][$index]);
         }
         $tmp .= $tag->render() . PHP_EOL;
         $tag->destroy($tag);
     };
     foreach ($data as $k => $v) {
         if (is_integer($k) && $k > -1 && is_array($v)) {
             $source($data[$k]);
         }
     }
     if (isset($data[-1])) {
         $source($data[-1]);
     }
     $urls = $res->getUrl();
     $img = new HtmlElement('img');
     $img->attr('src', $urls[$data['src-index']]);
     $img->attr('alt', htmlspecialchars($res->getName()));
     $tag = new HtmlElement('picture');
     //$tag->attr('alt', htmlspecialchars($res->getName()));
     foreach ($data['attr'] as $k => $v) {
         $tag->attr(htmlspecialchars($k), htmlspecialchars($v));
     }
     preg_match('/<picture.*?>/', $tag->render(), $result);
     $output[] = (isset($result[0]) ? $result[0] . PHP_EOL : '<picture>' . PHP_EOL) . "<!--[if IE 9]><video style=\"display: none;\"><![endif]-->" . PHP_EOL . str_replace("</source>", '', $tmp) . "<!--[if IE 9]></video><![endif]-->" . PHP_EOL . $img->render() . PHP_EOL . '</picture>';
     $tag->destroy($tag);
     $img->destroy($img);
 }
 /**
  * Kod źródłowy w formacie HTML
  * 
  * @param JavaScriptResource $res
  * @param string $output
  */
 protected function render_html(JavaScriptResource $res, &$output)
 {
     foreach ($res->getUrl() as $url) {
         $tag = new HtmlElement('script');
         $tag->attr('src', $url);
         $tag->attr('type', 'text/javascript');
         $output .= $tag->render();
         $tag->destroy($tag);
     }
 }