Created
September 22, 2014 02:07
-
-
Save dzhioev/1229aae33ebbd6e0ed0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/third_party/tvcm/tvcm/generate.py b/third_party/tvcm/tvcm/generate.py | |
index acf32fc..160f02f 100644 | |
--- a/third_party/tvcm/tvcm/generate.py | |
+++ b/third_party/tvcm/tvcm/generate.py | |
@@ -68,18 +68,6 @@ def GenerateJSToFile(f, | |
f.write(js_warning_message) | |
f.write('\n') | |
- | |
- loader = load_sequence[0].loader | |
- | |
- platform_script = loader.LoadRawScript('platform.min.js') | |
- f.write(platform_script.contents) | |
- | |
- polymer_script = loader.LoadRawScript('polymer.min.js') | |
- f.write(polymer_script.contents) | |
- | |
- f.write('\n') | |
- f.write("window._TVCM_IS_COMPILED = true;\n") | |
- | |
for module in load_sequence: | |
module.AppendJSContentsToFile(f, | |
use_include_tags_for_scripts, | |
@@ -123,11 +111,21 @@ def GenerateStandaloneHTMLToFile(output_file, | |
output_file.write("""<!DOCTYPE HTML> | |
<html> | |
- <head i18n-values="dir:textdirection;"> | |
+ <head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>%s</title> | |
""" % title) | |
+ if flattened_js_url: | |
+ output_file.write('<script src="%s"></script>\n' % flattened_js_url) | |
+ else: | |
+ output_file.write('<script>\n') | |
+ output_file.write(GenerateJS(load_sequence)) | |
+ output_file.write('</script>\n') | |
+ | |
+ for extra_script in extra_scripts: | |
+ extra_script.WriteToFile(output_file) | |
+ | |
loader = load_sequence[0].loader | |
written_style_sheets = set() | |
@@ -150,16 +148,6 @@ def GenerateStandaloneHTMLToFile(output_file, | |
ctl = HTMLGenerationController(module) | |
module.AppendHTMLContentsToFile(output_file, ctl) | |
- if flattened_js_url: | |
- output_file.write('<script src="%s"></script>\n' % flattened_js_url) | |
- else: | |
- output_file.write('<script>\n') | |
- output_file.write(GenerateJS(load_sequence)) | |
- output_file.write('</script>\n') | |
- | |
- for extra_script in extra_scripts: | |
- extra_script.WriteToFile(output_file) | |
- | |
output_file.write("""</head> | |
<body> | |
""") | |
diff --git a/third_party/tvcm/tvcm/html_module.py b/third_party/tvcm/tvcm/html_module.py | |
index 8384308..58b1055 100644 | |
--- a/third_party/tvcm/tvcm/html_module.py | |
+++ b/third_party/tvcm/tvcm/html_module.py | |
@@ -12,7 +12,8 @@ from tvcm import style_sheet | |
def IsHTMLResourceTheModuleGivenConflictingResourceNames( | |
js_resource, html_resource): | |
- return 'polymer-element' in html_resource.contents | |
+ return 'polymer-element' in html_resource.contents or \ | |
+ os.path.basename(html_resource.absolute_path) == 'polymer.html' | |
class HTMLModule(module.Module): | |
@property | |
@@ -160,7 +161,7 @@ def _HRefToResource(loader, module_name, module_dir_name, href, tag_for_err_msg) | |
def Parse(loader, module_name, module_dir_name, parser_results): | |
if parser_results.has_decl == False: | |
- raise Exception('%s must have <!DOCTYPE html>' % module_name) | |
+ print 'WARNING: %s must have <!DOCTYPE html>' % module_name | |
res = module.ModuleDependencyMetadata() | |
@@ -186,10 +187,12 @@ def Parse(loader, module_name, module_dir_name, parser_results): | |
for inline_script in parser_results.inline_scripts: | |
stripped_text = inline_script.stripped_contents | |
try: | |
- js_utils.ValidateUsesStrictMode('_', stripped_text) | |
- except: | |
- raise Exception('%s has an inline script tag that is missing ' \ | |
- 'a \'use strict\' directive.' % module_name) | |
+ js_utils.ValidateUsesStrictMode(module_name, stripped_text) | |
+ except module.DepsException, e: | |
+ print "WARNING:", e | |
+ # raise Exception('%s has an inline script tag that is missing ' \ | |
+ # 'a \'use strict\' directive.' % module_name) | |
+ | |
# Style sheets | |
for href in parser_results.stylesheets: | |
diff --git a/third_party/tvcm/tvcm/js_utils.py b/third_party/tvcm/tvcm/js_utils.py | |
index fede8c8..e514822 100644 | |
--- a/third_party/tvcm/tvcm/js_utils.py | |
+++ b/third_party/tvcm/tvcm/js_utils.py | |
@@ -2,6 +2,8 @@ | |
# Use of this source code is governed by a BSD-style license that can be | |
# found in the LICENSE file. | |
+import tvcm.module | |
+ | |
def EscapeJSIfNeeded(js): | |
return js.replace("</script>", "<\/script>") | |
@@ -12,7 +14,7 @@ def ValidateUsesStrictMode(module_name, stripped_text): | |
stripped_text: Javascript source code with comments stripped out. | |
Raises: | |
- DepsException: This file doesn't use strict mode. | |
+ tvcm.module.DepsException: This file doesn't use strict mode. | |
""" | |
lines = stripped_text.split('\n') | |
for line in lines: | |
@@ -21,5 +23,5 @@ def ValidateUsesStrictMode(module_name, stripped_text): | |
continue | |
if """'use strict';""" in line.strip(): | |
break | |
- raise module.DepsException('%s must use strict mode' % module_name) | |
+ raise tvcm.module.DepsException('%s must use strict mode' % module_name) | |
diff --git a/third_party/tvcm/tvcm/module.py b/third_party/tvcm/tvcm/module.py | |
index 5fa9343..50c92cc 100644 | |
--- a/third_party/tvcm/tvcm/module.py | |
+++ b/third_party/tvcm/tvcm/module.py | |
@@ -15,7 +15,7 @@ import re | |
import inspect | |
from tvcm import resource as resource_module | |
-from tvcm import js_utils | |
+import tvcm.js_utils | |
class DepsException(Exception): | |
@@ -134,7 +134,7 @@ class Module(object): | |
dir_for_include_tag_root) | |
f.write("""<include src="%s">\n""" % rel_filename) | |
else: | |
- f.write(js_utils.EscapeJSIfNeeded(dependent_raw_script.contents)) | |
+ f.write(tvcm.js_utils.EscapeJSIfNeeded(dependent_raw_script.contents)) | |
f.write('\n') | |
def AppendHTMLContentsToFile(self, f, ctl): | |
@@ -151,9 +151,11 @@ class Module(object): | |
assert self.name, 'Module name must be set before dep resolution.' | |
assert self.filename, 'Module filename must be set before dep resolution.' | |
assert self.name in self.loader.loaded_modules, 'Module must be registered in resource loader before loading.' | |
+ print "Loading: " + self.resource.absolute_path | |
metadata = self.dependency_metadata | |
for name in metadata.dependent_module_names: | |
+ print "Loading dependent module: %s" % name | |
module = self.loader.LoadModule(module_name=name) | |
self.dependent_modules.append(module) | |
diff --git a/third_party/tvcm/tvcm/parse_html_deps.py b/third_party/tvcm/tvcm/parse_html_deps.py | |
index aa4f2ff..8125e28 100644 | |
--- a/third_party/tvcm/tvcm/parse_html_deps.py | |
+++ b/third_party/tvcm/tvcm/parse_html_deps.py | |
@@ -14,6 +14,7 @@ CHUNK_TEXT_OP = 'text-op' | |
CHUNK_SCRIPT_OP = 'script-op' | |
CHUNK_STYLESHEET_OP = 'stylesheet-op' | |
CHUNK_INLINE_STYLE_OP = 'inline-style-op' | |
+CHUNK_IMPORT_OP = 'import-op' | |
class _Chunk(object): | |
def __init__(self, op, data): | |
@@ -132,6 +133,9 @@ class HTMLModuleParserResults(object): | |
def AppendHTMLStylesheetSplicePoint(self, href): | |
self._chunks.append(_Chunk(CHUNK_STYLESHEET_OP, href)) | |
+ def AppendHTMLImportSplicePoint(self, href): | |
+ self._chunks.append(_Chunk(CHUNK_IMPORT_OP, href)) | |
+ | |
def GenerateHTML(self, controller): | |
return ''.join(list(self.YieldHTMLInPieces(controller))) | |
@@ -152,13 +156,16 @@ class HTMLModuleParserResults(object): | |
if html: | |
yield html | |
else: | |
- raise NotImplementedError() | |
+ pass | |
+ # raise NotImplementedError() | |
@property | |
def html_contents_without_links_and_script(self): | |
return self.GenerateHTML(html_generation_controller.HTMLGenerationController()) | |
-_SELF_CLOSING_TAGS = ('link', 'p', 'meta') | |
+# According to http://www.w3.org/TR/html5/syntax.html#void-elements | |
+_VOID_ELEMENTS = ('area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', | |
+ 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr') | |
class _Tag(object): | |
def __init__(self, tag, attrs): | |
@@ -205,7 +212,7 @@ class HTMLModuleParser(): | |
if tag == 'br': | |
raise Exception('Must use <br/>') | |
- if tag not in _SELF_CLOSING_TAGS: | |
+ if tag not in _VOID_ELEMENTS: | |
self.open_tags.append(_Tag(tag, attrs)) | |
if tag == 'link': | |
@@ -263,7 +270,7 @@ class HTMLModuleParser(): | |
self.current_results.AppendHTMLContent('%s' % self.get_starttag_text()) | |
def handle_endtag(self, tag): | |
- if tag not in _SELF_CLOSING_TAGS: | |
+ if tag not in _VOID_ELEMENTS: | |
if len(self.open_tags) == 0: | |
raise Exception('got </%s> with no previous open tag' % tag) | |
diff --git a/third_party/tvcm/tvcm/resource_loader.py b/third_party/tvcm/tvcm/resource_loader.py | |
index 6b74239..4c642ac 100644 | |
--- a/third_party/tvcm/tvcm/resource_loader.py | |
+++ b/third_party/tvcm/tvcm/resource_loader.py | |
@@ -122,7 +122,7 @@ class ResourceLoader(object): | |
raise module.DepsException('No resource for module "%s"' % module_name) | |
if resource.absolute_path.endswith('.js'): | |
- raise Exception(".js modules are deprecated") | |
+ raise Exception(".js modules are deprecated, when trying to load %s" % resource.absolute_path) | |
m = html_module.HTMLModule(self, module_name, resource) | |
m.Parse() | |
self.loaded_modules[module_name] = m | |
diff --git a/trace_viewer/build/generate_about_tracing_contents.py b/trace_viewer/build/generate_about_tracing_contents.py | |
index 8d3b3cb..f16cbde 100644 | |
--- a/trace_viewer/build/generate_about_tracing_contents.py | |
+++ b/trace_viewer/build/generate_about_tracing_contents.py | |
@@ -41,7 +41,7 @@ def main(args): | |
o = open(os.path.join(options.out_dir, "about_tracing.js"), 'w') | |
tvcm.GenerateJSToFile( | |
- o, | |
+ o, | |
load_sequence, | |
use_include_tags_for_scripts=True, | |
dir_for_include_tag_root=options.out_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment