Commit 421fbb0e authored by cduvall@chromium.org's avatar cduvall@chromium.org

Extensions Docs Server: Proper path handling

The docs now use paths with the branch first, like 'trunk/apps/storage.html'
instead of paths like 'apps/trunk/storage.html'.

Also a couple other fixes to the samples page.

BUG=131095

Review URL: https://chromiumcodereview.appspot.com/10826173

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150168 0039d316-1c4b-4281-b951-d872f2087c98
parent 772c3757
...@@ -15,22 +15,15 @@ class BranchUtility(object): ...@@ -15,22 +15,15 @@ class BranchUtility(object):
self._memcache = memcache self._memcache = memcache
def SplitChannelNameFromPath(self, path): def SplitChannelNameFromPath(self, path):
prefix = ''
if path.startswith('extensions/'):
prefix = 'extensions/'
path = path[len('extensions/'):]
elif path.startswith('apps/'):
prefix = 'apps/'
path = path[len('apps/'):]
try: try:
first, second = path.split('/', 1) first, second = path.split('/', 1)
except ValueError: except ValueError:
first = path first = path
second = '' second = ''
if first in ['trunk', 'dev', 'beta', 'stable']: if first in ['trunk', 'dev', 'beta', 'stable']:
return (first, prefix + second) return (first, second)
else: else:
return (self._default_branch, prefix + path) return (self._default_branch, path)
def GetBranchNumberForChannelName(self, channel_name): def GetBranchNumberForChannelName(self, channel_name):
"""Returns an empty string if the branch number cannot be found. """Returns an empty string if the branch number cannot be found.
......
...@@ -128,10 +128,10 @@ class Handler(webapp.RequestHandler): ...@@ -128,10 +128,10 @@ class Handler(webapp.RequestHandler):
if '_ah/warmup' in path: if '_ah/warmup' in path:
logging.info('Warmup request.') logging.info('Warmup request.')
if DEFAULT_BRANCH != 'local': if DEFAULT_BRANCH != 'local':
self._NavigateToPath('extensions/trunk/samples.html') self._NavigateToPath('trunk/extensions/samples.html')
self._NavigateToPath('extensions/dev/samples.html') self._NavigateToPath('dev/extensions/samples.html')
self._NavigateToPath('extensions/beta/samples.html') self._NavigateToPath('beta/extensions/samples.html')
self._NavigateToPath('extensions/stable/samples.html') self._NavigateToPath('stable/extensions/samples.html')
return return
# Redirect paths like "directory" to "directory/". This is so relative file # Redirect paths like "directory" to "directory/". This is so relative file
......
...@@ -95,7 +95,7 @@ class SamplesDataSource(object): ...@@ -95,7 +95,7 @@ class SamplesDataSource(object):
if l10n_data['icon'] is None: if l10n_data['icon'] is None:
icon_path = self._static_path + DEFAULT_ICON_PATH icon_path = self._static_path + DEFAULT_ICON_PATH
else: else:
icon_path = sample_base_path + '/' + l10n_data['icon'] icon_path = '/' + sample_base_path + '/' + l10n_data['icon']
l10n_data.update({ l10n_data.update({
'icon': icon_path, 'icon': icon_path,
'path': sample_base_path, 'path': sample_base_path,
......
...@@ -36,11 +36,13 @@ class ServerInstance(object): ...@@ -36,11 +36,13 @@ class ServerInstance(object):
def Get(self, path, request, response): def Get(self, path, request, response):
templates = self._template_data_source_factory.Create(request) templates = self._template_data_source_factory.Create(request)
if fnmatch(path, 'examples/*.zip'): if fnmatch(path, 'extensions/examples/*.zip'):
content = self._example_zipper.Create(path[:-len('.zip')]) content = self._example_zipper.Create(
path[len('extensions/'):-len('.zip')])
response.headers['content-type'] = mimetypes.types_map['.zip'] response.headers['content-type'] = mimetypes.types_map['.zip']
elif path.startswith('examples/'): elif path.startswith('extensions/examples/'):
content = self._cache.GetFromFile(DOCS_PATH + '/' + path) content = self._cache.GetFromFile(
DOCS_PATH + '/' + path[len('extensions/'):])
response.headers['content-type'] = 'text/plain' response.headers['content-type'] = 'text/plain'
elif path.startswith('static/'): elif path.startswith('static/'):
content = self._FetchStaticResource(path, response) content = self._FetchStaticResource(path, response)
......
...@@ -9,12 +9,14 @@ ...@@ -9,12 +9,14 @@
return; return;
var current_branch = window.bootstrap.branchInfo.current; var current_branch = window.bootstrap.branchInfo.current;
var path = window.location.pathname.split('/'); var path = window.location.pathname.split('/');
if (path[0] == '')
path = path.slice(1);
var index = path.indexOf(current_branch); var index = path.indexOf(current_branch);
if (index != -1) if (index != -1)
path[index] = value; path[index] = value;
else else
path.splice(path.length - 1, 0, value); path.splice(0, 0, value);
window.location = path.join('/'); window.location = '/' + path.join('/');
} }
document.getElementById('branchChooser').addEventListener( document.getElementById('branchChooser').addEventListener(
......
...@@ -14,12 +14,11 @@ ...@@ -14,12 +14,11 @@
{{?is_apps}} {{?is_apps}}
api_names: {{*api_list.apps.chrome}}.concat( api_names: {{*api_list.apps.chrome}}.concat(
{{*api_list.apps.experimental}}), {{*api_list.apps.experimental}}),
branchInfo: {{*branchInfo}}
{{:is_apps}} {{:is_apps}}
api_names: {{*api_list.extensions.chrome}}.concat( api_names: {{*api_list.extensions.chrome}}.concat(
{{*api_list.extensions.experimental}}), {{*api_list.extensions.experimental}}),
branchInfo: {{*branchInfo}}
{{/is_apps}} {{/is_apps}}
branchInfo: {{*branchInfo}}
}; };
</script> </script>
<script src="{{static}}/js/branch.js" type="text/javascript"></script> <script src="{{static}}/js/branch.js" type="text/javascript"></script>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<td class="label">Filter by API:</td> <td class="label">Filter by API:</td>
<td> <td>
<div id="api_filter_items"> <div id="api_filter_items">
{{#api_list.chrome}} {{#api_list.extensions.chrome}}
<span><a href="javascript:void(0)">{{name}}</a>{{^last}} | {{/}}</span> <span><a href="javascript:void(0)">{{name}}</a>{{^last}} | {{/}}</span>
{{/}} {{/}}
</div> </div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment