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 import copy | 5 import copy |
6 import logging | 6 import logging |
7 import posixpath | 7 import posixpath |
8 | 8 |
9 from compiled_file_system import SingleFile, Unicode | 9 from compiled_file_system import Cache, SingleFile, Unicode |
10 from data_source import DataSource | 10 from data_source import DataSource |
11 from extensions_paths import JSON_TEMPLATES | 11 from extensions_paths import JSON_TEMPLATES |
12 from future import Future | 12 from future import Future |
13 from third_party.json_schema_compiler.json_parse import Parse | 13 from third_party.json_schema_compiler.json_parse import Parse |
14 | 14 |
15 | 15 |
16 def _AddLevels(items, level): | 16 def _AddLevels(items, level): |
17 '''Add a 'level' key to each item in |items|. 'level' corresponds to how deep | 17 '''Add a 'level' key to each item in |items|. 'level' corresponds to how deep |
18 in |items| an item is. |level| sets the starting depth. | 18 in |items| an item is. |level| sets the starting depth. |
19 ''' | 19 ''' |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 navigation bar. | 58 navigation bar. |
59 ''' | 59 ''' |
60 def __init__(self, server_instance, request): | 60 def __init__(self, server_instance, request): |
61 self._cache = server_instance.compiled_fs_factory.Create( | 61 self._cache = server_instance.compiled_fs_factory.Create( |
62 server_instance.host_file_system_provider.GetTrunk(), | 62 server_instance.host_file_system_provider.GetTrunk(), |
63 self._CreateSidenavDict, | 63 self._CreateSidenavDict, |
64 SidenavDataSource) | 64 SidenavDataSource) |
65 self._server_instance = server_instance | 65 self._server_instance = server_instance |
66 self._request = request | 66 self._request = request |
67 | 67 |
| 68 @Cache |
68 @SingleFile | 69 @SingleFile |
69 @Unicode | 70 @Unicode |
70 def _CreateSidenavDict(self, _, content): | 71 def _CreateSidenavDict(self, _, content): |
71 items = Parse(content) | 72 items = Parse(content) |
72 # Start at level 2, the top <ul> element is level 1. | 73 # Start at level 2, the top <ul> element is level 1. |
73 _AddLevels(items, level=2) | 74 _AddLevels(items, level=2) |
74 self._QualifyHrefs(items) | 75 self._QualifyHrefs(items) |
75 return items | 76 return items |
76 | 77 |
77 def _QualifyHrefs(self, items): | 78 def _QualifyHrefs(self, items): |
(...skipping 19 matching lines...) Expand all Loading... |
97 | 98 |
98 def get(self, key): | 99 def get(self, key): |
99 # TODO(mangini/kalman): Use |key| to decide which sidenav to use, | 100 # TODO(mangini/kalman): Use |key| to decide which sidenav to use, |
100 # which will require a more complex Cron method. | 101 # which will require a more complex Cron method. |
101 sidenav = self._cache.GetFromFile( | 102 sidenav = self._cache.GetFromFile( |
102 posixpath.join(JSON_TEMPLATES, 'chrome_sidenav.json')).Get() | 103 posixpath.join(JSON_TEMPLATES, 'chrome_sidenav.json')).Get() |
103 sidenav = copy.deepcopy(sidenav) | 104 sidenav = copy.deepcopy(sidenav) |
104 _AddAnnotations(sidenav, | 105 _AddAnnotations(sidenav, |
105 self._server_instance.base_path + self._request.path) | 106 self._server_instance.base_path + self._request.path) |
106 return sidenav | 107 return sidenav |
OLD | NEW |