Skip to main content

Tool for sorting CSS file declarations.

Project description

sort_css_declarations

Sorts CSS declarations.

Installation

pip install sort_css_declarations

Console scripts

Consult sort-css-declarations --help for the full set of options. sort-css-declarations takes filenames as positional arguments.

Common options:

  • -h, --help show this help message and exit
  • --by_html BY_HTML Order CSS declarations by HTML's order.
  • -i, --in_place Edits file in-place.

Usage examples

Result directly goes to stdout.

sort-css-declarations test_dir/test_css.css

File will be edited in-place with the result.

sort-css-declarations -i test_dir/test_css.css

Redirect the stdout to a new file.

sort-css-declarations test_dir/test_css.css > test_dir/cleaned_css.css

Result reordered by html directly goes to stdout.

sort-css-declarations test_dir/test_css.css

Reorder by html and redirect the stdout to a new file.

sort-css-declarations test_dir/test_css.css --by_html test_dir/test_html.html > test_dir/cleaned_css.css

What does it do?

Without --by_html flag.

Separates block of grouped declarations and reorders them alphabetically the following way.

  • General tags, like <body>, <div>, <h1>, etc... goes to the top of the file ordered alphabetically.
  • Followed by the general tags, come the id or class specified declarations.

CSS before-after diff

1c1,6
- /*FORM GENERAL*/
---
+ 
+ body {
+     margin: 0;
+     padding: 0;
+ }
+ 
3,9c8,9
- .form-container,
- .form-wrapper,
- .form-wrapper form,
- .form-wrapper form div {
- 	display: grid;
- 	align-items: center;
- 	justify-content: center;
---
+ h1 {
+     color: red;
12,17c12,16
- .form-wrapper {
- 	width: fit-content;
- 	padding: 1rem;
- 	border: 1px solid lightgrey;
- 	border-radius: 5px;
- 	background: linear-gradient(109.6deg, rgb(248,248,248) 30.1%, rgb(144,144,144) 100.2%);
---
+ /* ====================== */
+ .form-container {
+     align-items: center;
+     display: grid;
+     justify-content: center;
20,21c19,28
- .form-wrapper form {
- 	gap: 1rem;
---
+ /* ====================== */
+ .form-wrapper {
+     align-items: center;
+     background: linear-gradient(109.6deg, rgb(248, 248, 248) 30.1%, rgb(144, 144, 144) 100.2%);
+     border-radius: 5px;
+     border: 1px solid lightgrey;
+     display: grid;
+     justify-content: center;
+     padding: 1rem;
+     width: fit-content;
24,26c31,36
- body {
-     margin: 0;
-     padding: 0;
---
+ /* ====================== */
+ .form-wrapper form {
+     align-items: center;
+     display: grid;
+     gap: 1rem;
+     justify-content: center;
28a39
+ /* ====================== */
30c41,44
- 	gap: 0.5rem;
---
+     align-items: center;
+     display: grid;
+     gap: 0.5rem;
+     justify-content: center;
34,35c48,49
- 	text-align: center;
- 	font-weight: 450;
---
+     font-weight: 450;
+     text-align: center;
38,39c52,53
- .form-wrapper form label+input {
- 	font-size: 16px;
---
+ .form-wrapper form label + input {
+     font-size: 16px;
41,42d54
- /* ====================== */
- 
44,46d55
- h1 {
-     color: red;
- }

With --by_html flag followed by the html template filename.

Separates block of grouped declarations and reorders them in the same order as in the html, increasing by the specification.

HTML sample

<div class="form-container">
    <div class="form-wrapper">
        <form action="login.php" method="post">

            <div class="username-input">
                <label for="username"><u>Username</u></label>
                <input id="username" name="username" type="text" 
                placeholder="Username.." value="username"/>
            </div>

            <div class="password-input">
                <label for="password"><u>Password</u></label>
                <input id="password" name="password" type="password" placeholder="Password.."/>
            </div>

            <div class="submit-btn-wrapper">
                <button class="button" id="submit-btn" name="submit" type="submit">Log in</button>
            </div>
        </form>
    </div>
</div> 

CSS before-after diff

1c1
- /*FORM GENERAL*/
---
+ 
3,9c3,6
- .form-container,
- .form-wrapper,
- .form-wrapper form,
- .form-wrapper form div {
- 	display: grid;
- 	align-items: center;
- 	justify-content: center;
---
+ .form-container {
+     align-items: center;
+     display: grid;
+     justify-content: center;
11a9
+ /* ====================== */
13,17c11,18
- 	width: fit-content;
- 	padding: 1rem;
- 	border: 1px solid lightgrey;
- 	border-radius: 5px;
- 	background: linear-gradient(109.6deg, rgb(248,248,248) 30.1%, rgb(144,144,144) 100.2%);
---
+     align-items: center;
+     background: linear-gradient(109.6deg, rgb(248, 248, 248) 30.1%, rgb(144, 144, 144) 100.2%);
+     border-radius: 5px;
+     border: 1px solid lightgrey;
+     display: grid;
+     justify-content: center;
+     padding: 1rem;
+     width: fit-content;
19a21
+ /* ====================== */
21,26c23,26
- 	gap: 1rem;
- }
- 
- body {
-     margin: 0;
-     padding: 0;
---
+     align-items: center;
+     display: grid;
+     gap: 1rem;
+     justify-content: center;
28a29
+ /* ====================== */
30c31,34
- 	gap: 0.5rem;
---
+     align-items: center;
+     display: grid;
+     gap: 0.5rem;
+     justify-content: center;
34,35c38,39
- 	text-align: center;
- 	font-weight: 450;
---
+     font-weight: 450;
+     text-align: center;
38,39c42,43
- .form-wrapper form label+input {
- 	font-size: 16px;
---
+ .form-wrapper form label + input {
+     font-size: 16px;
41d44
- /* ====================== */
43,46d45
- 
- h1 {
-     color: red;
- }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sort_css_declarations-1.0.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sort_css_declarations-1.0.1-py2.py3-none-any.whl (8.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sort_css_declarations-1.0.1.tar.gz.

File metadata

  • Download URL: sort_css_declarations-1.0.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for sort_css_declarations-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a7b2c94ca580e311eb2c6c1027d8fce987c37595109b87fb3df806dfda5981e7
MD5 4524c855220ed7404043d5fa9bb4e976
BLAKE2b-256 9b085fac71bdd18f67bf635afc67ca24c424d5365b9eb01bdae7606ad613586d

See more details on using hashes here.

File details

Details for the file sort_css_declarations-1.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sort_css_declarations-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fb010bad4f2be99f63e1770fd5ee59912107bec7eb7b18963c2a998be017c285
MD5 3c57ff0a691e57a6f3205dd4db12c6e1
BLAKE2b-256 e6f748a2f3a2aae66af900125ac2542c24ce979995b60df885c7a6cba2be404e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page