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

Side by Side Diff: src/caterpillar.py

Issue 1644543005: inject_misc_tags no longer fails if document has no head. Resolves #16. (Closed) Base URL: git@github.com:chromium/caterpillar.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | 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 python2 1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # Copyright 2015 Google Inc. All Rights Reserved. 4 # Copyright 2015 Google Inc. All Rights Reserved.
5 # 5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License. 7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at 8 # You may obtain a copy of the License at
9 # 9 #
10 # http://www.apache.org/licenses/LICENSE-2.0 10 # http://www.apache.org/licenses/LICENSE-2.0
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 """ 273 """
274 Injects meta and link tags into an HTML document. 274 Injects meta and link tags into an HTML document.
275 275
276 Args: 276 Args:
277 soup: BeautifulSoup HTML document. Will be modified. 277 soup: BeautifulSoup HTML document. Will be modified.
278 ca_manifest: Manifest dictionary of _Chrome App_. 278 ca_manifest: Manifest dictionary of _Chrome App_.
279 root_path: Path to the root directory of the web app from this HTML file. 279 root_path: Path to the root directory of the web app from this HTML file.
280 This can be either absolute or relative. 280 This can be either absolute or relative.
281 html_path: Path to the HTML document being modified. 281 html_path: Path to the HTML document being modified.
282 """ 282 """
283 target_tag = soup.head if soup.head else soup
Matt Giuca 2016/01/28 06:56:25 Maybe this should create a head tag, instead of ju
Matthew Alger 2016/01/28 23:08:43 Good idea - done.
284
283 # Add manifest link tag. 285 # Add manifest link tag.
284 manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME) 286 manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME)
285 manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path) 287 manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path)
286 soup.head.append(manifest_link) 288 target_tag.append(manifest_link)
287 289
288 # Add meta tags (if they don't already exist). 290 # Add meta tags (if they don't already exist).
289 for tag in ('description', 'author', 'name'): 291 for tag in ('description', 'author', 'name'):
290 if tag in ca_manifest and not soup('meta', {'name': tag}): 292 if tag in ca_manifest and not soup('meta', {'name': tag}):
291 meta = soup.new_tag('meta', content=ca_manifest[tag]) 293 meta = soup.new_tag('meta', content=ca_manifest[tag])
292 meta['name'] = tag 294 meta['name'] = tag
293 soup.head.append(meta) 295 target_tag.append(meta)
294 logging.debug('Injected `%s` tag into `%s` with content `%s`.', tag, 296 logging.debug('Injected `%s` tag into `%s` with content `%s`.', tag,
295 html_path, ca_manifest[tag]) 297 html_path, ca_manifest[tag])
296 if not soup('meta', {'charset': True}): 298 if not soup('meta', {'charset': True}):
297 meta_charset = soup.new_tag('meta', charset='utf-8') 299 meta_charset = soup.new_tag('meta', charset='utf-8')
298 soup.head.insert(0, meta_charset) 300 target_tag.insert(0, meta_charset)
299 301
300 302
301 def insert_todos_into_file(js_path): 303 def insert_todos_into_file(js_path):
302 """Inserts TODO comments in a JavaScript file. 304 """Inserts TODO comments in a JavaScript file.
303 305
304 The TODO comments inserted should draw attention to places in the converted 306 The TODO comments inserted should draw attention to places in the converted
305 app that the developer will need to edit to finish converting their app. 307 app that the developer will need to edit to finish converting their app.
306 308
307 Args: 309 Args:
308 js_path: Path to JavaScript file. 310 js_path: Path to JavaScript file.
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 if args.mode == 'config': 726 if args.mode == 'config':
725 configuration.generate_and_save(args.output, args.interactive) 727 configuration.generate_and_save(args.output, args.interactive)
726 728
727 elif args.mode == 'convert': 729 elif args.mode == 'convert':
728 config = configuration.load(args.config) 730 config = configuration.load(args.config)
729 convert_app(args.input, args.output, config, args.force) 731 convert_app(args.input, args.output, config, args.force)
730 732
731 733
732 if __name__ == '__main__': 734 if __name__ == '__main__':
733 sys.exit(main()) 735 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698