refactor: move cff code to library
This commit is contained in:
+25
-1
@@ -823,7 +823,31 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_cff() {
|
||||||
|
|
||||||
|
$btb = new BibDataBase();
|
||||||
|
$btb->load('bibacid-utf8.bib');
|
||||||
|
$entry = $btb->bibdb['arXiv-1807.05030'];
|
||||||
|
$expected = "cff-version: 1.2.0\n".
|
||||||
|
"# CITATION.cff created with https://github.com/monperrus/bibtexbrowser/\n".
|
||||||
|
"preferred-citation:\n".
|
||||||
|
" title: \"A Comprehensive Study of Pseudo-tested Methods\"\n".
|
||||||
|
" year: \"2018\"\n".
|
||||||
|
" authors:\n".
|
||||||
|
" - family-names: Vera-Pérez\n".
|
||||||
|
" given-names: Oscar Luis\n".
|
||||||
|
" - family-names: Danglot\n".
|
||||||
|
" given-names: Benjamin\n".
|
||||||
|
" - family-names: Monperrus\n".
|
||||||
|
" given-names: Martin\n".
|
||||||
|
" - family-names: Baudry\n".
|
||||||
|
" given-names: Benoit\n";
|
||||||
|
|
||||||
|
$this->assertEquals($expected,$entry->toCFF());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end class
|
} // end class
|
||||||
|
|
||||||
@copy('bibtexbrowser.local.php.bak','bibtexbrowser.local.php');
|
@copy('bibtexbrowser.local.php.bak','bibtexbrowser.local.php');
|
||||||
|
|||||||
+1
-25
@@ -21,31 +21,7 @@ function bibtexbrowser_cff($arguments) {
|
|||||||
$current_entry = $db->getEntryByKey($arguments[$i+1]);
|
$current_entry = $db->getEntryByKey($arguments[$i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// now we have $current_entry
|
echo $current_entry->toCFF();
|
||||||
echo "cff-version: 1.2.0"."\n";
|
|
||||||
echo "# CITATION.cff created with https://github.com/monperrus/bibtexbrowser/"."\n";
|
|
||||||
echo "preferred-citation:"."\n";
|
|
||||||
echo " title: \"".$current_entry->getTitle()."\""."\n";
|
|
||||||
if ($current_entry->hasField("doi")) {
|
|
||||||
echo " doi: \"".$current_entry->getField("doi")."\""."\n";
|
|
||||||
}
|
|
||||||
if ($current_entry->hasField("year")) {
|
|
||||||
echo " year: \"".$current_entry->getField("year")."\""."\n";
|
|
||||||
}
|
|
||||||
if ($current_entry->hasField("journal")) {
|
|
||||||
echo " type: article\n";
|
|
||||||
echo " journal: \"".$current_entry->getField("journal")."\""."\n";
|
|
||||||
}
|
|
||||||
if ($current_entry->hasField("booktitle")) {
|
|
||||||
echo " type: conference-paper\n";
|
|
||||||
echo " conference: \"".$current_entry->getField("booktitle")."\""."\n";
|
|
||||||
}
|
|
||||||
echo " authors:"."\n";
|
|
||||||
foreach ($current_entry->getFormattedAuthorsArray() as $author) {
|
|
||||||
$split = splitFullName($author);
|
|
||||||
echo " - family-names: ".$split[1]."\n";
|
|
||||||
echo " given-names: ".$split[0]."\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bibtexbrowser_cff($argv);
|
bibtexbrowser_cff($argv);
|
||||||
|
|||||||
+32
-1
@@ -1980,7 +1980,38 @@ class BibEntry {
|
|||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // enc class BibEntry
|
/** returns in the citation file format, tailored for github */
|
||||||
|
function toCFF() {
|
||||||
|
$result = "";
|
||||||
|
$result .= "cff-version: 1.2.0"."\n";
|
||||||
|
$result .= "# CITATION.cff created with https://github.com/monperrus/bibtexbrowser/"."\n";
|
||||||
|
$result .= "preferred-citation:"."\n";
|
||||||
|
$result .= " title: \"".$this->getTitle()."\""."\n";
|
||||||
|
if ($this->hasField("doi")) {
|
||||||
|
$result .= " doi: \"".$this->getField("doi")."\""."\n";
|
||||||
|
}
|
||||||
|
if ($this->hasField("year")) {
|
||||||
|
$result .= " year: \"".$this->getField("year")."\""."\n";
|
||||||
|
}
|
||||||
|
if ($this->hasField("journal")) {
|
||||||
|
$result .= " type: article\n";
|
||||||
|
$result .= " journal: \"".$this->getField("journal")."\""."\n";
|
||||||
|
}
|
||||||
|
if ($this->hasField("booktitle")) {
|
||||||
|
$result .= " type: conference-paper\n";
|
||||||
|
$result .= " conference: \"".$this->getField("booktitle")."\""."\n";
|
||||||
|
}
|
||||||
|
$result .= " authors:"."\n";
|
||||||
|
foreach ($this->getFormattedAuthorsArray() as $author) {
|
||||||
|
$split = splitFullName($author);
|
||||||
|
$result .= " - family-names: ".$split[1]."\n";
|
||||||
|
$result .= " given-names: ".$split[0]."\n";
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // end class BibEntry
|
||||||
|
|
||||||
class RawBibEntry extends BibEntry {
|
class RawBibEntry extends BibEntry {
|
||||||
function setField($name, $value) {
|
function setField($name, $value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user