Skip to main content

Transparent integration of ClojureScript in a Django project. Currently supports Leiningen and Figwheel, which means you can rely on Figwheel’s auto-refresh features during development.

This project is heavily inspired by the django-webpack-loader project, which has the similar goal of transparently including and using Webpack bundles in a Django project.

The integration with Leiningen is simplistic: information is read from the Leiningen project.clj file to determine which output bundles are available and where. This means that there is a tight coupling to the structure of the Leiningen project file – expect things to break if you have a really exotic project setup!

Install

$> pip install django-cljs-loader

Usage

Examples

This repository contains one example application, have a look at that to see a working setup in action.

Some more advanced examples are on the way!

Settings

Only Leiningen projects are supported. With a project.clj file somewhere in your project, you can set the django-cljs loader up in your app settings.

It should look something like this:

from edn_format.edn_lex import Keyword

BASE_DIR = ...  # should point to the project root

STATIC_URL = '/static/'

CLJS_LOADER = {
    # where to find the Leiningen project file
    'PROJECT_FILE': os.path.join(BASE_DIR, 'project.clj'),

    # If True, tries to load JS files from the Figwheel dev server.
    # Set to False in production mode.
    'FIGWHEEL': True,

    # Which cljs build (defined in the project.clj file) to use.
    # Change this for production.
    'CLJS_BUILD': Keyword('dev'),

    # The root folder for assets built by Leiningen.
    # In development mode, this matches the Figwheel root.
    'ROOT': 'assets/public',
}

# Add the folder where cljsbuild output lands as a source directory for the
# staticfiles app. This assumes you are using the staticfiles app.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, CLJS_LOADER['ROOT']),
)

Where you put the ClojureScript source files is up to you - assets/cljs is one possibility. See the example projects.

Template tag

Use the render_bundle template tag to hook the compiled ClojureScript bundle into your application. It will insert a script tag and call the main function you have defined in the Leiningen project file.

{% load render_bundle from cljs_loader %}
...
<body>
  ...
  {% render_bundle %}
</body>

Development

Open a second terminal and run lein figwheel. Alternatively, launch a REPL and do (fig-start). The JavaScript bundle will be loaded from the Figwheel development server.

Production

Assuming you have a cljsbuild profile called prod:

$> lein cljsbuild once prod

The compiled bundle that is produced by lein cljsbuild can be collected with python manage.py collectstatic, or whichever your preferred method of including production assets is.

The render_bundle template tag does not need to change.

Contributing

You can run the test suite in the tests folder with the following command:

$> make test

Metadata

Release files for django-cljs-loader 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cljs-loader 0.1.1
File Size Uploaded
django-cljs-loader-0.1.1.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cljs-loader 0.1.1
File Interpreter ABI Platform
django_cljs_loader-0.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 13.1 kB

Release files / django-cljs-loader-0.1.1.tar.gz

Download URL django-cljs-loader-0.1.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0ea7ef468e6a3a5f6009c9dacd5f46e6982a49fd362cfc1eacaf505a474a318c
BLAKE2b-256 checksum
How to use checksums
2f0ee37028a91f3ede3f6506295269974b9a8c4f788030371da6258e0510ecee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_cljs_loader-0.1.1-py2.py3-none-any.whl

Download URL django_cljs_loader-0.1.1-py2.py3-none-any.whl
Size 8.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2118eb258e2629f976ac1e6839093d8df175d4b93831e8e4c87cbed41a22828d
BLAKE2b-256 checksum
How to use checksums
1fcbee548e02793e9bebbfea085f1f6e6dbe8f33d67b93b67f53c012b9bde46b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page