File: javascript.rst

package info (click to toggle)
python-django-waffle 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 684 kB
  • sloc: python: 3,266; makefile: 139; sh: 39; javascript: 34
file content (78 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
.. _usage-javascript:

==============
Using WaffleJS
==============

Waffle supports using :ref:`flags <types-flag>`, :ref:`switches
<types-switch>`, and :ref:`samples <types-sample>` in JavaScript
("WaffleJS") either via inline script or an external script.

.. warning::

    Unlike samples when used in Python, samples in WaffleJS **are only
    calculated once** and so are **consistent**.


The WaffleJS ``waffle`` object
==============================

WaffleJS exposes a global ``waffle`` object that gives access to flags,
switches, and samples.


Methods
-------

These methods can be used exactly like their Python equivalents:

- ``waffle.flag_is_active(flag_name)``
- ``waffle.switch_is_active(switch_name)``
- ``waffle.sample_is_active(sample_name)``


Members
-------

WaffleJS also directly exposes dictionaries of each type, where keys are
the names and values are ``true`` or ``false``:

- ``waffle.FLAGS``
- ``waffle.SWITCHES``
- ``waffle.SAMPLES``


Installing WaffleJS
===================


As an external script
---------------------

Using the ``wafflejs`` view requires adding Waffle to your URL
configuration. For example, in your ``ROOT_URLCONF``::

    urlpatterns = patterns('',
        (r'^', include('waffle.urls')),
    )

This adds a route called ``wafflejs``, which you can use with the
``url`` template tag:

.. code-blocK:: django

    <script src="{% url 'wafflejs' %}"></script>


As an inline script
-------------------

To avoid an extra request, you can also use the ``wafflejs`` template
tag to include WaffleJS as an inline script:

.. code-block:: django

    {% load waffle_tags %}
    <script>
      {% wafflejs %}
    </script>