Esempio n. 1
0
 public function render(Tag $tag)
 {
     if (!$tag instanceof Input) {
         throw new Exception(__CLASS__ . ' only renders Tag objects that instances of ' . Input::class);
     }
     $tag->assignDefaultValue();
     $tagRenderer = new DefaultTagRenderer();
     return $tagRenderer->render($tag);
 }
Esempio n. 2
0
 /**
  * @param      $value
  * @param null $label
  */
 public static function dump($value, $label = null)
 {
     echo Tag::pre();
     if ($label) {
         echo Tag::div($label);
     }
     var_dump($value);
     echo Tag::pre()->close();
 }
Esempio n. 3
0
 public static function dump()
 {
     echo '<!-- Embedded JavaScript files -->' . PHP_EOL;
     foreach (self::$files as $src => $attributes) {
         echo PHP_EOL;
         Tag::factory('script')->addAttribute('src', $src)->addAttribute('type', 'application/javascript')->addAttributes($attributes)->dump();
         Tag::factory('script')->close();
         echo PHP_EOL;
     }
     echo '<!-- End of embedded JavaScript files -->' . PHP_EOL;
 }
 protected function renderException(\Throwable $exception)
 {
     $div = Tag::div(Tag::h2('Exception trace'), 'errors');
     $div->append(Tag::h2('Exception'), Tag::i(get_class($exception)));
     $div->append(Tag::h2('Message'), Tag::pre($exception->getMessage()));
     $div->append(Tag::h2('File'), Tag::pre($exception->getFile())->append(':', $exception->getLine())->setSeparator(''));
     // shorten Trace
     $trace = Str::cast($exception->getTraceAsString())->replace(getcwd() . '/', '');
     $div->append(Tag::h2('Trace'), Tag::pre($trace));
     return $div;
 }
Esempio n. 5
0
 public function testAttributeMergePolicies()
 {
     $tag = new Tag();
     $tag->disableAutoDump();
     $tag->addAttribute('test', 'value');
     $tag->addAttribute('test', 'value2', MergePolicy::COMBINE);
     $this->assertEquals(['value', 'value2'], $tag->getAttribute('test')->toArray());
     $tag->addAttribute('test2', 'value3', MergePolicy::COMBINE);
     $this->assertEquals('value3', $tag->getAttribute('test2'));
 }
Esempio n. 6
0
 public static function errors($input, callable $renderer = null)
 {
     if (!($messages = self::$errors)) {
         // no messages at all
         return;
     }
     if (!$messages->has($input)) {
         // no message for this input
         return;
     }
     // render errors using external renderer
     if ($renderer) {
         return $renderer($input, $messages->get($input), $messages);
     }
     $errors = Tag::ul()->addClass('form-field-error');
     foreach ($messages->get($input) as $message) {
         $errors->append(Tag::li($message, 'message-' . $message->getType()));
     }
     return $errors;
 }
Esempio n. 7
0
 public function render(Tag $tag)
 {
     if ($tag->isClosingTag()) {
         $tag->close(false);
         return '</' . $tag->getTag() . '>';
     } else {
         $html = '<' . trim(implode(' ', [$tag->getTag(), $tag->getAttributes()])) . '>';
         if (!$tag->getContent()->isEmpty()) {
             $chunks = new Collection();
             $tag->getContent()->each(function ($chunk) use(&$chunks) {
                 $content = (string) $chunk;
                 if ($content) {
                     $chunks[] = $content;
                 }
             });
             $html .= $chunks->join($tag->getSeparator())->trim();
             $html .= '</' . $tag->getTag() . '>';
         } elseif ($tag->isAlwaysClosed()) {
             $html .= '</' . $tag->getTag() . '>';
         }
         return $html;
     }
 }