| 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, base_path): | 13 def __init__(self, compiled_fs_factory, json_path, base_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 self._base_path = base_path | 17 self._base_path = base_path |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) | 68 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) |
| 72 href = '/' + href | 69 href = '/' + href |
| 73 item['href'] = '%s%s' % (self._file_dir, href) | 70 item['href'] = '%s%s' % (self._file_dir, href) |
| 74 | 71 |
| 75 def get(self, key): | 72 def get(self, key): |
| 76 sidenav = copy.deepcopy(self._cache.GetFromFile( | 73 sidenav = copy.deepcopy(self._cache.GetFromFile( |
| 77 '%s/%s_sidenav.json' % (self._json_path, key))) | 74 '%s/%s_sidenav.json' % (self._json_path, key))) |
| 78 self._AddSelected(sidenav) | 75 self._AddSelected(sidenav) |
| 79 self._QualifyHrefs(sidenav) | 76 self._QualifyHrefs(sidenav) |
| 80 return sidenav | 77 return sidenav |
| OLD | NEW |