Note
As these conventions were established only after a large part of the code base has been written, the code style described here is not yet in effect in all parts of the Zotonic code base. We’re trying to gradually adapt to it, however.
We use the “Emacs-style” indenting (using erlang-mode provided with the Erlang distribution). This indenting style seems to be a convention in much of the Erlang world.
Provided with the Zotonic distribution is a Zotonic template mode, zotonic-tpl-mode, which supports the Zotonic flavor of ErlyDtl. It is located in the priv/emacs/zotonic-tpl-mode.el file, and may be installed in emacs by adding something like this to your .emacs file:
(add-to-list 'load-path ".../path/to/zotonic/priv/emacs")
(require 'zotonic-tpl-mode)
;; optional, for associating .tpl files with zotonic-tpl-mode
(add-to-list 'auto-mode-alist '("\\.tpl$" . zotonic-tpl-mode))
A common style and shorthand techniques make templates from multiple authors more alike. This makes them easier to maintain and share in a team or with the community.
When the template sees that you request a property of an integer then it assumes that the integer is a m.rsc id. This makes templates more readable.
Example:
<li>
<h3>{{ m.rsc[id].title }}</h3>
{% for image_id in m.rsc[id].o.depiction %}
<figure>
{% media image_id width=100 link=id %}
{% if m.rsc[image_id].summary %}
<p class="image-caption">{{ m.rsc[image_id].summary }}</p>
{% endif %}
</figure>
{% endfor %}
</li>
Can be more effectively written as follows to improve readability:
<li>
<h3>{{ id.title }}</h3>
{% for image_id in id.o.depiction %}
<figure>
{% media image_id width=100 link=id %}
{% if image_id.summary %}
<p class="image-caption">{{ image_id.summary }}</p>
{% endif %}
</figure>
{% endfor %}
</li>
We use spaces everywhere. One tab stop is equal to 4 spaces.
When writing code, do not introduce trailing whitespace and try to keep lines of code shorter than 80 characters.
The Zotonic commit convention are slightly based on rebar’s README.
Structure your commit message like this:
prefix: One line summary (less than 50 characters)
Longer description, multiline text that is supposed to wrap at 72
characters.
Fixes #403
- mod_foobar: Changes that are related to a single module should be prefixed with the module name.
- doc: For changes to the documentation, everything below doc/
- scripts: for changes to the zotonic command and its helper scripts.
- build: for the build system and related changes.
- tests: for unit tests and the testsandbox.
- skel: for the skeleton sites.
- zotonic_status: for the default site.
- translation: for new/updated translations.
- core: For changes in the src, include or deps folder; e.g. anything not covered by another tag.
Notice the empty line preceding the longer description and the “Fixes” tag.
When this is your first contribution to Zotonic, you are welcome to add your name and e-mail address to the CONTRIBUTORS file in the root of the project. Please keep the file alphabetically ordered.