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 json | 6 import json |
7 | 7 |
8 import compiled_file_system as compiled_fs | |
9 from third_party.json_schema_compiler.model import UnixName | |
10 | |
11 class SidenavDataSource(object): | 8 class SidenavDataSource(object): |
12 """This class reads in and caches a JSON file representing the side navigation | 9 """This class reads in and caches a JSON file representing the side navigation |
13 menu. | 10 menu. |
14 """ | 11 """ |
15 class Factory(object): | 12 class Factory(object): |
16 def __init__(self, compiled_fs_factory, json_path): | 13 def __init__(self, compiled_fs_factory, json_path): |
17 self._cache = compiled_fs_factory.Create(self._CreateSidenavDict, | 14 self._cache = compiled_fs_factory.Create(self._CreateSidenavDict, |
18 SidenavDataSource) | 15 SidenavDataSource) |
19 self._json_path = json_path | 16 self._json_path = json_path |
20 | 17 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) | 63 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) |
67 href = '/' + href | 64 href = '/' + href |
68 item['href'] = href | 65 item['href'] = href |
69 | 66 |
70 def get(self, key): | 67 def get(self, key): |
71 sidenav = copy.deepcopy(self._cache.GetFromFile( | 68 sidenav = copy.deepcopy(self._cache.GetFromFile( |
72 '%s/%s_sidenav.json' % (self._json_path, key))) | 69 '%s/%s_sidenav.json' % (self._json_path, key))) |
73 self._AddSelected(sidenav) | 70 self._AddSelected(sidenav) |
74 self._QualifyHrefs(sidenav) | 71 self._QualifyHrefs(sidenav) |
75 return sidenav | 72 return sidenav |
OLD | NEW |