Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
handful of python scripts to facilitate in web development and deployment.
Python
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
README.md
css_concatenate.py
css_datauri.py

README.md

python-tasks-for-webdev

handful of python scripts to facilitate in web development and deployment.

css-concatenate

Concatenates url resource contents declared in @import directives of a single file.

example

directory structure

|-project
    |---tools
        +- css-concatenate.py
    |---style
        +- main.css
        +- one.css
        +- two.css
    +- index.html

main.css

@import url("one.css");
@import url("two.css");
body {
    margin: 0;
    padding: 0;
}

one.css

ul {
    list-style: none;
}

two.css

a {
    text-decoration: none;
}

usage

$project> ./tools/css-concatenate.py ./style/main.css

produces

main.css

ul {
    list-style: none;
}
a {
    text-decoration: none;
}
body {
    margin: 0;
    padding: 0;
}

known shortcomings

  • Currently only supports @import from local disk.
  • Not recursive; if resource itself has @imports, does not replace those.
  • Overwrites to input file.

css_datauri

Data URI util.

Traverses a directory and encodes asset files to base64 and replaces relative URL references in CSS files with the base64 string.

example

directory structure

|-project
    |---tools
        +- css_datauri.py
    |---style
        |-----assets
            +- image.png
        +- main.css

main.css

.background {
    background-image: url('assets/image.png')
}

usage

$project> ./tools/css_datauri.py style

produces

main.css

.background {
    background-image: url('data:img/jpg;base64,/9j/4AAQSkZJRgABAQ...'
}

known shortcomings

  • Overwrites CSS files; no option for -output directory. As such, it is recommended first to copy all files over to a distribution directory before running the css_datauri task.
  • Finds only relative paths in CSS.
  • If supplied path starts with './' or ends in '/', relative path detection does not work properly; for now, ensure that the supplied directory argument does not have a prefixed './' or trailing '/'.
Something went wrong with that request. Please try again.