| 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 collections | 5 import collections |
| 6 | 6 |
| 7 import easy_template | 7 import easy_template |
| 8 | 8 |
| 9 def CmpByName(x, y): | 9 def CmpByName(x, y): |
| 10 return cmp(x['NAME'], y['NAME']) | 10 return cmp(x['NAME'], y['NAME']) |
| 11 | 11 |
| 12 class LandingPage(object): | 12 class LandingPage(object): |
| 13 def __init__(self): | 13 def __init__(self): |
| 14 self.section_list = ['Getting Started', 'API', 'Demo', 'Tutorial'] | 14 self.section_list = ['Getting Started', 'API', 'Demo', 'Tutorial'] |
| 15 self.section_map = collections.defaultdict(list) | 15 self.section_map = collections.defaultdict(list) |
| 16 | 16 |
| 17 def GeneratePage(self, template_path): | 17 def GeneratePage(self, template_path): |
| 18 with open(template_path) as template_file: | 18 with open(template_path) as template_file: |
| 19 template = template_file.read() | 19 template = template_file.read() |
| 20 | 20 |
| 21 sec_map = {} | 21 sec_map = {} |
| 22 for section_name in self.section_map: | 22 for section_name in self.section_map: |
| 23 items = self.section_map[section_name] | 23 items = self.section_map[section_name] |
| 24 items = sorted(items, cmp=CmpByName) | 24 items = sorted(items, cmp=CmpByName) |
| 25 sec_map[section_name] = items | 25 sec_map[section_name] = items |
| 26 print 'Add section ' + section_name | |
| 27 | 26 |
| 28 template_dict = { 'section_map': sec_map } | 27 template_dict = { 'section_map': sec_map } |
| 29 return easy_template.RunTemplateString(template, template_dict) | 28 return easy_template.RunTemplateString(template, template_dict) |
| 30 | 29 |
| 31 def AddDesc(self, desc): | 30 def AddDesc(self, desc): |
| 32 group = desc['GROUP'] | 31 group = desc['GROUP'] |
| 33 assert group in self.section_list | 32 assert group in self.section_list |
| 34 self.section_map[group].append(desc) | 33 self.section_map[group].append(desc) |
| OLD | NEW |