2
0

theming.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .. raw:: html
  2. <div id="banner"><a href="https://github.com/jcbrand/converse.js/blob/master/docs/source/theming.rst">Edit me on GitHub</a></div>
  3. .. _theming:
  4. =======
  5. Theming
  6. =======
  7. Setting up your environment
  8. ===========================
  9. In order to theme Converse, you first need to set up a :ref:`development` environment
  10. and then you'll also want to follow the guide to :ref:`webserver`.
  11. Modifying the HTML templates of Converse
  12. ========================================
  13. Converse uses `lit-html <https://lit-html.polymer-project.org/guide>`_ as HTML
  14. templating library, and the HTML source code is contained in JavaScript ``.js``
  15. files in various ``./template`` directories in the source code.
  16. Some top-level templates are found in the ``./src/templates`` directory, but
  17. usually the templates that are relevant to a specific plugin will be find
  18. inside that plugin's subdirectory.
  19. For example: `src/plugins/chatview/templates <https://github.com/conversejs/converse.js/tree/master/src/plugins/chatview/templates>`_.
  20. You can modify HTML markup that Converse generates by modifying these files.
  21. Use webpack aliases to modify templates without changing the original files
  22. ---------------------------------------------------------------------------
  23. Generally what I do when creating a modified version of Converse for a project
  24. or customer, is that I create a new JavaScript package with its own
  25. ``package.json`` and I then add ``converse.js`` as a dependency (e.g. via ``npm
  26. install --save converse.js``) to the ``package.json``.
  27. Then I add a Webpack configuration and use `webpack aliases <https://webpack.js.org/configuration/resolve/#resolvealias>`_
  28. to resolve template paths to my own modified files.
  29. For example, in the webpack configuration snippet below, I add two aliases, so
  30. that the ``message-body.js`` and ``message.js`` templates can be replaced with
  31. two of my own custom templates.
  32. .. code-block:: javascript
  33. resolve: {
  34. extensions: ['.js'],
  35. alias: {
  36. './message-body.js': path.resolve(__dirname, 'path/to/my/custom/message-body.js'),
  37. './templates/message.js': path.resolve(__dirname, 'path/to/my/custom/chat_message.js'),
  38. }
  39. }
  40. Modifying the CSS
  41. =================
  42. The CSS files are generated from `Sass <http://sass-lang.com>`_ files that end in ``.scss`` and
  43. which are distributed throughout the source code.
  44. Similarly to the template files, the CSS that is relevant to a particular plugin
  45. is usually inside the ``./styles`` directory inside the relevant plugin
  46. directory.
  47. For example: `src/plugins/controlbox/styles <https://github.com/conversejs/converse.js/tree/master/src/plugins/controlbox/styles>`_.
  48. To generate the CSS you can run::
  49. make css