/** * @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 citation form the already injected data or from the given values. * * @param string $style * @param string $input * @param string $language * @return string */ public function citation($style = '', $input = '', $language = '') { try { $this->registerContext('citation')->setStyle($style)->changeLocale($language)->setInput($input); return Container::getCitation()->render(''); } catch (\ErrorException $error) { return 'An error occurred! ' . $error->getMessage(); } }
/** * Render a bibliography. * * @param string $data * @return string */ public function render($data) { // sort $this->sort(); // render citation to create year-suffix if necessary if (Container::getContext()->getValue('disambiguateAddYearSuffix', 'citation') == true) { Container::getContext()->setName('citation'); Container::getData()->moveToFirst(); Container::getCitation()->render($data); Container::getContext()->setName('bibliography'); // re-sort with bibliography keys $this->sort(); } // render Container::getContext()->enter('bibliography'); $result = $this->layout->render($data); Container::getContext()->leave(); // format return $return = '<div class="csl-bib-body"><div class="csl-entry">'; if (is_array($result) == true && count($result) > 0) { $return .= implode('</div><div class="csl-entry">', $result); } else { $return .= $result; } return $return . '</div></div>'; }
/** * 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); } }