Josh Pratt | f4dee35 | 2018-07-30 17:04:49 +1000 | [diff] [blame^] | 1 | """An example script applying rewrite rules files passed in as arguments. |
| 2 | |
| 3 | Usage: example.py "gtk-3.*/*.css" |
| 4 | """ |
| 5 | |
| 6 | from __future__ import print_function |
| 7 | import sys |
| 8 | from rewriter import background_color |
| 9 | from rewriter import border_color |
| 10 | from rewriter import color |
| 11 | from rewriter import Mod |
| 12 | from rewriter import rewrite_files |
| 13 | |
| 14 | mods = [ |
| 15 | Mod(r'button', |
| 16 | remove=r' *box-shadow:[^;]*;', |
| 17 | enabled=True), |
| 18 | Mod(r'button\.suggested-action', |
| 19 | anti=[r'\.destructive-action'], |
| 20 | remove=color(), |
| 21 | replace=r'\1@theme_base_color\3', |
| 22 | enabled=False), |
| 23 | Mod(r'button\.suggested-action', |
| 24 | anti=[r'\.destructive-action'], |
| 25 | remove=background_color(), |
| 26 | replace=r'\1@suggestion_color\3', |
| 27 | enabled=False), |
| 28 | Mod(r'button', |
| 29 | anti=[r'\..*\-action'], |
| 30 | remove=color(), |
| 31 | replace=r'\1@suggestion_color\3', |
| 32 | enabled=False), |
| 33 | Mod(r'button', |
| 34 | anti=[r'\..*\-action'], |
| 35 | remove=background_color(), |
| 36 | replace=r'\1@theme_base_color\3', |
| 37 | enabled=False), |
| 38 | Mod(r'menuitem.*button', |
| 39 | anti=[r'\..*\-action'], |
| 40 | remove=color(), |
| 41 | replace=r'\1@theme_text_color\3', |
| 42 | enabled=True), |
| 43 | Mod(r'text-button', |
| 44 | anti=[r'\..*\-action'], |
| 45 | remove=color(), |
| 46 | replace=r'\1@theme_text_color\3', |
| 47 | enabled=True), |
| 48 | Mod(r'menuitem.*button', |
| 49 | anti=[r'\..*\-action'], |
| 50 | remove=background_color(), |
| 51 | replace=r'\1@theme_base_color\3', |
| 52 | enabled=True), |
| 53 | Mod(r'text-button', |
| 54 | anti=[r'\..*\-action'], |
| 55 | remove=background_color(), |
| 56 | replace=r'\1@theme_base_color\3', |
| 57 | enabled=True), |
| 58 | Mod(r'button.*:disabled', |
| 59 | anti=[r'-action'], |
| 60 | remove=border_color(), |
| 61 | replace=r'\1@insensitive_bg_color\3', |
| 62 | enabled=True), |
| 63 | Mod(r'button.*:disabled', |
| 64 | anti=[r'-action'], |
| 65 | remove=border_color(), |
| 66 | replace=r'\1@insensitive_bg_color\3', |
| 67 | enabled=True), |
| 68 | Mod(r'button.*:disabled', |
| 69 | anti=[r'-action'], |
| 70 | remove=background_color(), |
| 71 | replace=r'\1@theme_base_color\3', |
| 72 | enabled=True), |
| 73 | Mod(r'button.*:disabled', |
| 74 | anti=[r'-action'], |
| 75 | remove=color(), |
| 76 | replace=r'\1@insensitive_fg_color\3', |
| 77 | enabled=True), |
| 78 | |
| 79 | Mod(r'button.suggested-action.*:disabled', |
| 80 | anti=[r'\.destructive-action'], |
| 81 | remove=color(), |
| 82 | replace=r'\1@insensitive_fg_color\3', |
| 83 | enabled=True), |
| 84 | Mod(r'button.suggested-action.*:disabled', |
| 85 | anti=[r'\.destructive-action'], |
| 86 | remove=background_color(), |
| 87 | replace=r'\1@suggestion_color\3', |
| 88 | enabled=True), |
| 89 | Mod(r'.*', # Fixes rgba(@color, .*) |
| 90 | remove=r'rgba(\(@[a-z_]*), .*(, [01]\.[0-9]*\))', |
| 91 | replace=r'alpha\1\2'), |
| 92 | Mod(r'.*', # Fixes alpha(currentColor, @var.* |
| 93 | remove=r'alpha\(currentColor, (@[a-z][^\.]*)([\.0-9]*)\)', |
| 94 | replace=r'alpha(\1, 0\2)') |
| 95 | ] |
| 96 | |
| 97 | if len(sys.argv) > 1: |
| 98 | rewrite_files(sys.argv[1:], mods) |
| 99 | else: |
| 100 | print('No files were passed in.') |
| 101 | exit() |