API¶
djangojs – Main package¶
Django.js provide better integration of javascript into Django.
- djangojs.JQUERY_DEFAULT_VERSION = '2.0.2'¶
Packaged jQuery version
djangojs.views – Javascript views helpers¶
This module provide helper views for javascript.
- class djangojs.views.JsInitView(**kwargs)[source]¶
Bases: django.views.generic.base.TemplateView
Render a javascript file containing the URLs mapping and the context as JSON.
- class djangojs.views.JsonView(**kwargs)[source]¶
Bases: django.views.generic.base.View
A views that render JSON.
- class djangojs.views.UrlsJsonView(**kwargs)[source]¶
Bases: djangojs.views.JsonView
Render the URLs as a JSON object.
- class djangojs.views.ContextJsonView(**kwargs)[source]¶
Bases: djangojs.views.JsonView
Render the context as a JSON object.
- class djangojs.views.JsTestView(**kwargs)[source]¶
Bases: django.views.generic.base.TemplateView
Base class for JS tests views
- django_js = False¶
Includes or not Django.js in the test view
- jquery = False¶
Includes or not jQuery in the test view.
- js_files = None¶
A path or a list of path to javascript files to include into the view.
- Supports glob patterns.
- Order is kept for rendering.
- class djangojs.views.JasmineView(**kwargs)[source]¶
Bases: djangojs.views.JsTestView
Render a Jasmine test runner.
- class djangojs.views.QUnitView(**kwargs)[source]¶
Bases: djangojs.views.JsTestView
Render a QUnit test runner
- theme = u'qunit'¶
QUnit runner theme.
Should be one of: qunit, gabe, ninja, nv
djangojs.runners – Javascript unittest runners¶
This module provide Javascript test runners for Django unittest.
- class djangojs.runners.JsTestCase(methodName='runTest')[source]¶
Bases: djangojs.runners.PhantomJsRunner, django.test.testcases.LiveServerTestCase
A PhantomJS suite that run against the Django LiveServerTestCase
- url_args = None¶
an optionnal arguments array to pass to the reverse() function
- url_kwargs = None¶
an optionnal keyword arguments dictionnary to pass to the reverse() function
- url_name = None¶
a mandatory named URL that point to the test runner page
- class djangojs.runners.JsFileTestCase(methodName='runTest')[source]¶
Bases: djangojs.runners.PhantomJsRunner, unittest.case.TestCase
A PhantomJS suite that run against a local html file
- filename = None¶
absolute path to the test runner page
- class djangojs.runners.JsTemplateTestCase(methodName='runTest')[source]¶
Bases: djangojs.runners.JsFileTestCase
A PhantomJS suite that run against a rendered html file but without server.
Note
Template is rendered using a modified static storage that give file:// scheme URLs. To benefits from it, you have to use either the static template tag or one the djangojs template tags.
Warning
Template is not rendered within a request/response dialog. You can’t access the request object and everything that depends on the server.
- jquery = False¶
Includes or not jQuery in the test view. Template has to handle the use_jquery property.
- js_files = None¶
A path or a list of path to javascript files to include into the view.
- Supports glob patterns.
- Order is kept for rendering.
- template_name = None¶
absolute path to the test runner page
- exception djangojs.runners.JsTestException(message, failures=None)[source]¶
Bases: exceptions.Exception
An exception raised by Javascript tests.
It display javascript errors into the exception message.
- class djangojs.runners.JasmineSuite[source]¶
Bases: object
A mixin that runs a jasmine test suite with PhantomJs.
djangojs.utils – Miscellaneous helpers¶
This modules holds every helpers that does not fit in any standard django modules.
It might be splitted in futur releases.
djangojs.tap – Tap format parser¶
This module provide test runners for JS in Django.
djangojs.templatetags.js – Javascript template tags¶
Provide template tags to help with Javascript/Django integration.
Bases: django.template.base.Node
Wrap {% verbatim %} and {% endverbatim %} around a block of javascript template and this will try its best to output the contents with no changes.
{% verbatim %} {% trans "Your name is" %} {{first}} {{last}} {% endverbatim %}
A simple shortcut to render a script tag to a static coffeescript file
A simple shortcut to render a script tag to a static coffeescript file
A simple shortcut to render a link tag to a static CSS file
Include Django.js javascript library in the page
Include Django.js javascript library initialization in the page
A simple shortcut to render a script tag to a static javascript file
A shortcut to render a script tag for the packaged jQuery
A simple shortcut to render a script tag to a static javascript file
Renders verbatim tags
Javascript templates (jquery, handlebars.js, mustache.js) use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates, because Django thinks {{ and }} means something.
The following code preserves {{ }} tokens.
This version of verbatim template tag allows you to use tags like url {% url name %}. {% trans “foo” %} or {% csrf_token %} within.
- Inspired by:
- Miguel Araujo: https://gist.github.com/893408