Skip to main content

A simple Django app for inlining static files in templates.

Project description

django-simpleinliner

A simple Django app for inlining static CSS and JS files in templates. Read CSS, JS or generic files from your static directories and insert them inline into your Django templates, wrapping in appropriate HTML tags if necessary.

Rationale

Provides a quick and easy way to inline an entire JS or CSS file from staticfiles into a template, wrapping it in appropriate tags. django-compressor does this but I wanted something more lightweight, and also wanted to try my hand at writing a Django extension. Some inspiration and staticfile-handling code was taken from django-inlinecss.

Installation

$ pip install django-simpleinliner

Add simpleinliner to your INSTALLED_APPS setting.

Usage

Load the app at the top of your template:

{% load simpleinliner %}

Call inlinecss, inlinejs or inlinegeneric where you want to pull in a static file:

{% inlinejs 'path/to/my.js' %}

{% inlinecss 'path/to/my.css' %}

{% inlinegeneric 'path/to/my.svg' %}

The file will be inserted into the template each time the template is rendered, keeping it up to date.

You can override the default attributes given to <script> and <style> tags generated by simpleinliner by including the following in your project settings:

SIMPLEINLINER_DEFAULT_TAG_ATTRIBUTES = {
    'script': {
        'charset': 'utf-8',
        'type': 'text/javascript',
    },
    'style': {
        'charset': 'utf-8',
        'type': 'text/css',
    },
}

Add or edit these as desired to change the attributes applied to these tags.

By default simpleinliner will silently fail (including an empty tag if using inlinejs or inlinecss) if the specified path doesn't exist. You can force it to raise an exception by setting SIMPLEINLINER_RAISE_EXCEPTIONS to True in your project settings.

Credits

Since version 0.2.5 this library bundles version 1.16 of the html library (in html.py), as that library does not correctly install itself in modern python/setuptools environments and cannot be correctly imported.

Issues, Suggestions, Contributions

...are welcome on GitHub. Thanks for your interest in simpleinliner!

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

django-simpleinliner-0.2.5.tar.gz (11.3 kB view details)

Uploaded Source

File details

Details for the file django-simpleinliner-0.2.5.tar.gz.

File metadata

  • Download URL: django-simpleinliner-0.2.5.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.6

File hashes

Hashes for django-simpleinliner-0.2.5.tar.gz
Algorithm Hash digest
SHA256 b71f21a9c3d497e08fcda6d1f86c050a7054cb8417b9031e390876cac17cad8f
MD5 51b99f41a5e871a0bff3d9bc6b063b13
BLAKE2b-256 ca528d10af235043020e5c550126a02fc9fa83beef175edda0bba5fc9f2ca5d5

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