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

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: Windows-specific fixes Created 4 years, 4 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..e937e3248c8eacd3ba18d2419027451ffab51d89
--- /dev/null
+++ b/third_party/dom_distiller_js/protoc_plugins/util/writer.py
@@ -0,0 +1,44 @@
+# Copyright 2016 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 contextlib
+
+class CodeWriter(object):
+ """Helper class for code indentation."""
+ 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.")
« no previous file with comments | « third_party/dom_distiller_js/protoc_plugins/util/types.py ('k') | third_party/dom_distiller_js/test_sample.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698