You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. import os
  3. import re
  4. import io
  5. directory = r'd:\WorkSpace\boying\boying-pda\src\views\modules'
  6. for root, _, files in os.walk(directory):
  7. for file in files:
  8. if file.endswith('.vue'):
  9. path = os.path.join(root, file)
  10. with io.open(path, 'r', encoding='utf-8') as f:
  11. content = f.read()
  12. changed = False
  13. # Ensure list-body wrapper exists in HTML if label-list is there
  14. if '<div class="label-list">' in content and 'class="list-body"' not in content:
  15. # We need to wrap the items. This is a bit complex to do automatically safely.
  16. print('Needs list-body wrapper: ' + path)
  17. # Update CSS for label-list
  18. # Find .label-list { ... }
  19. label_list_pattern = r'(\.label-list\s*\{[^}]*?)\}'
  20. match = re.search(label_list_pattern, content)
  21. if match:
  22. inner_content = match.group(1)
  23. # Check if it has display: flex;
  24. if 'flex:' not in inner_content:
  25. new_inner = inner_content + ' flex: 1;\n display: flex;\n flex-direction: column;\n max-height: 300px;\n}'
  26. content = re.sub(label_list_pattern, new_inner.replace('\\', '\\\\'), content, count=1)
  27. changed = True
  28. # Find .list-body { ... } or add it
  29. if '.label-list .list-body {' not in content and '.list-body {' not in content and 'class="list-body"' in content:
  30. content = content.replace('.list-header {', '.label-list .list-body {\n flex: 1;\n overflow-y: auto;\n max-height: 250px;\n}\n\n.list-header {')
  31. changed = True
  32. if changed:
  33. with io.open(path, 'w', encoding='utf-8') as f:
  34. f.write(content)
  35. print('Updated flex ' + file)