1
0

METADATA 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Metadata-Version: 2.1
  2. Name: django-js-asset
  3. Version: 2.2.0
  4. Summary: script tag with additional attributes for django.forms.Media
  5. Project-URL: Homepage, https://github.com/matthiask/django-js-asset/
  6. Author-email: Matthias Kestenholz <mk@feinheit.ch>
  7. License: BSD-3-Clause
  8. License-File: LICENSE
  9. Classifier: Environment :: Web Environment
  10. Classifier: Framework :: Django
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: BSD License
  13. Classifier: Operating System :: OS Independent
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 3 :: Only
  16. Classifier: Programming Language :: Python :: 3.8
  17. Classifier: Programming Language :: Python :: 3.9
  18. Classifier: Programming Language :: Python :: 3.10
  19. Classifier: Programming Language :: Python :: 3.11
  20. Classifier: Programming Language :: Python :: 3.12
  21. Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
  22. Classifier: Topic :: Software Development
  23. Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
  24. Requires-Python: >=3.8
  25. Requires-Dist: django>=3.2
  26. Provides-Extra: tests
  27. Requires-Dist: coverage; extra == 'tests'
  28. Description-Content-Type: text/x-rst
  29. ===============================================================================
  30. django-js-asset -- script tag with additional attributes for django.forms.Media
  31. ===============================================================================
  32. .. image:: https://github.com/matthiask/django-js-asset/workflows/Tests/badge.svg
  33. :target: https://github.com/matthiask/django-js-asset
  34. Usage
  35. =====
  36. Use this to insert a script tag via ``forms.Media`` containing additional
  37. attributes (such as ``id`` and ``data-*`` for CSP-compatible data
  38. injection.):
  39. .. code-block:: python
  40. from js_asset import JS
  41. forms.Media(js=[
  42. JS("asset.js", {
  43. "id": "asset-script",
  44. "data-answer": "42",
  45. }),
  46. ])
  47. The rendered media tag (via ``{{ media.js }}`` or ``{{ media }}`` will
  48. now contain a script tag as follows, without line breaks:
  49. .. code-block:: html
  50. <script type="text/javascript" src="/static/asset.js"
  51. data-answer="42" id="asset-script"></script>
  52. The attributes are automatically escaped. The data attributes may now be
  53. accessed inside ``asset.js``:
  54. .. code-block:: javascript
  55. var answer = document.querySelector("#asset-script").dataset.answer;
  56. Also, because the implementation of ``static`` differs between supported
  57. Django versions (older do not take the presence of
  58. ``django.contrib.staticfiles`` in ``INSTALLED_APPS`` into account), a
  59. ``js_asset.static`` function is provided which does the right thing
  60. automatically.
  61. When adding external script assets, you should pass ``static=False`` to the
  62. ``JS`` object to avoid passing the script URL through ``static()``. In this
  63. case, you probably want to add ``defer`` or ``async``, and maybe also
  64. ``integrity`` and ``crossorigin`` attributes. Please note that boolean
  65. attributes are not properly supported when using Django before 4.1 so specify
  66. them as follows:
  67. .. code-block:: python
  68. JS(
  69. "https://cdn.example.com/script.js",
  70. {"defer": "defer"},
  71. static=False,
  72. )
  73. Compatibility
  74. =============
  75. At the time of writing this app is compatible with Django 1.8 and better
  76. (up to and including the Django master branch), but have a look at the
  77. `tox configuration
  78. <https://github.com/matthiask/django-js-asset/blob/main/tox.ini>`_ for
  79. definitive answers.