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.
## 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`](https://github.com/roverdotcom/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` or `inlinejs` where you want to pull in a static file:
```
{% inlinejs 'path/to/my.js' %}
{% inlinecss 'path/to/my.css' %}
```
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 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.
## Issues, Suggestions, Contributions
...are welcome on GitHub. Thanks for your interest in `simpleinliner`!
A simple Django app for inlining static CSS and JS files in templates.
## 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`](https://github.com/roverdotcom/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` or `inlinejs` where you want to pull in a static file:
```
{% inlinejs 'path/to/my.js' %}
{% inlinecss 'path/to/my.css' %}
```
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 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.
## Issues, Suggestions, Contributions
...are welcome on GitHub. Thanks for your interest in `simpleinliner`!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-simpleinliner-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd07a662b974622aefb4ea8ca2e9cba8659e3f7256dfd1adf4d4ca2584cf4715 |
|
MD5 | 5d9ce8842a8391b9d678327532bcbdc7 |
|
BLAKE2b-256 | 1a2a2094688cb6a21b5dfafd1baf3cd51d6ca4a9b5dbf38f03faa8eb69b724ef |