OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview This file is the controller for generating extension | 6 * @fileoverview This file is the controller for generating extension |
7 * doc pages. | 7 * doc pages. |
8 * | 8 * |
9 * It expects to have available via XHR (relative path): | 9 * It expects to have available via XHR (relative path): |
10 * 1) API_TEMPLATE which is the main template for the api pages. | 10 * 1) API_TEMPLATE which is the main template for the api pages. |
11 * 2) The files located at MODULE_SCHEMAS which are shared with the extension | 11 * 2) The files located at MODULE_SCHEMAS which are shared with the extension |
12 * system and defines the methods and events contained in one api. | 12 * system and defines the methods and events contained in one api. |
13 * 3) (Possibly) A static version of the current page url in /static/. I.e. | 13 * 3) (Possibly) A static version of the current page url in /static/. I.e. |
14 * if called as ../foo.html, it will look for ../static/foo.html. | 14 * if called as ../foo.html, it will look for ../static/foo.html. |
15 * | 15 * |
16 * The "shell" page may have a renderering already contained within it so that | 16 * The "shell" page may have a renderering already contained within it so that |
17 * the docs can be indexed. | 17 * the docs can be indexed. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 var API_TEMPLATE = 'template/api_template.html'; | 21 var API_TEMPLATE_EXTENSIONS = 'template/api_template.html'; |
| 22 var API_TEMPLATE_APPS = 'template/api_template_apps.html'; |
22 var MODULE_SCHEMAS = [ | 23 var MODULE_SCHEMAS = [ |
23 '../api/alarms.json', // autogenerated | 24 '../api/alarms.json', // autogenerated |
24 '../api/bookmarks.json', | 25 '../api/bookmarks.json', |
25 '../api/browser_action.json', | 26 '../api/browser_action.json', |
26 '../api/browsing_data.json', | 27 '../api/browsing_data.json', |
27 '../api/chrome_auth_private.json', | 28 '../api/chrome_auth_private.json', |
28 '../api/chromeos_info_private.json', | 29 '../api/chromeos_info_private.json', |
29 '../api/content_settings.json', | 30 '../api/content_settings.json', |
30 '../api/context_menus.json', | 31 '../api/context_menus.json', |
31 '../api/cookies.json', | 32 '../api/cookies.json', |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // The page name minus the '.html' extension. | 150 // The page name minus the '.html' extension. |
150 pageBase = document.location.href.match(/\/([^\/]*)\.html/)[1]; | 151 pageBase = document.location.href.match(/\/([^\/]*)\.html/)[1]; |
151 if (!pageBase) { | 152 if (!pageBase) { |
152 alert('Empty page name for: ' + document.location.href); | 153 alert('Empty page name for: ' + document.location.href); |
153 return; | 154 return; |
154 } | 155 } |
155 | 156 |
156 pageName = pageBase.replace(/([A-Z])/g, ' $1'); | 157 pageName = pageBase.replace(/([A-Z])/g, ' $1'); |
157 pageName = pageName.substring(0, 1).toUpperCase() + pageName.substring(1); | 158 pageName = pageName.substring(0, 1).toUpperCase() + pageName.substring(1); |
158 | 159 |
| 160 // TODO(aa): Ugh, this is horrible. The problem is that these files are |
| 161 // rendered at many locations: |
| 162 // |
| 163 // - file:///some/path/on/your/machine/chrome/common/extensions/docs/ |
| 164 // - http://chromeextensionsdocs.appspot.com/ |
| 165 // - code.google.com/chrome/extensions |
| 166 // - etc |
| 167 // |
| 168 // At this point, we don't know what the root is, so we can't know for sure |
| 169 // which path component should be the family. So we just base it off the |
| 170 // current assumption that all our HTML files are currently in the root |
| 171 // directory. |
| 172 var docFamily = location.pathname.split("/"); |
| 173 docFamily = docFamily[docFamily.length - 2]; |
| 174 if (docFamily != "extensions" && docFamily != "apps") |
| 175 docFamily = ""; |
| 176 |
| 177 var apiTemplate = { |
| 178 "extensions": API_TEMPLATE_EXTENSIONS, |
| 179 "apps": API_TEMPLATE_APPS |
| 180 }[docFamily]; |
| 181 |
| 182 if (!apiTemplate) |
| 183 throw new Error("Unexpected doc family: " + docFamily); |
| 184 |
159 // Fetch the api template and insert into the <body>. | 185 // Fetch the api template and insert into the <body>. |
160 fetchContent(API_TEMPLATE, function(templateContent) { | 186 fetchContent(apiTemplate, function(templateContent) { |
161 document.getElementsByTagName('body')[0].innerHTML = templateContent; | 187 document.getElementsByTagName('body')[0].innerHTML = templateContent; |
162 fetchStatic(); | 188 fetchStatic(); |
163 }, function(error) { | 189 }, function(error) { |
164 alert('Failed to load ' + API_TEMPLATE + '. ' + error); | 190 alert('Failed to load ' + API_TEMPLATE + '. ' + error); |
165 }); | 191 }); |
166 } | 192 } |
167 | 193 |
168 function fetchStatic() { | 194 function fetchStatic() { |
169 // Fetch the static content and insert into the 'static' <div>. | 195 // Fetch the static content and insert into the 'static' <div>. |
170 fetchContent(staticResource(pageBase), function(overviewContent) { | 196 fetchContent(staticResource(pageBase), function(overviewContent) { |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 790 } |
765 if (a.name > b.name) { | 791 if (a.name > b.name) { |
766 return 1; | 792 return 1; |
767 } | 793 } |
768 return 0; | 794 return 0; |
769 } | 795 } |
770 | 796 |
771 function disableDocs(obj) { | 797 function disableDocs(obj) { |
772 return !!obj.nodoc; | 798 return !!obj.nodoc; |
773 } | 799 } |
OLD | NEW |