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 from HTMLParser import HTMLParser | 5 from HTMLParser import HTMLParser |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import re | 8 import re |
9 | 9 |
10 from data_source import DataSource | 10 from data_source import DataSource |
11 from docs_server_utils import FormatKey | 11 from docs_server_utils import FormatKey |
12 from extensions_paths import INTROS_TEMPLATES, ARTICLES_TEMPLATES | 12 from extensions_paths import INTROS_TEMPLATES, ARTICLES_TEMPLATES |
13 from file_system import FileNotFoundError | 13 from file_system import FileNotFoundError |
14 from future import Future | 14 from future import Future |
15 from third_party.handlebar import Handlebar | 15 from third_party.handlebar import Handlebar |
16 | 16 |
17 | 17 |
18 | 18 |
19 # TODO(kalman): rename this HTMLDataSource or other, then have separate intro | 19 # TODO(kalman): rename this HTMLDataSource or other, then have separate intro |
20 # article data sources created as instances of it. | 20 # article data sources created as instances of it. |
21 class IntroDataSource(DataSource): | 21 class IntroDataSource(DataSource): |
22 '''This class fetches the intros for a given API. From this intro, a table | 22 '''This class fetches the intros for a given API. From this intro, a table |
23 of contents dictionary is created, which contains the headings in the intro. | 23 of contents dictionary is created, which contains the headings in the intro. |
24 ''' | 24 ''' |
25 | 25 |
26 def __init__(self, server_instance, request): | 26 def __init__(self, server_instance, request): |
27 self._template_renderer = server_instance.template_renderer | |
28 self._request = request | 27 self._request = request |
29 self._cache = server_instance.compiled_fs_factory.Create( | 28 self._cache = server_instance.compiled_fs_factory.Create( |
30 server_instance.host_file_system_provider.GetTrunk(), | 29 server_instance.host_file_system_provider.GetTrunk(), |
31 self._MakeIntro, | 30 self._MakeIntro, |
32 IntroDataSource) | 31 IntroDataSource) |
33 self._ref_resolver = server_instance.ref_resolver_factory.Create() | 32 self._ref_resolver = server_instance.ref_resolver_factory.Create() |
34 | 33 |
35 def _MakeIntro(self, intro_path, intro): | 34 def _MakeIntro(self, intro_path, intro): |
36 # Guess the name of the API from the path to the intro. | 35 # Guess the name of the API from the path to the intro. |
37 api_name = os.path.splitext(intro_path.split('/')[-1])[0] | 36 api_name = os.path.splitext(intro_path.split('/')[-1])[0] |
(...skipping 14 matching lines...) Expand all Loading... |
52 except FileNotFoundError: | 51 except FileNotFoundError: |
53 continue | 52 continue |
54 # Not found. Do the first operation again so that we get a stack trace - we | 53 # Not found. Do the first operation again so that we get a stack trace - we |
55 # know that it'll fail. | 54 # know that it'll fail. |
56 get_from_base_path(base_paths[0]) | 55 get_from_base_path(base_paths[0]) |
57 raise AssertionError() | 56 raise AssertionError() |
58 | 57 |
59 def Cron(self): | 58 def Cron(self): |
60 # TODO(kalman): Walk through the intros and articles directory. | 59 # TODO(kalman): Walk through the intros and articles directory. |
61 return Future(value=()) | 60 return Future(value=()) |
OLD | NEW |