index.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. Contributing
  2. ============
  3. Developing CodeRed CMS
  4. ----------------------
  5. To create a test project locally:
  6. #. Clone the code from https://github.com/coderedcorp/coderedcms.
  7. #. Run ``pip install -e ./[dev]`` from the root coderedcms directory. The -e flag makes the install editable,
  8. which is relevant when running ``makemigrations`` in test project to actually generate the migration
  9. files in the coderedcms pip package. The ``[dev]`` installs extras such as sphinx for generating docs.
  10. #. Follow the steps in :doc:`/getting_started/install`. Use ``testproject`` for
  11. your project name to ensure it is ignored by git.
  12. #. When making model or block changes within coderedcms, run ``makemigrations coderedcms`` in the
  13. test project to generate the relevant migration files for the pip package. ALWAYS follow steps
  14. 4 and 5 in :doc:`/getting_started/install` with a fresh database before making migrations.
  15. #. When model or block changes affect the local test project (i.e. the "website" app), run
  16. ``makemigrations website`` in the test project to generate the relevant migration files locally.
  17. Apply and test the migrations. When satisfied, re-generate the ``0001_initial.py`` migration in
  18. ``project_template/website/migrations/`` as so:
  19. #. Create a new test project using ``coderedcms start testproject``.
  20. #. Before running migrations, DELETE all migrations in ``testproject/website/migrations/``.
  21. #. Run ``python manage.py makemigrations website``. This should generate an ``0001_initial.py``
  22. migration.
  23. #. Replace ``project_template/website/migrations/0001_initial.py`` with your newly generated migration.
  24. When making changes that are potentially destructive or backwards incompatible, increment the minor
  25. version number until coderedcms reaches a stable 1.0 release. Each production project that uses
  26. coderedcms should specify the appropriate version in its requirements.txt to prevent breakage.
  27. .. note::
  28. When testing existing projects with coderedcms installed from the master or development branches,
  29. be sure to use a disposable database, as it is likely that the migrations in master will
  30. not be the same migrations that get released.
  31. CSS Development
  32. ---------------
  33. When CSS changes are needed for front-end code (not the wagtail admin), Sass should be used.
  34. Each block, page, snippet, or other component that requires styling should have a dedicated ``.scss``
  35. file created beginning with an underscore in ``coderedcms/static/scss/``. Then import the file
  36. in our main ``codered-front.scss`` file. Then build a human readable and minified version of CSS
  37. from the command prompt as so:
  38. .. code-block:: console
  39. $ cd coderedcms/static/coderedcms/
  40. // Build human readable CSS, and source map for nicer debugging.
  41. $ pysassc -g -t expanded scss/codered-front.scss css/codered-front.css
  42. // Build minified CSS.
  43. $ pysassc -t compressed scss/codered-front.scss css/codered-front.min.css
  44. Finally, copy the license header comment into codered-front.min.css (since ``pysassc`` does
  45. not have an argument to preserve comments while also using compressed output).
  46. The generated CSS files must also be committed to version control whenever a sass file is
  47. changed, as they are distributed as part of our package.
  48. JavaScript Development
  49. ----------------------
  50. All JavaScript should use ``codered-front.js`` as an entry point, meaning feature
  51. detection should happen in ``codered-front.js`` and then only load secondary scripts and CSS
  52. as needed. This ensures only one single small JavaScript file is required on page load, which
  53. reduces render-blocking resources and page load time.
  54. All JavaScript files produced by CodeRed should contain a license header comment. This standard
  55. license header comment states copyright, ownership, license, and also provides compatibility for
  56. `LibreJS <https://www.gnu.org/software/librejs/free-your-javascript.html>`_.
  57. .. code-block:: text
  58. /*
  59. CodeRed CMS (https://www.coderedcorp.com/cms/)
  60. Copyright 2018-2019 CodeRed LLC
  61. License: https://github.com/coderedcorp/coderedcms/blob/master/LICENSE
  62. @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
  63. */
  64. ... script code here ...
  65. /* @license-end */
  66. Testing CodeRed CMS
  67. -------------------
  68. To run the built in tests for CodeRed CMS using Django, run the following:
  69. .. code-block:: console
  70. $ python testproject/manage.py test coderedcms --settings=coderedcms.tests.settings
  71. Or, to use ``pytest`` and output a unit test report and code coverage report (this how CI runs the tests):
  72. .. code-block:: console
  73. $ pytest coderedcms/ --ds=coderedcms.tests.settings --junitxml=junit/test-results.xml --cov=coderedcms --cov-report=xml --cov-report=html
  74. Detailed test coverage reports are now available by opening ``htmlcov/index.html`` in your browser (which is ignored by version control)
  75. Adding New Tests
  76. ----------------
  77. Test coverage at the moment is fairly minimal and it is highly recommended that new features and models include proper unit tests.
  78. Any testing infrastructure (i.e. implementations of abstract models and migrations) needed should be added to the ``tests`` app in your
  79. local copy of CodeRed CMS. The tests themselves should be in their relevant section in CodeRed CMS (i.e. tests for
  80. models in ``coderedcms.models.page_models`` should be located in ``coderedcms.models.tests.test_page_models``).
  81. For example, here is how you would add tests for a new abstract page type, ``CoderedCustomPage`` that would live in ``coderedcms/models/page_models.py``:
  82. 1. Navigate to ``coderedcms/tests/testapp/models.py``
  83. 2. Add the following import: ``from coderedcms.models.page_models import CoderedCustomPage``
  84. 3. Implement a concrete version of ``CoderedCustomPage``, i.e. ``CustomPage(CoderedCustomPage)``.
  85. 4. Run ``python manage.py makemigrations`` to make new testing migrations.
  86. 5. Navigate to ``coderedcms/models/tests/test_page_models.py``
  87. 6. Add the following import: ``from coderedcms.models import CoderedCustomPage``
  88. 7. Add the following import: ``from coderedcms.tests.testapp.models import CustomPage``
  89. 8. Add the following to the bottom of the file:
  90. .. code-block:: python
  91. class CoderedCustomPageTestCase(AbstractPageTestCase, WagtailPageTests):
  92. model = CoderedCustomPage
  93. 9. Add the following to the bottom of the file:
  94. .. code-block:: python
  95. class CustomPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
  96. model = CustomPage
  97. 10. Write any specific test cases that ``CoderedCustomPage`` and ``CustomPage`` may require.
  98. Static Analysis
  99. ---------------
  100. Flake8 is used to check for syntax and style errors. To analyze the entire codebase, run:
  101. .. code-block:: console
  102. $ flake8 .
  103. Alternatively, our continuous integration only analyzes the diff between your changes
  104. and master. To analyze just the diff of your current changes, run the
  105. `PowerShell Core <https://github.com/powershell/powershell>`_ script:
  106. .. code-block:: console
  107. $ ./ci/run_flake8.ps1
  108. A Note on Cross-Platform Support
  109. --------------------------------
  110. CodeRed CMS works equally well on Windows, MacOS, and Linux. When adding new features
  111. or new dependencies, ensure that these utilize proper cross-platform utilities in Python.
  112. For shell or automation scripts, we default to
  113. `PowerShell Core <https://github.com/powershell/powershell>`_ because it provides high quality
  114. commercial support for Windows, MacOS, and Linux.
  115. Our goal is that users of any platform can develop or host a CodeRed CMS website easily.
  116. Contributor Guidelines
  117. ----------------------
  118. We are happy to accept pull requests from the community if it aligns with our vision for coderedcms.
  119. When creating a pull request, please make sure you include the following:
  120. * A description in the pull request of what this change does and how it works.
  121. * Reference to an issue if the change is related to one of the issues on our GitHub page.
  122. * Documentation updates in the ``docs/`` directory describing your change.
  123. Following submission of your pull request, a CodeRed member will review and test your change.
  124. **All changes, even by CodeRed members, must go through a pull request process to ensure quality.**
  125. Building Python Packages
  126. ------------------------
  127. To build a publicly consumable pip package, run:
  128. .. code-block:: console
  129. $ python setup.py sdist bdist_wheel
  130. Building Documentation
  131. ----------------------
  132. For every code or feature change, be sure to update the docs in the repository. To build and publish
  133. the documentation run:
  134. .. code-block:: console
  135. $ cd docs/
  136. $ make clean
  137. $ make html
  138. .. note::
  139. Windows users should run ``make.bat`` instead of ``make`` above.
  140. Output will be in ``docs/_build/html/`` directory.
  141. Publishing a New Release
  142. ------------------------
  143. First checkout the code/branch for release.
  144. Next build a pip package:
  145. .. code-block:: console
  146. $ python setup.py sdist bdist_wheel
  147. Then upload the pip package to the Python Package Index:
  148. .. code-block:: console
  149. $ twine upload dist/*
  150. Finally build and update docs:
  151. .. code-block:: console
  152. $ cd docs/
  153. $ make clean
  154. $ make html
  155. .. note::
  156. Windows users should run ``make.bat`` instead of ``make`` above.
  157. If updating docs for an existing minor version release:
  158. #. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under the existing version directory.
  159. If this is a new major or minor version release:
  160. #. Create a new ``major.minor`` directory on the CodeRed docs server.
  161. #. Update the ``stable`` symbolic link to point to the new version directory.
  162. #. Add the new version to the ``versions.txt`` file on the docs server.
  163. #. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under the new version directory.
  164. Note that we do not release separate documentation versions for maintenance releases. Update the existing minor
  165. version docs with release notes and other changes.