Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(894)

Side by Side Diff: grit/node/structure.py

Issue 10386189: Add chrome_html gatherer, which inlines html and automatically generates image set… (Closed) Base URL: http://git.chromium.org/external/grit-i18n.git@master
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« grit/gather/chrome_html.py ('K') | « grit/gather/chrome_html.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '''The <structure> element. 6 '''The <structure> element.
7 ''' 7 '''
8 8
9 import os 9 import os
10 10
11 from grit.node import base 11 from grit.node import base
12 from grit.node import variant 12 from grit.node import variant
13 13
14 from grit import constants 14 from grit import constants
15 from grit import exception 15 from grit import exception
16 from grit import util 16 from grit import util
17 17
18 import grit.gather.admin_template 18 import grit.gather.admin_template
19 import grit.gather.chrome_html
19 import grit.gather.igoogle_strings 20 import grit.gather.igoogle_strings
20 import grit.gather.muppet_strings 21 import grit.gather.muppet_strings
21 import grit.gather.policy_json 22 import grit.gather.policy_json
22 import grit.gather.rc 23 import grit.gather.rc
23 import grit.gather.tr_html 24 import grit.gather.tr_html
24 import grit.gather.txt 25 import grit.gather.txt
25 26
26 import grit.format.rc 27 import grit.format.rc
27 import grit.format.rc_header 28 import grit.format.rc_header
28 29
29 # Type of the gatherer to use for each type attribute 30 # Type of the gatherer to use for each type attribute
30 _GATHERERS = { 31 _GATHERERS = {
31 'accelerators' : grit.gather.rc.Accelerators, 32 'accelerators' : grit.gather.rc.Accelerators,
32 'admin_template' : grit.gather.admin_template.AdmGatherer, 33 'admin_template' : grit.gather.admin_template.AdmGatherer,
34 'chrome_html' : grit.gather.chrome_html.ChromeHtml,
33 'dialog' : grit.gather.rc.Dialog, 35 'dialog' : grit.gather.rc.Dialog,
34 'igoogle' : grit.gather.igoogle_strings.IgoogleStrings, 36 'igoogle' : grit.gather.igoogle_strings.IgoogleStrings,
35 'menu' : grit.gather.rc.Menu, 37 'menu' : grit.gather.rc.Menu,
36 'muppet' : grit.gather.muppet_strings.MuppetStrings, 38 'muppet' : grit.gather.muppet_strings.MuppetStrings,
37 'rcdata' : grit.gather.rc.RCData, 39 'rcdata' : grit.gather.rc.RCData,
38 'tr_html' : grit.gather.tr_html.TrHtml, 40 'tr_html' : grit.gather.tr_html.TrHtml,
39 'txt' : grit.gather.txt.TxtFile, 41 'txt' : grit.gather.txt.TxtFile,
40 'version' : grit.gather.rc.Version, 42 'version' : grit.gather.rc.Version,
41 'policy_template_metafile' : grit.gather.policy_json.PolicyJson, 43 'policy_template_metafile' : grit.gather.policy_json.PolicyJson,
42 } 44 }
43 45
44 46
45 # Formatter instance to use for each type attribute 47 # Formatter instance to use for each type attribute
46 # when formatting .rc files. 48 # when formatting .rc files.
47 _RC_FORMATTERS = { 49 _RC_FORMATTERS = {
48 'accelerators' : grit.format.rc.RcSection(), 50 'accelerators' : grit.format.rc.RcSection(),
49 'admin_template' : grit.format.rc.RcInclude('ADM'), 51 'admin_template' : grit.format.rc.RcInclude('ADM'),
52 'chrome_html' : grit.format.rc.RcInclude('HTML'),
50 'dialog' : grit.format.rc.RcSection(), 53 'dialog' : grit.format.rc.RcSection(),
51 'igoogle' : grit.format.rc.RcInclude('XML'), 54 'igoogle' : grit.format.rc.RcInclude('XML'),
52 'menu' : grit.format.rc.RcSection(), 55 'menu' : grit.format.rc.RcSection(),
53 'muppet' : grit.format.rc.RcInclude('XML'), 56 'muppet' : grit.format.rc.RcInclude('XML'),
54 'rcdata' : grit.format.rc.RcSection(), 57 'rcdata' : grit.format.rc.RcSection(),
55 'tr_html' : grit.format.rc.RcInclude('HTML'), 58 'tr_html' : grit.format.rc.RcInclude('HTML'),
56 'txt' : grit.format.rc.RcInclude('TXT'), 59 'txt' : grit.format.rc.RcInclude('TXT'),
57 'version' : grit.format.rc.RcSection(), 60 'version' : grit.format.rc.RcSection(),
58 'policy_template_metafile': None, 61 'policy_template_metafile': None,
59 } 62 }
(...skipping 19 matching lines...) Expand all
79 82
80 def DefaultAttributes(self): 83 def DefaultAttributes(self):
81 return { 'encoding' : 'cp1252', 84 return { 'encoding' : 'cp1252',
82 'exclude_from_rc' : 'false', 85 'exclude_from_rc' : 'false',
83 'line_end' : 'unix', 86 'line_end' : 'unix',
84 'output_encoding' : 'utf-8', 87 'output_encoding' : 'utf-8',
85 'generateid': 'true', 88 'generateid': 'true',
86 'expand_variables' : 'false', 89 'expand_variables' : 'false',
87 'output_filename' : '', 90 'output_filename' : '',
88 'fold_whitespace': 'false', 91 'fold_whitespace': 'false',
92 'scale_factors' : '',
89 'run_command' : '', 93 'run_command' : '',
90 # TODO(joi) this is a hack - should output all generated files 94 # TODO(joi) this is a hack - should output all generated files
91 # as SCons dependencies; however, for now there is a bug I can't 95 # as SCons dependencies; however, for now there is a bug I can't
92 # find where GRIT doesn't build the matching fileset, therefore 96 # find where GRIT doesn't build the matching fileset, therefore
93 # this hack so that only the files you really need are marked as 97 # this hack so that only the files you really need are marked as
94 # dependencies. 98 # dependencies.
95 'sconsdep' : 'false', 99 'sconsdep' : 'false',
96 } 100 }
97 101
98 def IsExcludedFromRc(self): 102 def IsExcludedFromRc(self):
(...skipping 12 matching lines...) Expand all
111 else: 115 else:
112 raise exception.UnexpectedAttribute( 116 raise exception.UnexpectedAttribute(
113 "Attribute 'line_end' must be one of 'linux' (default), 'windows' or 'ma c'") 117 "Attribute 'line_end' must be one of 'linux' (default), 'windows' or 'ma c'")
114 118
115 def GetCliques(self): 119 def GetCliques(self):
116 if self.gatherer: 120 if self.gatherer:
117 return self.gatherer.GetCliques() 121 return self.gatherer.GetCliques()
118 else: 122 else:
119 return [] 123 return []
120 124
125 def GetDataPackPair(self, lang, encoding):
126 """Returns a (id, string) pair that represents the resource id and raw
127 bytes of the data. This is used to generate the data pack data file.
128 """
129 from grit.format import rc_header
130 id_map = rc_header.Item.tids_
131 id = id_map[self.GetTextualIds()[0]]
132 data = ''
133 if self.gatherer:
134 data = self.gatherer.GetData(lang, encoding)
135 return id, data
136
121 def GetTextualIds(self): 137 def GetTextualIds(self):
122 if self.gatherer and self.attrs['type'] not in ['tr_html', 'admin_template', 'txt']: 138 if self.gatherer and self.attrs['type'] not in ['chrome_html', 'tr_html', 'a dmin_template', 'txt']:
123 return self.gatherer.GetTextualIds() 139 return self.gatherer.GetTextualIds()
124 else: 140 else:
125 return [self.attrs['name']] 141 return [self.attrs['name']]
126 142
127 def ItemFormatter(self, t): 143 def ItemFormatter(self, t):
128 if t == 'rc_header': 144 if t == 'rc_header':
129 return grit.format.rc_header.Item() 145 return grit.format.rc_header.Item()
130 elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and 146 elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and
131 self.SatisfiesOutputCondition()): 147 self.SatisfiesOutputCondition()):
132 return _RC_FORMATTERS[self.attrs['type']] 148 return _RC_FORMATTERS[self.attrs['type']]
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 def SubstituteMessages(self, substituter): 299 def SubstituteMessages(self, substituter):
284 '''Propagates substitution to gatherer. 300 '''Propagates substitution to gatherer.
285 301
286 Args: 302 Args:
287 substituter: a grit.util.Substituter object. 303 substituter: a grit.util.Substituter object.
288 ''' 304 '''
289 assert self.gatherer 305 assert self.gatherer
290 if self.ExpandVariables(): 306 if self.ExpandVariables():
291 self.gatherer.SubstituteMessages(substituter) 307 self.gatherer.SubstituteMessages(substituter)
292 308
OLDNEW
« grit/gather/chrome_html.py ('K') | « grit/gather/chrome_html.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698