PhoenixLecture  2.0.0
Set of tools to make lectures
platexobj_menu.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 "platexobj_html.h"
8 #include "platexobj_text.h"
9 
10 #include "platexobj_menu.h"
11 
12 
14 
17 void platexobj_toMenuAll(PFullMenu & menu, const PLatexObj & obj){
18  PString complextTitle(platexobj_text(obj.getComplexTitle()));
19  PString objTitle("<strong aria-hidden=\"true\">" + vecNumberToString(obj.getVecSecNumber()) + ".</strong> " + complextTitle); //Content of the section title
20  PLatexType::PLatexType type(obj.getType());
21  menu.setLink(obj.getLink());
22  if(type == PLatexType::PART){menu.setText(/*"Part " +*/ objTitle);}
23  else if(type == PLatexType::CHAPTER){menu.setText(/*"Chapter " +*/ objTitle);}
24  else if(type == PLatexType::SECTION){menu.setText(objTitle);}
25  else if(type == PLatexType::SUBSECTION){menu.setText(objTitle);}
26  else if(type == PLatexType::SUBSUBSECTION){menu.setText(objTitle);}
27  else if(type == PLatexType::FILE){menu.setText(obj.getName());}
28  else if(type == PLatexType::BOOKPARTSEPARATOR){
29  menu.setText(complextTitle);
30  menu.setIsSeparator(true);
31  }
32 
33  const std::vector<PLatexObj> & vecChildren = obj.getVecContent();
34  for(std::vector<PLatexObj>::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
35  if(!isSectionOrSeparator(*it)){continue;}
36  PFullMenu subMenu;
37  platexobj_toMenuAll(subMenu, *it);
38  menu.getVecSubMenu().push_back(subMenu);
39  }
40 }
41 
42 
44 
48 PFullMenu platexobj_toMenu(const PLatexObj & obj, const PLatexObj & mainPageLink){
49  PFullMenu menu;
50  platexobj_toMenuAll(menu, obj);
51  if(mainPageLink.getType() == PLatexType::BOOKMAINPAGELINK){
52  PString textMainPage(platexobj_text(mainPageLink.getVecContent()));
53  if(textMainPage != ""){
54  menu.setMainPageLink(textMainPage);
55  }else{
56  menu.setMainPageLink("Main Page");
57  }
58  }else{
59  menu.setMainPageLink("Main Page");
60  }
61  return menu;
62 }
63 
65 
69 PString platexobj_menuToHtmlChapter(const PFullMenu & menu, const PString & indentation){
70  PString body(""), link(menu.getLink()), text(menu.getText());
71  PString displayList("");
72  if(menu.getIsSeparator()){
73  body += indentation + "<li class=\"chapter-item affix \"><li class=\"part-title\">"+text+"</li>\n";
74  }else{
75  if(menu.getIsExpanded()){
76  displayList = "expanded";
77  if(menu.getIsFirstExpanded()){
78  displayList += " active";
79  }
80  }
81  body += indentation + "<li class=\"chapter-item "+displayList+"\"><a href=\""+link+"\">"+text+"</a>";
82 
83  const std::vector<PFullMenu> & vecSubMenu = menu.getVecSubMenu();
84  if(vecSubMenu.size() != 0lu){
85  body += "<a class=\"toggle\"><div>❱</div></a></li>\n";
86  body += indentation + "<li>\n";
87  body += indentation + "\t<ol class=\"section\">\n";
88  for(std::vector<PFullMenu>::const_iterator it(vecSubMenu.begin()); it != vecSubMenu.end(); ++it){
89  body += platexobj_menuToHtmlChapter(*it, indentation + "\t\t");
90  }
91  body += indentation + "\t</ol>\n";
92  body += indentation + "</li>\n";
93  }else{
94  body += "</li>\n";
95  }
96  }
97  return body;
98 }
99 
101 
104 bool platexobg_isMenuExtanded(const PFullMenu & menu, const PString & currentLink){
105  return menu.getLink() == currentLink;
106 }
107 
109 
112 void platexobj_makeExpandMenu(PFullMenu & menu, const PString & currentLink){
113  bool isFirstExtended(platexobg_isMenuExtanded(menu, currentLink)); //Check if the current section has to be expanded
114  menu.setIsFirstExpanded(isFirstExtended);
115  bool isExtended(isFirstExtended);
116  std::vector<PFullMenu> & vecSubMenu = menu.getVecSubMenu();
117  std::vector<PFullMenu>::iterator it(vecSubMenu.begin());
118  while(!isExtended && it != vecSubMenu.end()){
119  platexobj_makeExpandMenu(*it, currentLink);
120  isExtended = it->getIsExpanded();
121  ++it;
122  }
123  menu.setIsExpanded(isExtended);
124 }
125 
127 
132 PString platexobj_menuToHtml(const PFullMenu & menu, const PString & currentLink, bool isBibliography){
133  PFullMenu expandedMenu(menu);
134  platexobj_makeExpandMenu(expandedMenu, currentLink);
135 
136  PString body(""), indentation("\t\t");
137  body += indentation+"<nav id=\"sidebar\" class=\"sidebar\" aria-label=\"Table of contents\">\n";
138  body += indentation+"\t<div class=\"sidebar-scrollbox\">\n";
139  body += indentation+"\t\t<ol class=\"chapter\">\n";
140  body += indentation + "\t\t\t<li class=\"chapter-item \"><a href=\"index.html\">"+menu.getMainPageLink()+"</a></li>\n";
141  const std::vector<PFullMenu> & vecSubMenu = expandedMenu.getVecSubMenu();
142  for(std::vector<PFullMenu>::const_iterator it(vecSubMenu.begin()); it != vecSubMenu.end(); ++it){
143  body += platexobj_menuToHtmlChapter(*it, indentation+"\t\t\t");
144  }
145  if(isBibliography){
146  body += indentation + "\t\t\t<li class=\"chapter-item \"><a href=\"bibliography.html\">Bibliography</a></li>\n";
147  }
148 
149  body += indentation+"\t\t</ol>\n";
150  body += indentation+"\t</div>\n";
151  body += indentation+"\t<div id=\"sidebar-resize-handle\" class=\"sidebar-resize-handle\"></div>\n";
152  body += indentation+"</nav>\n";
153  return body;
154 }
155 
156 
Full menu of all site.
Definition: PLatexObj.h:168
void setText(const PString &text)
Sets the text of the PFullMenu.
Definition: PLatexObj.cpp:708
void setMainPageLink(const PString &mainPageLink)
Sets the mainPageLink of the PFullMenu.
Definition: PLatexObj.cpp:722
bool getIsSeparator() const
Gets the isSeparator of the PFullMenu.
Definition: PLatexObj.cpp:757
const PString & getLink() const
Gets the link of the PFullMenu.
Definition: PLatexObj.cpp:771
void setIsFirstExpanded(bool isFirstExpanded)
Sets the isFirstExpanded of the PFullMenu.
Definition: PLatexObj.cpp:687
void setLink(const PString &link)
Sets the link of the PFullMenu.
Definition: PLatexObj.cpp:701
bool getIsExpanded() const
Gets the isExpanded of the PFullMenu.
Definition: PLatexObj.cpp:729
void setIsSeparator(bool isSeparator)
Sets the isSeparator of the PFullMenu.
Definition: PLatexObj.cpp:694
void setIsExpanded(bool isExpanded)
Sets the isExpanded of the PFullMenu.
Definition: PLatexObj.cpp:680
const PString & getText() const
Gets the text of the PFullMenu.
Definition: PLatexObj.cpp:785
const PString & getMainPageLink() const
Gets the mainPageLink of the PFullMenu.
Definition: PLatexObj.cpp:813
const std::vector< PFullMenu > & getVecSubMenu() const
Gets the vecSubMenu of the PFullMenu.
Definition: PLatexObj.cpp:799
bool getIsFirstExpanded() const
Gets the isFirstExpanded of the PFullMenu.
Definition: PLatexObj.cpp:743
Describe a latex object.
Definition: PLatexObj.h:40
const std::vector< PLatexObj > & getVecContent() const
Gets the vecContent of the PLatexObj.
Definition: PLatexObj.cpp:410
const std::vector< PLatexObj > & getComplexTitle() const
Gets the complexTitle of the PLatexObj.
Definition: PLatexObj.cpp:396
const PLatexType::PLatexType & getType() const
Gets the type of the PLatexObj.
Definition: PLatexObj.cpp:298
const PString & getName() const
Gets the name of the PLatexObj.
Definition: PLatexObj.cpp:326
const PString & getLink() const
Gets the link of the PLatexObj.
Definition: PLatexObj.cpp:368
const std::vector< long unsigned int > & getVecSecNumber() const
Gets the vecSecNumber of the PLatexObj.
Definition: PLatexObj.cpp:438
Extends the std::string.
Definition: PString.h:16
PLatexType
Type of the PLatexObj.
Definition: PLatexType.h:12
@ SUBSUBSECTION
Definition: PLatexType.h:54
@ BOOKMAINPAGELINK
Definition: PLatexType.h:65
@ BOOKPARTSEPARATOR
Definition: PLatexType.h:64
PString vecNumberToString(const std::vector< long unsigned int > &vecNb)
Convert a vector of numbers into a string.
PString platexobj_menuToHtmlChapter(const PFullMenu &menu, const PString &indentation)
Convert a PFullMenu to html.
void platexobj_toMenuAll(PFullMenu &menu, const PLatexObj &obj)
Convert a PLatexObj into a menu.
PFullMenu platexobj_toMenu(const PLatexObj &obj, const PLatexObj &mainPageLink)
Convert a PLatexObj into a menu.
void platexobj_makeExpandMenu(PFullMenu &menu, const PString &currentLink)
Update menus which are supposed to be extended.
bool platexobg_isMenuExtanded(const PFullMenu &menu, const PString &currentLink)
Say if the current menu has to be extended.
PString platexobj_menuToHtml(const PFullMenu &menu, const PString &currentLink, bool isBibliography)
Convert a PFullMenu to html.
PString platexobj_text(const std::vector< PLatexObj > &vecObj)
Convert a PLatexObj in text.
bool isSectionOrSeparator(const PLatexObj &obj)
Say if the PLatexObj is a part, charpter, section, subsection, subsubsection or a book separator.