Skip to content

Instantly share code, notes, and snippets.

@DrOctogon
Created January 9, 2015 19:07
Show Gist options
  • Save DrOctogon/91ca29ffbc4c3687cc7e to your computer and use it in GitHub Desktop.
Save DrOctogon/91ca29ffbc4c3687cc7e to your computer and use it in GitHub Desktop.
Bootstrap2 > Bootstrap3 Migration
import os
import re
import argparse
app_path = os.path.split(os.path.split(__file__)[0])[0]
PROJECT_ROOT = os.path.abspath(app_path)
regexps = [
(r'class=(["\'] *?)row-fluid(.*?["\']+)', r'class=\1row\2'),
(r'class=(["\'] *?)brand(.*?["\']+)', r'class=\1navbar-brand\2'),
(r'class=(["\'] *?)nav-collapse(.*?["\']+)', r'class=\1navbar-collapse\2'),
(r'class=(["\'] *?)nav-toggle(.*?["\']+)', r'class=\1navbar-toggle\2'),
(r'class=(["\'] *?)btn-navbar(.*?["\']+)', r'class=\1navbar-btn\2'),
(r'class=(["\'] *?)hero-unit(.*?["\']+)', r'class=\1jumbotron\2'),
(r'class=(["\'] *?)btn-mini(.*?["\']+)', r'class=\1btn-xs\2'),
(r'class=(["\'] *?)btn-small(.*?["\']+)', r'class=\1btn-sm\2'),
(r'class=(["\'] *?)btn-large(.*?["\']+)', r'class=\1btn-lg\2'),
(r'class=(["\'] *?)alert-error(.*?["\']+)', r'class=\1alert-danger\2'),
(r'class=(["\'] *?)visible-phone(.*?["\']+)', r'class=\1visible-xs\2'),
(r'class=(["\'] *?)visible-tablet(.*?["\']+)', r'class=\1visible-sm\2'),
(r'class=(["\'] *?)hidden-desktop(.*?["\']+)', r'class=\1hidden-md\2'),
(r'class=(["\'] *?)input-block-level(.*?["\']+)', r'class=\1form-control\2'),
(r'class=(["\'] *?)control-group(.*?["\']+)', r'class=\1form-group\2'),
(r'class=(["\'] *?)label-important(.*?["\']+)', r'class=\1label-danger\2'),
(r'class=(["\'] *?)text-error(.*?["\']+)', r'class=\1text-danger\2'),
(r'class=(["\'] *?)span([\d]+)(.*?["\']+)', r'class=\1col-md-\2\3'),
(r'class=(["\'] *?)offset([\d]+)(.*?["\']+)', r'class=\1col-md-offset-\2\3'),
(r'class=(["\'] *?)icon-([\d]+)(.*?["\']+)', r'class=\1glyphicon glyphicon-\2\3'),
(r'class=(["\'] *?)offset([\d]+)(.*?["\']+)', r'class=\1col-md-offset-\2\3'),
]
def update_path(directory):
"Update BT classes"
for path, dirs, files in os.walk(directory):
for fname in files:
if fname.endswith('.html'):
fpath = os.path.join(path, fname)
with open(fpath) as f:
s = f.read()
for regxp in regexps:
s = re.sub(regxp[0], regxp[1], s)
with open(fpath, "w") as f:
f.write(s)
for dir in dirs:
update_path(dir)
def get_args():
parser = argparse.ArgumentParser(description='Simple script to migrate from boostrap 2 to boostrap 3')
parser.add_argument("path", help='Path of the HTML files to be converted')
return parser.parse_args()
def main(args):
update_path(args.path)
if __name__ == '__main__':
args = get_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment