/** * @covers Geissler\CSL\Style\Style::readFile * @covers Geissler\CSL\Style\Style::setDir * @covers Geissler\CSL\Style\Style::readXml */ public function testReadFile2() { $this->assertInstanceOf($this->class, $this->object->setDir($this->dir)); $this->assertInstanceOf($this->class, $this->object->readFile('american-journal-of-archaeology')); $this->assertInstanceOf('\\Geissler\\CSL\\Style\\Citation', \Geissler\CSL\Container::getCitation()); $this->assertInstanceOf('\\Geissler\\CSL\\Style\\Bibliography', \Geissler\CSL\Container::getBibliography()); $this->assertInstanceOf('\\Geissler\\CSL\\Locale\\Locale', \Geissler\CSL\Container::getLocale()); }
/** * Render the citations. * * @param string $data * @return string */ public function render($data) { Container::getContext()->enter('citation'); // sort if (isset($this->sort) == true) { $this->sort->sort('citation'); } // render citation $result = $this->layout->render($data); // The assignment of the year-suffixes follows the order of the bibliographies entries, // so sort if disambiguation by year-suffixes is needed, sort the data by the bibliography // and re-render citations if (Container::hasBibliography() == true && Container::getContext()->getValue('disambiguateAddYearSuffix', 'citation') === true && Container::getContext()->getLastDisambiguation() == 'Geissler\\CSL\\Options\\Disambiguation\\AddYearSuffix' && Container::getBibliography()->sort() == true) { Container::getRendered()->clear(); // re-render citation $result = $this->layout->render($data); } if (Container::getCitationItem() !== false) { // apply additional citation formatting options Container::getCitationItem()->moveToFirst(); if (Container::getCitationItem()->get('noteIndex') !== null || Container::getCitationItem()->get('index') !== null) { $citation = array(); $length = count($result); $prefix = '..'; for ($i = 0; $i < $length; $i++) { if ($i + 1 == $length) { $prefix = '>>'; } // Therefore, the first character of a citation should preferably be uppercased $citation[] = $prefix . '[' . $i . '] ' . $this->upperCase($result[$i]); } $return = implode("\n", $citation); } else { array_walk($result, array($this, 'upperCase')); $return = implode("\n", $result); } } else { array_walk($result, array($this, 'upperCase')); $return = implode("\n", $result); } Container::getContext()->leave(); return $return; }
/** * Render the bibliography form the already injected data or from the given values. * * @param string $style * @param string $input * @param string $language * @return string */ public function bibliography($style = '', $input = '', $language = '') { try { $this->registerContext('bibliography')->setStyle($style)->changeLocale($language)->setInput($input); return Container::getBibliography()->render(''); } catch (\ErrorException $error) { return 'An error occurred! ' . $error->getMessage(); } }
/** * 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); } }