Exemplo n.º 1
0
 /**
  * Generates a Style object and injects the dir path.
  * 
  * @return \Geissler\CSL\Style\Style
  */
 public static function style()
 {
     self::loadConfig();
     $style = new Style();
     $style->setDir(self::$configuration['styles']['dir']);
     return $style;
 }
Exemplo n.º 2
0
 /**
  * Running PHPUnit test
  * @param $text
  * @param $name
  * @return array
  */
 protected function runTestFromFile($text, $name)
 {
     Container::clear();
     preg_match('/MODE [=]+>>(.*)<<[=]+ MODE/s', $text, $match);
     $mode = preg_replace('/\\s\\s+/', '', $match[1]);
     $mode = preg_replace('/\\n/', '', $mode);
     preg_match('/RESULT [=]+>>(.*)<<[=]+ RESULT/s', $text, $match);
     $result = preg_replace('/\\s\\s+/', '', $match[1]);
     $result = preg_replace('/^\\n/', '', $result);
     $result = preg_replace('/\\n$/', '', $result);
     preg_match('/CSL [=]+>>(.*)<<[=]+ CSL/s', $text, $match);
     $csl = preg_replace('/^\\n/', '', $match[1]);
     preg_match('/INPUT [=]+>>(.*)<<[=]+ INPUT/s', $text, $match);
     $json = preg_replace('/\\s\\s+/', '', $match[1]);
     $style = new Style();
     if (strpos($csl, '<') !== false) {
         $style->readXml(new \SimpleXMLElement($csl));
     } else {
         $csl = preg_replace('/\\n/', '', $csl);
         $csl = str_replace('.csl', '', $csl);
         $style->setDir(__DIR__ . $this->style)->readFile($csl);
     }
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     Container::getContext()->setName($mode);
     // Abbreviations
     if (preg_match('/ABBREVIATIONS [=]+>>(.*)<<[=]+ ABBREVIATIONS/s', $text, $match) == 1) {
         $json = preg_replace('/\\s\\s+/', '', $match[1]);
         $abbreviation = new Abbreviation();
         $abbreviation->set($json);
         Container::setAbbreviation($abbreviation);
     }
     // CitationItems items
     if (preg_match('/CITATION-ITEMS[ ]+[=]+>>(.*)<<[=]+[ ]+CITATION-ITEMS/s', $text, $match) == 1) {
         $json = preg_replace('/\\s\\s+/', '', $match[1]);
         $citation = new CitationItems();
         $citation->set($json);
         Container::setCitationItem($citation);
     } elseif (preg_match('/CITATIONS[ ]+[=]+>>(.*)<<[=]+[ ]+CITATIONS/s', $text, $match) == 1) {
         // Citations items
         $json = preg_replace('/\\s\\s+/', '', $match[1]);
         $citation = new Citations();
         $citation->set($json);
         Container::setCitationItem($citation);
     }
     if ($mode == 'citation') {
         return array($result, Container::getCitation()->render(''), $name);
     } elseif ($mode == 'bibliography') {
         return array($result, Container::getBibliography()->render(''), $name);
     } elseif ($mode == 'bibliography-nosort') {
         Container::getBibliography()->setDoNotSort(true);
         return array($result, Container::getBibliography()->render(''), $name);
     } else {
         return array('Missing mode', '', $name);
     }
 }