54 строки
1.3 KiB
ReStructuredText
54 строки
1.3 KiB
ReStructuredText
Zamboni Style Guide
|
|
===================
|
|
|
|
Writing code for zamboni? Awesome! Please help keep our code readable by,
|
|
whenever possible, adhering to these style conventions.
|
|
|
|
|
|
Python
|
|
------
|
|
- see https://wiki.mozilla.org/Webdev:Python
|
|
|
|
|
|
Markup
|
|
------
|
|
- ``<!DOCTYPE html>``
|
|
- double-quote attributes
|
|
- Soft tab (2 space) indentation
|
|
- Title-Case ``<label>``s
|
|
- "Display Name" vs "Display name"
|
|
- to clearfix, use the class ``c`` on an element
|
|
|
|
|
|
JavaScript
|
|
----------
|
|
- Soft tabs (4 space) indentation
|
|
- Single quotes around strings (unless the string contains single quotes)
|
|
- variable names for jQuery objects start with $. for example:
|
|
|
|
- ``var $el = $(el);``
|
|
|
|
- Element IDs and classes that are not generated by Python should be separated
|
|
by hyphens, eg: #some-module.
|
|
- Protect all functions and objects from global scope to avoid potential name
|
|
collisions. When exposing functions to other scripts use
|
|
the ``z`` namespace.
|
|
- Always protect code from loading on pages it's not supposed to load on.
|
|
For example:
|
|
|
|
::
|
|
|
|
$(document).ready(function() {
|
|
if ($('#something-on-your-page').length) {
|
|
initYourCode();
|
|
}
|
|
|
|
function initYourCode() {
|
|
// ...
|
|
}
|
|
});
|
|
|
|
- Write `JavaScript`_ tests whenever possible
|
|
|
|
.. _`JavaScript`: http://jbalogh.github.com/zamboni/topics/testing/#javascript-tests
|