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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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()) |
OLD | NEW |