Skip to content

Commit f26278c

Browse files
authored
docs: Update coding styles (#8212)
* docs: Update coding styles * Update docs/contributing/code.rst * Remove mention of static_placeholder
1 parent 2e7b83e commit f26278c

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

docs/contributing/code.rst

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,65 @@ Syntax and conventions
5353
Python
5454
------
5555

56-
We try to conform to `PEP8`_ as much as possible. A few highlights:
56+
We try to conform to `PEP8`_ as much as possible. New code must follow the ruff
57+
formatter (and the pre-commit hook will ensure this). A few highlights:
5758

58-
- Indentation should be exactly 4 spaces. Not 2, not 6, not 8. **4**. Also, tabs
59-
are evil.
60-
- We try (loosely) to keep the line length at 79 characters. Generally the rule
61-
is "it should look good in a terminal-base editor" (eg vim), but we try not be
62-
too inflexible about it.
59+
- **Line Length**: Default is 119 characters.
6360

61+
- **Indentation**: 4 spaces per indentation level; not more, not less.
6462

65-
HTML, CSS and JavaScript
66-
------------------------
63+
- **Quotes**: We use double quotes (`"`).
6764

68-
As of django CMS 3.2, we are using the same guidelines as described in `Aldryn
69-
Boilerplate`_
65+
- **Trailing Commas**: Included where syntactically valid, such as in function arguments and list literals.
7066

71-
Frontend code should be formatted for readability. If in doubt, follow existing
72-
examples, or ask.
67+
- **Function Definitions**: Parameters are each on their own line if the function signature spans multiple lines.
7368

69+
- **Docstrings**: Single-line docstrings use double quotes and are formatted with consistent indentation.
70+
71+
- **Blank Lines**: Two blank lines before top-level definitions; one blank line between methods inside a class.
72+
73+
- **Imports**: Grouped and ordered: standard library, third-party, then local imports. Each group is separated by a blank line.
74+
75+
76+
HTML
77+
----
78+
79+
- **Naming**: Use clear, meaningful names.
80+
- **Indentation**: 4 spaces, no tabs.
81+
- **IDs vs Classes**: Prefer classes.
82+
- **Modularity**: Create reusable components.
83+
84+
CSS
85+
---
86+
87+
- **Naming**: Follow `BEM (Block Element Modifier) <http://getbem.com/>`_.
88+
- **Nesting**: Keep Sass nesting shallow (1–2 levels).
89+
- **Formatting**:
90+
- 4 spaces indentation.
91+
- One selector per line.
92+
- Lowercase properties/values (unless uppercase is needed).
93+
- **Ordering**:
94+
1. Positioning
95+
2. Box model
96+
3. Typography
97+
4. Visual
98+
5. Miscellaneous
99+
100+
JavaScript
101+
----------
102+
103+
- **Naming**:
104+
- `camelCase` for variables/functions
105+
- `PascalCase` for classes
106+
- `UPPER_CASE` for constants
107+
- **Formatting**:
108+
- 4 spaces indentation
109+
- Always use semicolons
110+
- Use single quotes (unlike Python quotes!)
111+
- **Implementation**:
112+
- Wrap code in IIFEs
113+
- Use `'use strict';`
114+
- **Patterns**: Prefer modular, reusable patterns.
74115

75116
.. _js_linting:
76117

docs/how_to/04-templates.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ Example: application template
218218
.. code-block:: html+django
219219

220220
{% extends CMS_TEMPLATE %}
221-
{% load cms_tags %}
221+
{% load cms_tags djangocms_alias_tags %}
222222
{% block main %}
223223
{% for item in object_list %}
224224
{{ item }}
225225
{% endfor %}
226-
{% static_placeholder "sidebar" %}
226+
{% static_alias "sidebar" %}
227227
{% endblock main %}
228228

229229
``CMS_TEMPLATE`` memorises the path of the cms template so the application
@@ -260,4 +260,4 @@ etc.). This introduces some nuances in template inheritance:
260260

261261
This behavior ensures that new translations automatically pick up any template changes that are in progress
262262
(draft state) in the main language, maintaining consistency across translations even before changes are
263-
published.
263+
published.

0 commit comments

Comments
 (0)