| OLD | NEW |
| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 """ | 279 """ |
| 280 Injects meta and link tags into an HTML document. | 280 Injects meta and link tags into an HTML document. |
| 281 | 281 |
| 282 Args: | 282 Args: |
| 283 soup: BeautifulSoup HTML document. Will be modified. | 283 soup: BeautifulSoup HTML document. Will be modified. |
| 284 ca_manifest: Manifest dictionary of _Chrome App_. | 284 ca_manifest: Manifest dictionary of _Chrome App_. |
| 285 root_path: Path to the root directory of the web app from this HTML file. | 285 root_path: Path to the root directory of the web app from this HTML file. |
| 286 This can be either absolute or relative. | 286 This can be either absolute or relative. |
| 287 html_path: Path to the HTML document being modified. | 287 html_path: Path to the HTML document being modified. |
| 288 """ | 288 """ |
| 289 head = soup.head |
| 290 if not head: |
| 291 head = soup.new_tag('head') |
| 292 if soup.html: |
| 293 soup.html.insert(0, head) |
| 294 else: |
| 295 soup.insert(0, head) |
| 296 |
| 289 # Add manifest link tag. | 297 # Add manifest link tag. |
| 290 manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME) | 298 manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME) |
| 291 manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path) | 299 manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path) |
| 292 soup.head.append(manifest_link) | 300 head.append(manifest_link) |
| 293 | 301 |
| 294 # Add meta tags (if they don't already exist). | 302 # Add meta tags (if they don't already exist). |
| 295 for tag in ('description', 'author', 'name'): | 303 for tag in ('description', 'author', 'name'): |
| 296 if tag in ca_manifest and not soup('meta', {'name': tag}): | 304 if tag in ca_manifest and not soup('meta', {'name': tag}): |
| 297 meta = soup.new_tag('meta', content=ca_manifest[tag]) | 305 meta = soup.new_tag('meta', content=ca_manifest[tag]) |
| 298 meta['name'] = tag | 306 meta['name'] = tag |
| 299 soup.head.append(meta) | 307 head.append(meta) |
| 300 logging.debug('Injected `%s` tag into `%s` with content `%s`.', tag, | 308 logging.debug('Injected `%s` tag into `%s` with content `%s`.', tag, |
| 301 html_path, ca_manifest[tag]) | 309 html_path, ca_manifest[tag]) |
| 302 if not soup('meta', {'charset': True}): | 310 if not soup('meta', {'charset': True}): |
| 303 meta_charset = soup.new_tag('meta', charset='utf-8') | 311 meta_charset = soup.new_tag('meta', charset='utf-8') |
| 304 soup.head.insert(0, meta_charset) | 312 head.insert(0, meta_charset) |
| 305 | 313 |
| 306 | 314 |
| 307 def insert_todos_into_file(js_path): | 315 def insert_todos_into_file(js_path): |
| 308 """Inserts TODO comments in a JavaScript file. | 316 """Inserts TODO comments in a JavaScript file. |
| 309 | 317 |
| 310 The TODO comments inserted should draw attention to places in the converted | 318 The TODO comments inserted should draw attention to places in the converted |
| 311 app that the developer will need to edit to finish converting their app. | 319 app that the developer will need to edit to finish converting their app. |
| 312 | 320 |
| 313 Args: | 321 Args: |
| 314 js_path: Path to JavaScript file. | 322 js_path: Path to JavaScript file. |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 if args.mode == 'config': | 756 if args.mode == 'config': |
| 749 configuration.generate_and_save(args.output, args.interactive) | 757 configuration.generate_and_save(args.output, args.interactive) |
| 750 | 758 |
| 751 elif args.mode == 'convert': | 759 elif args.mode == 'convert': |
| 752 config = configuration.load(args.config) | 760 config = configuration.load(args.config) |
| 753 convert_app(args.input, args.output, config, args.force) | 761 convert_app(args.input, args.output, config, args.force) |
| 754 | 762 |
| 755 | 763 |
| 756 if __name__ == '__main__': | 764 if __name__ == '__main__': |
| 757 sys.exit(main()) | 765 sys.exit(main()) |
| OLD | NEW |