summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/build_tools/generate_index.py
blob: 4061165b13c43661cb33b0b5f007df97daf90d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import collections

import easy_template

def CmpByName(x, y):
  return cmp(x['NAME'], y['NAME'])
  
class LandingPage(object):
  def __init__(self):
    self.section_list = ['Getting Started', 'API', 'Demo', 'Tutorial']
    self.section_map = collections.defaultdict(list)

  def GeneratePage(self, template_path):
    with open(template_path) as template_file:
      template = template_file.read()

    sec_map = {}
    for section_name in self.section_map:
      items = self.section_map[section_name]
      items = sorted(items, cmp=CmpByName)
      sec_map[section_name] = items

    template_dict = { 'section_map': sec_map }
    return easy_template.RunTemplateString(template, template_dict)

  def AddDesc(self, desc):
    group = desc['GROUP']
    assert group in self.section_list
    self.section_map[group].append(desc)