/** * 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>'; }
/** * 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; }
public function testWrittenIn() { $layout = '<layout prefix="(" suffix=")"> <group delimiter=" "> <names variable="author"> <name form="short" /> </names> <date variable="issued"> <date-part name="year" /> </date> </group> </layout>'; $json = '[ { "author": [ { "family": "Smith", "given": "John", "static-ordering": false } ], "id": "ITEM-1", "issued": { "date-parts": [ [ "2000", "2", "15" ] ] }, "title": "Book C", "type": "book" } ]'; $citation = '[ [ { "id": "ITEM-1", "prefix": "As written in" } ] ]'; $this->initElement($layout, $json, $citation); $result = $this->object->render(''); $this->assertInternalType('array', $result); $this->assertContains('(As written in Smith 2000)', implode('', $result)); }