コード例 #1
0
ファイル: Style.php プロジェクト: geissler/csl
 /**
  * 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;
 }
コード例 #2
0
ファイル: GroupTest.php プロジェクト: geissler/csl
    /**
     * @covers Geissler\CSL\Rendering\Group::__construct
     * @covers Geissler\CSL\Rendering\Group::render
     * @covers Geissler\CSL\Rendering\Group::hasAccessEmptyVariable
     */
    public function testRenderNames()
    {
        $layout = '<group delimiter=", ">
                        <names variable="author">
                          <name and="symbol" delimiter=", " form="short" />
                        </names>
                      </group>';
        $json = '[
    {
        "author": [
            {
                "family": "Doe",
                "given": "John",
                "static-ordering": false
            },
            {
                "family": "Roe",
                "given": "Jane",
                "static-ordering": false
            }
        ],
        "id": "ITEM-1",
        "issued": {
            "date-parts": [
                [
                    "2000"
                ]
            ]
        },
        "title": "Book A",
        "type": "book"
    },
    {
        "author": [
            {
                "family": "Doe",
                "given": "John",
                "static-ordering": false
            },
            {
                "family": "Roe",
                "given": "Jane",
                "static-ordering": false
            }
        ],
        "id": "ITEM-2",
        "issued": {
            "date-parts": [
                [
                    "2000"
                ]
            ]
        },
        "title": "Book B",
        "type": "book"
    }
]';
        $this->initElement($layout, $json);
        Container::getLocale()->readFile();
        $citation = '<citation
                            disambiguate-add-givenname="true"
                            disambiguate-add-names="true"
                            disambiguate-add-year-suffix="true"
                            et-al-min="2"
                            et-al-use-first="1"
                            givenname-disambiguation-rule="by-cite">
                            <layout></layout>
                            </citation>';
        Container::setCitation(new Citation(new \SimpleXMLElement($citation)));
        Container::getContext()->setName('citation');
        $this->assertEquals('Doe et al.', $this->object->render(''));
    }
コード例 #3
0
ファイル: NameTest.php プロジェクト: geissler/csl
 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);
 }