UNPKG

5.17 kBJavaScriptView Raw
1/**
2 * @Route ("/documentation")
3 */
4class documentationController extends nodefony.Controller {
5
6 constructor(container, context) {
7 super(container, context);
8 // start session
9 this.startSession();
10 }
11
12 /**
13 * @Method ({"GET"})
14 * @Route (
15 * "/search",
16 * name="nodefony-search")
17 *
18 */
19 searchAction() {
20 return new Promise((resolve, reject)=>{
21 try {
22 let url = this.generateUrl("nodefony-doc", {
23 bundle: "nodefony"
24 //version: this.defaultVersion
25 }, true);
26 if (this.query.search) {
27 let webCrawler = this.get("webCrawler");
28 webCrawler.siteAll(url, this.query.search, this.context, (data) => {
29 return resolve( this.renderJson(data) );
30 });
31 } else {
32 return resolve(this.renderJson({}));
33 }
34 }catch(e){
35 return reject(e);
36 }
37 });
38
39 }
40
41 /**
42 * @Method ({"GET"})
43 * @Route (
44 * "/notes.html",
45 * name="nodefony-slides-notes")
46 *
47 */
48 notesAction() {
49 this.hideDebugBar();
50 return this.render("documentation:documentation/slides/notes:notes.html.twig");
51 }
52
53 /**
54 * @Method ({"GET"})
55 * @Route (
56 * "/{bundle}/slides",
57 * name="nodefony-slides",
58 * defaults={"bundle" = "nodefony"})
59 *
60 */
61 slidesAction(bundle) {
62 this.hideDebugBar();
63 let readme = null;
64 if (bundle === "nodefony") {
65 readme = path.resolve(this.kernel.rootDir, "README.md");
66 return this.render("documentation:documentation/slides:index.html.twig", {
67 title: "README",
68 readme: this.htmlMdParser(new nodefony.fileClass(readme).content())
69 });
70 } else {
71 return this.forward(`${bundle}:documentation:slides`);
72 }
73 }
74
75 /*slidesServerAction() {
76 this.hideDebugBar();
77 return this.render("documentation:slides:slides-server.html.twig");
78 }
79
80 notesServerAction() {
81 this.hideDebugBar();
82 return this.render("documentation:slides:notes-server.html.twig");
83 }*/
84
85 /**
86 * @Method ({"GET"})
87 * @Route ("/{bundle}",
88 * name="nodefony-doc",
89 * defaults={"bundle" = "nodefony"})
90 */
91 indexAction(bundle) {
92 if (bundle === "nodefony") {
93 return this.render(`documentation:documentation:index.html.twig`, {
94 title: bundle,
95 bundle: this.kernel.bundles,
96 url: this.bundle.settings.github.url
97 });
98 } else {
99 try {
100 return this.forward(`${bundle}:documentation:index`);
101 }catch(e){
102 return this.render(`documentation:documentation:progress.html.twig`, {
103 title: bundle,
104 bundle: bundle
105 });
106 }
107 }
108 }
109
110 /**
111 * @Method ({"GET"})
112 * @Route (
113 * "/{bundle}/readme",
114 * name="nodefony-readme",
115 * defaults={"bundle" = "nodefony"})
116 *
117 */
118 readmeAction(bundle) {
119 let readme = null;
120 if (bundle === "nodefony") {
121 readme = path.resolve(this.kernel.rootDir, "README.md");
122 return this.render("documentation:documentation:readme.html.twig", {
123 title: "README",
124 readme: this.htmlMdParser(new nodefony.fileClass(readme).content(), {
125 linkify: true,
126 typographer: true
127 })
128 });
129 } else {
130 if (this.kernel.bundles[bundle]) {
131 readme = path.resolve(this.kernel.bundles[bundle].path, "README.md");
132 }
133 return this.render(`${bundle}:documentation:readme.html.twig`, {
134 title: "README",
135 readme: this.htmlMdParser(new nodefony.fileClass(readme).content(), {
136 linkify: true,
137 typographer: true
138 })
139 });
140 }
141 }
142
143 /**
144 * @Method ({"GET"})
145 * @Route ("/nodefony/{section}/{subsection}",
146 * defaults={"subsection" = ""},
147 * name="nodefony-doc-index")
148 */
149 nodefonyAction(section, subsection) {
150 if (subsection) {
151 return this.render(`documentation:nodefony/${section}/${subsection}:index.html.twig`, {});
152 }
153 return this.render(`documentation:nodefony/${section}:index.html.twig`, {});
154 }
155
156
157 /**
158 * @Method ({ "GET"})
159 * @Route ("/lang", name="nodefony-doc-lang")
160 */
161 langAction() {
162 if (this.query.language) {
163 if (this.session) {
164 this.session.set("lang", this.query.language);
165 let route = this.session.getMetaBag("lastRoute");
166 if (route) {
167 return this.redirect(this.url(route));
168 }
169 }
170 }
171 let referer = this.request.getHeader("referer");
172 if (referer) {
173 return this.redirect(referer);
174 }
175 return this.redirect("/");
176 }
177
178 /**
179 *
180 */
181 headerAction(version) {
182 return this.render("documentation:documentation:header.html.twig", {
183 langs: this.get("translation").getLangs(),
184 locale: this.getLocale(),
185 version: version || this.defaultVersion,
186 bundle: "nodefony"
187 });
188 }
189
190 /**
191 *
192 */
193 footerAction() {
194 let version = this.kernel.settings.version;
195 return this.render("documentation:documentation:footer.html.twig", {
196 version: version,
197 year: new Date().getFullYear()
198 });
199 }
200
201}
202
203module.exports = documentationController;