Beispiel #1
0
 /**
  * @covers Devtools\Template::autofill
  **/
 public function testAutofill()
 {
     $template = "prefix {{data}} postfix";
     file_put_contents($file = 'template.html', $template);
     $data = ['data' => 7];
     $result = "prefix 7 postfix";
     $this->assertEquals(\Devtools\Template::autofill($template, $data), $result);
     $this->assertEquals(\Devtools\Template::autofill($file, $data), $result);
     unlink($file);
 }
Beispiel #2
0
 private function getTextPath($line, $type)
 {
     switch ($type) {
         case 'link':
             $textDelimStart = '[';
             $textDelimEnd = ']';
             $pathDelimStart = '(';
             $pathDelimEnd = ')';
             $template = "{{prefix}}<a href='{{path}}' >{{text}}</a>{{postfix}}";
             break;
         case 'image':
             $textDelimStart = '![';
             $textDelimEnd = ']';
             $pathDelimStart = '(';
             $pathDelimEnd = ')';
             $template = "{{prefix}}<img src='{{path}}' alt='{{text}}' />{{postfix}}";
             break;
     }
     while (isset($textDelimStart) && isset($textDelimEnd) && isset($pathDelimStart) && isset($pathDelimEnd) && isset($template) && ($squareOpen = strpos($line, $textDelimStart)) !== false && ($squareClose = strpos($line, $textDelimEnd, $textBegin = $squareOpen + strlen($textDelimStart))) !== false && ($parensOpen = strpos($line, $pathDelimStart, $squareClose)) !== false && ($parensClose = strpos($line, $pathDelimEnd, $pathBegin = $parensOpen + strlen($pathDelimStart))) !== false) {
         $vars = ['text' => substr($line, $textBegin, $squareClose - $textBegin), 'path' => substr($line, $pathBegin, $parensClose - $pathBegin), 'prefix' => substr($line, 0, $squareOpen), 'postfix' => substr($line, $parensClose + 1)];
         $line = \Devtools\Template::autofill($template, $vars);
     }
     return $line;
 }