You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

how_to_handle_statics.rst 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ================================
  2. How to change Oscar's appearance
  3. ================================
  4. This is a guide for Front-End Developers (FEDs) working on Oscar projects, not
  5. on Oscar itself. It is written with Tangent's FED team in mind but should be
  6. more generally useful for anyone trying to customise Oscar and looking for the
  7. right approach.
  8. Overview
  9. ========
  10. Oscar ships with a set of HTML templates and a collection of static files
  11. (eg images, javascript). Oscar's default CSS is generated from LESS
  12. files.
  13. Templates
  14. ---------
  15. Oscar's default templates use the mark-up conventions from Twitter's Bootstrap project.
  16. LESS/CSS
  17. --------
  18. Oscar contains three main LESS files:
  19. * `styles.less`
  20. * `responsive.less`
  21. * `dashboard.less`
  22. These use the LESS files that ship with Twitter's Bootstrap project as well as
  23. some Oscar-specific styling.
  24. A few other CSS files are used to provide styles for javascript libraries.
  25. The core CSS files are not committed to source control to avoid duplication
  26. issues. However, they are included in the released Oscar packages.
  27. By default, the CSS files are used rather than the Less ones. To use Less
  28. directly, set ``USE_LESS = True`` in your settings file. You will also need to
  29. ensure that the ``lessc`` executable is installed and is configured using a
  30. setting like::
  31. COMPRESS_PRECOMPILERS = (
  32. ('text/less', 'lessc {infile} {outfile}'),
  33. )
  34. Using offline compression
  35. ~~~~~~~~~~~~~~~~~~~~~~~~~
  36. Django compressor also provides a way of running offline compression which can
  37. be used during deployment to automatically generate CSS files from your LESS
  38. files. To make sure that compressor is obeying the ``USE_LESS`` setting and
  39. is not trying to compress CSS files that are not available, the setting has to
  40. be passed into the ``COMPRESS_OFFLINE_CONTEXT``. You should add something like
  41. this to your settings file::
  42. COMPRESS_OFFLINE_CONTEXT = {
  43. # this is the only default value from compressor itself
  44. 'STATIC_URL': 'STATIC_URL',
  45. 'use_less': USE_LESS,
  46. }
  47. Javascript
  48. ----------
  49. Oscar uses javascript for progressive enhancements.
  50. For the customer-facing pages, Oscar uses:
  51. * jQuery 1.7
  52. * a few selected plugins to provide functionality for the content blocks that can be set-up.
  53. * the Bootstrap javascript
  54. * an Oscar-specific JS file (ui.js)
  55. In the dashboard, Oscar uses all the JS assets from the customer side as well
  56. as:
  57. * jQuery UI 1.8
  58. * wysihtml5 for HTML textareas
  59. * an Oscar specific JS file for dashboard functionality (dashboard.js)
  60. Customistation
  61. ==============
  62. Customising templates
  63. ---------------------
  64. Oscar ships with a complete set of templates (in ``oscar/templates``). These
  65. will be available to an Oscar project but can be overridden or modified.
  66. The templates use Twitter's Bootstrap conventions for class names and mark-up.
  67. There is a separate recipe on how to do this.
  68. Customising statics
  69. -------------------
  70. Oscar's static files are stored in ``oscar/static``. When a Django site is
  71. deployed, the ``collectstatic`` command is run which collects static files from
  72. all installed apps and puts them in a single location (called the
  73. ``STATIC_ROOT``). It is common for a separate HTTP server (like nginx) to be
  74. used to serve these files, setting its document root to ``STATIC_ROOT``.
  75. For an individual project, you may want to override Oscar's static files. The
  76. best way to do this is to have a statics folder within your project and to add
  77. it to the ``STATICFILES_DIRS`` setting. Then, any files which match the same
  78. path as files in Oscar will be served from your local statics folder instead.
  79. For instance, if you want to use a local version of ``oscar/css/styles.css``,
  80. your could create a file::
  81. yourproject/
  82. static/
  83. oscar/
  84. css/
  85. styles.css
  86. and this would override Oscar's equivalent file.
  87. To make things easier, Oscar ships with a management command for creating a copy
  88. of all of its static files. This breaks the link with Oscar's static files and
  89. means everything is within the control of the project. Run it as follows::
  90. ./manage.py oscar_fork_statics
  91. This is the recommended approach for non-trivial projects.
  92. Another option is simply to ignore all of Oscar's CSS and write your own from
  93. scratch. To do this, you simply need to adjust the layout templates to include
  94. your own CSS instead of Oscar's. For instance, you might override ``base.html``
  95. and replace the 'less' block::
  96. # project/base.html
  97. {% block less %}
  98. <link rel="stylesheet" type="text/less" href="{{ STATIC_URL }}myproject/less/styles.less" />
  99. {% endblock %}