PhoenixLecture  2.0.0
Set of tools to make lectures
pbiblio_html.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #include "convertToString.h"
8 #include "platexobj_html.h"
9 #include "pbiblio_html.h"
10 
12 
16 PString createNavigationMenuBiblio(const PString & cssClassName, const POutoutMode & outputMode){
17  PString body("");
18  body += "\t\t<table class=\""+cssClassName+"\">\n";
19  body += "\t\t\t<tr>\n";
20  body += "\t\t\t<td><a href=\"index.html\">Main Page</a></td>\n";
21  body += "\t\t\t<td><a href=\"bibliography.html\">Bibliographie</a></td>\n";
22  if(!outputMode.isBookTheme){
23  body += "\t\t\t<td><a href=\"outline.html\">Outline</a></td>\n";
24  }
25  body += "\t\t\t</tr>\n";
26  body += "\t\t</table>\n";
27  return body;
28 }
29 
31 
35  if(type == PBiblioEntryType::ARTICLE){return "bibarticle";}
36  else if(type == PBiblioEntryType::BOOK){return "bibbook";}
37  else if(type == PBiblioEntryType::SOFTWARE){return "bibsoftware";}
38  else if(type == PBiblioEntryType::INPROCEEDINGS){return "bibinproceedings";}
39  else if(type == PBiblioEntryType::PHDTHESIS){return "bibphdthesis";}
40  else if(type == PBiblioEntryType::TECHREPORT){return "bibtechreport";}
41  else {return "bibarticle";}
42 }
43 
45 
50 PString pbiblio_attributeHtml(const PString & attrValue, const PString & balise, const PString & extraText){
51  if(attrValue == ""){return "";}
52  PString body("");
53  body += "\t<"+balise+">";
54  if(extraText != ""){
55  body += extraText + " : ";
56  }
57  body += convertStrToHtml(attrValue)+"</"+balise+">\n";
58  return body;
59 }
60 
62 
66 PString pbiblio_attributeUrlHtml(const PString & attrValue, const PString & balise){
67  if(attrValue == ""){return "";}
68  PString body("");
69  body += "\t<"+balise+"><a href=\""+attrValue+"\">"+attrValue+"</a></"+balise+">\n";
70  return body;
71 }
72 
74 
78  PString fileName("bib_"+valueToString(bibEntry.getId())+".html");
79  PString body("");
80  body += pbiblio_attributeHtml(bibEntry.getTitle(), "h1", "Title");
81  body += pbiblio_attributeHtml(bibEntry.getAuthor(), "h2", "Authors");
82  body += pbiblio_attributeHtml(bibEntry.getJournal(), "h3", "Journal");
83  body += pbiblio_attributeHtml(bibEntry.getVolume(), "h3", "Volume");
84  body += pbiblio_attributeHtml(bibEntry.getYear(), "h3", "Year");
85  body += pbiblio_attributeHtml(bibEntry.getPages(), "h3", "Pages");
86  body += pbiblio_attributeUrlHtml(bibEntry.getUrl(), "h3");
87  //TODO : Add more info there
88  if(bibEntry.getAbstract() != ""){
89  body += "<h3>Abstract</h3>\n";
90  body += bibEntry.getAbstract() + "\n";
91  }
92 
93  return body;
94 }
95 
97 
101 bool pbiblio_entryPage(const PBiblioEntry & bibEntry, const POutoutMode & outputMode){
102  PString body(getHtmlHeader(bibEntry.getTitle(), false, false, outputMode.currentStyle));
103  body += createNavigationMenuBiblio("navigationMenu", outputMode);
104  body += "\t\t<div class=\"biblioContent\">\n";
105 
106  body += "\t\t\t<div class=\""+pbiblio_entryTypeToHtml(bibEntry.getType())+"\">\n";
107  body += pbiblio_entryPageHtml(bibEntry);
108  body += "\t\t\t</div>\n";
109 
110  body += "\t\t</div>\n";
111  body += createNavigationMenuBiblio("navigationMenuBottom", outputMode);
112  body += getHtmlFooter();
113 
114  PPath fileName("bib_"+valueToString(bibEntry.getId())+".html");
115  if(!fileName.saveFileContent(body)){
116  std::cerr << "pbiblio_entryPage : can't save file '"<<fileName<<"'" << std::endl;
117  return false;
118  }
119 // else{
120 // std::cerr << "pbiblio_entryPage : save file '"<<fileName<<"'" << std::endl;
121 // }
122  return true;
123 }
124 
126 
130  PString body("");
131  body += "<div class=\""+pbiblio_entryTypeToHtml(bibEntry.getType())+"\" id=\""+valueToString(bibEntry.getId())+"\">\n";
132  body += pbiblio_attributeHtml(bibEntry.getTitle(), "h1", "Title");
133  body += pbiblio_attributeHtml(bibEntry.getAuthor(), "h2", "Authors");
134  body += pbiblio_attributeHtml(bibEntry.getJournal(), "h3", "Journal");
135  body += pbiblio_attributeHtml(bibEntry.getVolume(), "h3", "Volume");
136  body += pbiblio_attributeHtml(bibEntry.getYear(), "h3", "Year");
137  body += pbiblio_attributeHtml(bibEntry.getPages(), "h3", "Pages");
138  body += pbiblio_attributeUrlHtml(bibEntry.getUrl(), "h3");
139  body += "\t<a href=\"bib_"+valueToString(bibEntry.getId())+".html\">+ informations</a>\n";
140  body += "</div>\n";
141  return body;
142 }
143 
145 
149 PString pbiblio_html(const PMapBiblioEntry & mapBiblioEntry, const POutoutMode & outputMode){
150  PString body(getHtmlHeader("Bibliography", false, false, outputMode.currentStyle));
151  body += createNavigationMenuBiblio("navigationMenu", outputMode);
152  body += "\t\t<div class=\"biblioContent\">\n";
153 
154  for(PMapBiblioEntry::const_iterator it(mapBiblioEntry.begin()); it != mapBiblioEntry.end(); ++it){
155  body += pbiblio_entryHtml(it->second);
156  pbiblio_entryPage(it->second, outputMode);
157  }
158 
159  body += "\t\t</div>\n";
160  body += createNavigationMenuBiblio("navigationMenuBottom", outputMode);
161  body += getHtmlFooter();
162  return body;
163 }
164 
166 
171 bool pbiblio_html(const PPath & fileName, const PMapBiblioEntry & mapBiblioEntry, const POutoutMode & outputMode){
172  PString fileContent(pbiblio_html(mapBiblioEntry, outputMode));
173  if(!fileName.saveFileContent(fileContent)){
174  std::cerr << "platexobj_html : can't save file '"<<fileName<<"'" << std::endl;
175  return false;
176  }else{
177  std::cerr << "platexobj_html : save file '"<<fileName<<"'" << std::endl;
178  }
179  return true;
180 
181 
182 }
183 
184 
Entry in the bibliography.
Definition: PLatexObj.h:409
const PString & getUrl() const
Gets the url of the PBiblioEntry.
Definition: PLatexObj.cpp:2075
const PBiblioEntryType::PBiblioEntryType & getType() const
Gets the type of the PBiblioEntry.
Definition: PLatexObj.cpp:1907
const PString & getAuthor() const
Gets the author of the PBiblioEntry.
Definition: PLatexObj.cpp:1935
const PString & getAbstract() const
Gets the abstract of the PBiblioEntry.
Definition: PLatexObj.cpp:2173
const PString & getTitle() const
Gets the title of the PBiblioEntry.
Definition: PLatexObj.cpp:1949
const PString & getVolume() const
Gets the volume of the PBiblioEntry.
Definition: PLatexObj.cpp:1991
const PString & getJournal() const
Gets the journal of the PBiblioEntry.
Definition: PLatexObj.cpp:1963
const PString & getPages() const
Gets the pages of the PBiblioEntry.
Definition: PLatexObj.cpp:2061
const PString & getYear() const
Gets the year of the PBiblioEntry.
Definition: PLatexObj.cpp:2033
size_t getId() const
Gets the id of the PBiblioEntry.
Definition: PLatexObj.cpp:1893
Path of a directory or a file.
Definition: PPath.h:17
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
Extends the std::string.
Definition: PString.h:16
std::string valueToString(const T &val)
Convert a type into a string.
PString convertStrToHtml(const PString &str)
fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux)
PString pbiblio_entryHtml(const PBiblioEntry &bibEntry)
Convert a PBiblioEntry in html.
PString pbiblio_attributeHtml(const PString &attrValue, const PString &balise, const PString &extraText)
Convert a biblio attribute in html.
PString pbiblio_entryTypeToHtml(PBiblioEntryType::PBiblioEntryType type)
Convert a string into an entry type.
PString pbiblio_attributeUrlHtml(const PString &attrValue, const PString &balise)
Convert a biblio attribute in html.
bool pbiblio_entryPage(const PBiblioEntry &bibEntry, const POutoutMode &outputMode)
Convert a PBiblioEntry in html.
PString pbiblio_entryPageHtml(const PBiblioEntry &bibEntry)
Convert a PBiblioEntry in html.
PString pbiblio_html(const PMapBiblioEntry &mapBiblioEntry, const POutoutMode &outputMode)
Save the bibliography in string.
PString createNavigationMenuBiblio(const PString &cssClassName, const POutoutMode &outputMode)
Create the navigation menu.
std::map< PString, PBiblioEntry > PMapBiblioEntry
Describes the map for all PBiblioEntry.
PString getHtmlHeader(const PString &title, bool useMathJax, bool useRemoteMathjax, const PString &currentStyle)
Get the html header.
PString getHtmlFooter()
Output mode of the html backend.
bool isBookTheme
True to activate the book theme.
PString currentStyle
Current style to be used for the generated pages of the site.