/** * Parses the affix configuration. * * @param \SimpleXMLElement $date * @param array $additional Array with key form and value text or numeric */ public function __construct(\SimpleXMLElement $date, array $additional) { $this->name = ''; $this->delimiter = '–'; $this->formatting = new Formatting($date); $this->textCase = new TextCase($date); $this->affix = new Affix($date); foreach ($date->attributes() as $name => $value) { switch ($name) { case 'name': $this->name = (string) $value; switch ($this->name) { case 'day': $this->render = Factory::day($additional['form'], $date); break; case 'month': $this->render = Factory::month($additional['form'], $date); break; case 'year': $this->render = Factory::year($additional['form'], $date); break; } break; case 'range-delimiter': $this->delimiter = (string) $value; break; } } }
/** * Parses the style configuration from the SimpleXMLElement object. * * @param \SimpleXMLElement $xml * @return \Geissler\CSL\Style\Style */ public function readXml(\SimpleXMLElement $xml) { // store "global" configuration options in the context object Container::getContext()->addStyle('initializeWithHyphen', true); Container::getContext()->addStyle('demoteNonDroppingParticle', 'display-and-sort'); foreach ($xml->attributes() as $name => $value) { switch ($name) { case 'class': Container::getContext()->addStyle('class', (string) $value); break; case 'default-locale': $locale = Factory::locale(); $locale->readFile((string) $value); Container::setLocale($locale); break; } } // set global options and inheritable name options $options = new Options(); $options->set('style', $xml); foreach ($xml->children() as $child) { switch ($child->getName()) { case 'citation': Container::setCitation(new Citation($child)); break; case 'bibliography': Container::setBibliography(new Bibliography($child)); break; case 'macro': $macroName = ''; foreach ($child->attributes() as $name => $value) { if ($name == 'name') { $macroName = (string) $value; break; } } if ($macroName !== '') { Container::addMacro($macroName, new Macro($child)); } break; case 'locale': Container::getLocale()->addXml($child); break; } } return $this; }
/** * Set a language different from the one configured in the style. * * @param string $language * @return \Geissler\CSL\CSL */ public function changeLocale($language) { if ($language != '') { $locale = Factory::locale(); $locale->readFile($language); Container::setLocale($locale); } return $this; }
protected function initElement($layout, $json, $language = 'en-US') { $locale = Factory::locale(); $locale->readFile($language); Container::setLocale($locale); $data = new Data(); $data->set($json); Container::setData($data); $xml = new \SimpleXMLElement($layout); $this->object = new Label($xml); }
protected function initElement($layout, $language = 'en-US') { $xml = new \SimpleXMLElement($layout); $this->object = new Month($xml); $locale = Factory::locale(); $locale->readFile($language); Container::setLocale($locale); }
/** * Reset all internal properties. * * @return void */ public static function clear() { self::$context = new Context(); self::$macros = array(); self::$citationItem = false; self::$context = new Context(); self::$rendered = new Rendered(); self::$bibliography = null; self::$citation = null; self::setLocale(Factory::locale()); self::$locale->readFile(); }
protected function initElement($layout, $context = '<citation><layout></layout></citation>', $language = 'en-US') { Container::clear(); Container::setData(new Data()); $locale = Factory::locale(); $locale->readFile($language); Container::setLocale($locale); if (strpos($context, 'citation') !== false) { Container::getContext()->setName('citation'); Container::setCitation(new Citation(new \SimpleXMLElement($context))); } else { Container::getContext()->setName('bibliography'); Container::setBibliography(new Bibliography(new \SimpleXMLElement($context))); } $xml = new \SimpleXMLElement($layout); $this->object = new Name($xml); }
/** * @covers Geissler\CSL\Rendering\Term::render * @covers Geissler\CSL\Rendering\Term::__construct */ public function testRender6() { $locale = Factory::locale(); $locale->readFile('fr'); Container::setLocale($locale); $layout = '<text term="paragraph" form="symbol" text-case="capitalize-first" strip-periods="true"/>'; $this->initElement($layout); $this->assertEquals('§', $this->object->render('')); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->object = Factory::locale(); }
/** * @covers Geissler\CSL\Rendering\TextCase::modify * @covers Geissler\CSL\Rendering\TextCase::render */ public function testRenderModified() { $locale = Factory::locale(); $locale->readFile('de'); Container::setLocale($locale); $this->initElement('<text variable="title" text-case="sentence"/>'); $xml = '<text variable="title" text-case="uppercase"/>'; $this->assertInstanceOf('\\Geissler\\CSL\\Rendering\\TextCase', $this->object->modify(new \SimpleXMLElement($xml))); $this->assertEquals('THIS IS A PEN THAT IS A SMITH PENCIL', $this->object->render('this is a Pen that is a Smith Pencil')); }
/** * @covers Geissler\CSL\Date\Day::render * @covers Geissler\CSL\Date\Day::modify */ public function testModifyAndRender() { $locale = Factory::locale(); $locale->readFile('fr'); Container::setLocale($locale); $layout = '<date-part name="day" form="ordinal"/>'; $this->initElement($layout); $xml = new \SimpleXMLElement('<date-part name="day" form="numeric"/>'); $this->assertInstanceOf('\\Geissler\\CSL\\Date\\Day', $this->object->modify($xml)); $this->assertEquals('1', $this->object->render('1')); }