Created
September 20, 2015 18:43
-
-
Save mtholder/b0296d7402b65fc51b6d to your computer and use it in GitHub Desktop.
copy opentree static CSS and JS files into a file - but forget to deal with relative paths changing...
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| import re | |
| inp = sys.stdin | |
| outp = sys.stdout | |
| JS_PAT = re.compile(r'^<script src="/opentree/static/(.+)" type="text/javascript"></script>\s+$') | |
| CSS_PAT = re.compile(r'^<link href="/opentree/static/(.+)" rel="stylesheet" type="text/css" />\s+$') | |
| for line in inp: | |
| m = JS_PAT.match(line) | |
| if m: | |
| fn = m.group(1) | |
| outp.write('<script type="text/javascript">\n') | |
| with open(fn, 'rU') as to_inline: | |
| outp.write(to_inline.read()) | |
| outp.write('\n</script>\n') | |
| else: | |
| m = CSS_PAT.match(line) | |
| if m: | |
| fn = m.group(1) | |
| outp.write('<style type="text/css">\n') | |
| with open(fn, 'rU') as to_inline: | |
| outp.write(to_inline.read()) | |
| outp.write('\n</style>\n') | |
| else: | |
| outp.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment