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

Unified Diff: third_party/dom_distiller_js/protoc_plugins/util/writer.py

Issue 2034373002: Generate the proto JSON converter for DOM distiller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/dom_distiller_js/protoc_plugins/util/writer.py
diff --git a/third_party/dom_distiller_js/protoc_plugins/util/writer.py b/third_party/dom_distiller_js/protoc_plugins/util/writer.py
new file mode 100644
index 0000000000000000000000000000000000000000..5c0c2b0920016f1b3e9b8c1a8ea070d01e29582d
--- /dev/null
+++ b/third_party/dom_distiller_js/protoc_plugins/util/writer.py
@@ -0,0 +1,43 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
nyquist 2016/06/14 00:48:11 Could you in general update these numbers?
wychen 2016/08/07 09:16:27 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import contextlib
+
+class CodeWriter(object):
nyquist 2016/06/14 00:48:11 Could you add an explanatory comment for this clas
wychen 2016/08/07 09:16:27 Done.
+ def __init__(self):
+ self.indent = 0
+ self.value = []
+ self.errors = []
+
+ def GetErrors(self):
+ return self.errors
+
+ @contextlib.contextmanager
+ def AddIndent(self, indent=2):
+ self.indent += indent
+ yield 0
+ self.indent -= indent
+
+ def IncreaseIndent(self, indent=2):
+ self.indent += indent
+
+ def DecreaseIndent(self, indent=2):
+ self.indent -= indent
+
+ def Output(self, fmt, **kwargs):
+ s = fmt.format(**kwargs)
+ s = s.rstrip('\n')
+ lines = s.split('\n')
+ lines = map(lambda s: (' ' * self.indent + s).rstrip(), lines)
+ self.value.extend(lines)
+
+ def AddError(self, fmt, **kwargs):
+ self.errors.append(fmt.format(**kwargs))
+
+ def GetValue(self):
+ return '\n'.join(self.value) + '\n'
+
+ def WriteCStyleHeader(self):
+ self.Output("// GENERATED FILE")
+ self.Output("// This file generated by DomDistillerJs protoc plugin.")

Powered by Google App Engine
This is Rietveld 408576698