| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 from xml.dom import minidom | 7 from xml.dom import minidom |
| 8 from grit import lazy_re | 8 from grit import lazy_re |
| 9 from grit.format.policy_templates.writers import xml_formatted_writer | 9 from grit.format.policy_templates.writers import xml_formatted_writer |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 replaced with links and the possible choices are enumerated in case | 109 replaced with links and the possible choices are enumerated in case |
| 110 of 'string-enum' and 'int-enum' type policies. | 110 of 'string-enum' and 'int-enum' type policies. |
| 111 | 111 |
| 112 Args: | 112 Args: |
| 113 parent: The DOM node for which the feature list will be added. | 113 parent: The DOM node for which the feature list will be added. |
| 114 policy: The data structure of a policy. | 114 policy: The data structure of a policy. |
| 115 ''' | 115 ''' |
| 116 # Replace URLs with links in the description. | 116 # Replace URLs with links in the description. |
| 117 self._AddTextWithLinks(parent, policy['desc']) | 117 self._AddTextWithLinks(parent, policy['desc']) |
| 118 # Add list of enum items. | 118 # Add list of enum items. |
| 119 if policy['type'] in ('string-enum', 'int-enum'): | 119 if policy['type'] in ('string-enum', 'int-enum', 'string-enum-list'): |
| 120 ul = self.AddElement(parent, 'ul') | 120 ul = self.AddElement(parent, 'ul') |
| 121 for item in policy['items']: | 121 for item in policy['items']: |
| 122 if policy['type'] == 'int-enum': | 122 if policy['type'] == 'int-enum': |
| 123 value_string = str(item['value']) | 123 value_string = str(item['value']) |
| 124 else: | 124 else: |
| 125 value_string = '"%s"' % item['value'] | 125 value_string = '"%s"' % item['value'] |
| 126 self.AddElement( | 126 self.AddElement( |
| 127 ul, 'li', {}, '%s = %s' % (value_string, item['caption'])) | 127 ul, 'li', {}, '%s = %s' % (value_string, item['caption'])) |
| 128 | 128 |
| 129 def _AddFeatures(self, parent, policy): | 129 def _AddFeatures(self, parent, policy): |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 pieces = [] | 372 pieces = [] |
| 373 if self.IsPolicySupportedOnPlatform(policy, 'win'): | 373 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
| 374 pieces.append('0x%08x (Windows)' % example_value) | 374 pieces.append('0x%08x (Windows)' % example_value) |
| 375 if self.IsPolicySupportedOnPlatform(policy, 'linux'): | 375 if self.IsPolicySupportedOnPlatform(policy, 'linux'): |
| 376 pieces.append('%d (Linux)' % example_value) | 376 pieces.append('%d (Linux)' % example_value) |
| 377 if self.IsPolicySupportedOnPlatform(policy, 'mac'): | 377 if self.IsPolicySupportedOnPlatform(policy, 'mac'): |
| 378 pieces.append('%d (Mac)' % example_value) | 378 pieces.append('%d (Mac)' % example_value) |
| 379 self.AddText(parent, ', '.join(pieces)) | 379 self.AddText(parent, ', '.join(pieces)) |
| 380 elif policy_type == 'string-enum': | 380 elif policy_type == 'string-enum': |
| 381 self.AddText(parent, '"%s"' % (example_value)) | 381 self.AddText(parent, '"%s"' % (example_value)) |
| 382 elif policy_type == 'list': | 382 elif policy_type in ('list', 'string-enum-list'): |
| 383 self._AddListExample(parent, policy) | 383 self._AddListExample(parent, policy) |
| 384 elif policy_type == 'dict': | 384 elif policy_type == 'dict': |
| 385 self._AddDictionaryExample(parent, policy) | 385 self._AddDictionaryExample(parent, policy) |
| 386 else: | 386 else: |
| 387 raise Exception('Unknown policy type: ' + policy_type) | 387 raise Exception('Unknown policy type: ' + policy_type) |
| 388 | 388 |
| 389 def _AddPolicyAttribute(self, dl, term_id, | 389 def _AddPolicyAttribute(self, dl, term_id, |
| 390 definition=None, definition_style=None): | 390 definition=None, definition_style=None): |
| 391 '''Adds a term-definition pair to a HTML DOM <dl> node. This method is | 391 '''Adds a term-definition pair to a HTML DOM <dl> node. This method is |
| 392 used by _AddPolicyDetails. Its result will have the form of: | 392 used by _AddPolicyDetails. Its result will have the form of: |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 if message.startswith('doc_feature_'): | 633 if message.startswith('doc_feature_'): |
| 634 self._FEATURE_MAP[message[12:]] = self.messages[message]['text'] | 634 self._FEATURE_MAP[message[12:]] = self.messages[message]['text'] |
| 635 # Human-readable names of types. | 635 # Human-readable names of types. |
| 636 self._TYPE_MAP = { | 636 self._TYPE_MAP = { |
| 637 'string': 'String', | 637 'string': 'String', |
| 638 'int': 'Integer', | 638 'int': 'Integer', |
| 639 'main': 'Boolean', | 639 'main': 'Boolean', |
| 640 'int-enum': 'Integer', | 640 'int-enum': 'Integer', |
| 641 'string-enum': 'String', | 641 'string-enum': 'String', |
| 642 'list': 'List of strings', | 642 'list': 'List of strings', |
| 643 'string-enum-list': 'List of strings', |
| 643 'dict': 'Dictionary', | 644 'dict': 'Dictionary', |
| 644 'external': 'External data reference', | 645 'external': 'External data reference', |
| 645 } | 646 } |
| 646 self._REG_TYPE_MAP = { | 647 self._REG_TYPE_MAP = { |
| 647 'string': 'REG_SZ', | 648 'string': 'REG_SZ', |
| 648 'int': 'REG_DWORD', | 649 'int': 'REG_DWORD', |
| 649 'main': 'REG_DWORD', | 650 'main': 'REG_DWORD', |
| 650 'int-enum': 'REG_DWORD', | 651 'int-enum': 'REG_DWORD', |
| 651 'string-enum': 'REG_SZ', | 652 'string-enum': 'REG_SZ', |
| 652 'dict': 'REG_SZ, encoded as a JSON string', | 653 'dict': 'REG_SZ, encoded as a JSON string', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 673 } | 674 } |
| 674 | 675 |
| 675 # A simple regexp to search for URLs. It is enough for now. | 676 # A simple regexp to search for URLs. It is enough for now. |
| 676 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') | 677 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
| 677 | 678 |
| 678 def GetTemplateText(self): | 679 def GetTemplateText(self): |
| 679 # Return the text representation of the main <div> tag. | 680 # Return the text representation of the main <div> tag. |
| 680 return self._main_div.toxml() | 681 return self._main_div.toxml() |
| 681 # To get a complete HTML file, use the following. | 682 # To get a complete HTML file, use the following. |
| 682 # return self._doc.toxml() | 683 # return self._doc.toxml() |
| OLD | NEW |