Skip to main content

Pythonic markup for css

Project description

CleanCSS

CleanCSS is a simple pythonic language for CSS inspired by CleverCSS but simpler and with less obstrusive features.

Why

I really liked the idea behind CleverCSS but when used in production I realized that I was trying to get away from its parser by escaping strings and unsupported CSS properties way too often. Using vendor prefixes like -webkit-gradient and values such as rgba resulted in a messy CSS, so I decided to write my own parser for a similar syntax without all the complex features that I did not use anyway and it now works fine for me in REAL modern websites.

Syntax examples

I’m going to keep the CleverCSS examples where possible since the syntax is really similar.

A small example below. Note the indentation based syntax and how you can nest rules:

#header, #footer:
        margin: 0
        padding: 0
        font->
                family: Verdana, sans-serif
                size: .9em

        li:
                padding: 0.4em
                margin: 0.8em 0 0.8em

                h3:
                        font-size: 1.2em
                p:
                        padding: 0.3em
                p.meta:
                        text-align: right
                        color: #ddd

Of course you can do the very same in CSS, but because of its flat nature the code would look more verbose. The following piece of code is the CleanCSS output of the above file:

#header, #footer {
        margin: 0;
        padding: 0;
        font-family: Verdana, sans-serif
        font-size: .9em
}

#header li,
#footer li {
        padding: 0.4em;
        margin: 0.8em 0 0.8em;
}

#header li h3,
#footer li h3 {
        font-size: 1.2em;
}

#header li p,
#footer li p {
        padding: 0.3em;
}

#header li p.meta,
#footer li p.meta {
        text-align: right;
        color: #dddddd;
}

Library usage

Import the cleancss module and call the convert() function with a file-like object.

Example:

import cleancss
with open('file.ccss') as f:
        print cleancss.convert(f)

Command line usage

Call the cleancss.py without parameters to show the usage instructions. Pass any number of files to cleancss.py and the script will convert the files to CSS and print the result to the console.

Example:

cleancss.py file.ccss > result.css

LICENSE

Copyright (c) 2010 Massimiliano Torromeo

CleanCSS is free software released under the terms of the BSD license.

See the LICENSE file provided with the source distribution for full details.

Contacts

Project details


Download files

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

Source Distributions

CleanCSS-1.3.zip (5.0 kB view details)

Uploaded Source

CleanCSS-1.3.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file CleanCSS-1.3.zip.

File metadata

  • Download URL: CleanCSS-1.3.zip
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for CleanCSS-1.3.zip
Algorithm Hash digest
SHA256 175391dbd558110edd8925b982a9ff2e2e9720054ceaf74cf352c46a9d3d4606
MD5 e643e96538b475229a3b15bb8ee17baf
BLAKE2b-256 7925a1894ad1fab4a641f2a1151e3fcdc1409c3526a47ac2c52a4327998e9bf2

See more details on using hashes here.

File details

Details for the file CleanCSS-1.3.tar.gz.

File metadata

  • Download URL: CleanCSS-1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for CleanCSS-1.3.tar.gz
Algorithm Hash digest
SHA256 8627ff613e21c8b534a722424b71bb6af275476a50964adc73cd772ae2c30736
MD5 4fcc34e6a85dafec4b82754474b161e4
BLAKE2b-256 31340d05f255e7fa5169934029e8b6a04df827a9d5b2e2bfbae8c33d349813f1

See more details on using hashes here.

Supported by

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