Remove product literal strings in "pht()", part 5
[phabricator.git] / src / docs / contributor / adding_new_css_and_js.diviner
blob00a3808fba4f161ec45a8060648af5d8a370d148
1 @title Adding New CSS and JS
2 @group developer
4 Explains how to add new CSS and JS files to Phabricator.
6 = Overview =
8 Phabricator uses a system called **Celerity** to manage static resources. If you
9 are a current or former Facebook employee, Celerity is based on the Haste system
10 used at Facebook and generally behaves similarly.
12 This document is intended for Phabricator developers and contributors. This
13 process will not work correctly for third-party code, plugins, or extensions.
15 = Adding a New File =
17 To add a new CSS or JS file, create it in an appropriate location in
18 `webroot/rsrc/css/` or `webroot/rsrc/js/` inside your `phabricator/`
19 directory.
21 Each file must `@provides` itself as a component, declared in a header comment:
23   LANG=css
24   /**
25    * @provides duck-styles-css
26    */
28   .duck-header {
29     font-size: 9001px;
30   }
32 Note that this comment must be a Javadoc-style comment, not just any comment.
34 If your component depends on other components (which is common in JS but
35 rare and inadvisable in CSS), declare then with `@requires`:
37   LANG=js
38   /**
39    * @requires javelin-stratcom
40    * @provides duck
41    */
43   /**
44    * Put class documentation here, NOT in the header block.
45    */
46   JX.install('Duck', {
47     ...
48   });
50 Then rebuild the Celerity map (see the next section).
52 = Changing an Existing File =
54 When you add, move or remove a file, or change the contents of existing JS or
55 CSS file, you should rebuild the Celerity map:
57   phabricator/ $ ./bin/celerity map
59 If you've only changed file content things will generally work even if you
60 don't, but they might start not working as well in the future if you skip this
61 step.
63 The generated file `resources/celerity/map.php` causes merge conflicts
64 quite often. They can be resolved by running the Celerity mapper. You can
65 automate this process by running:
67   phabricator/ $ ./scripts/celerity/install_merge.sh
69 This will install Git merge driver which will run when a conflict in this file
70 occurs.
72 = Including a File =
74 To include a CSS or JS file in a page, use
75 @{function:require_celerity_resource}:
77   require_celerity_resource('duck-style-css');
78   require_celerity_resource('duck');
80 If your map is up to date, the resource should now be included correctly when
81 the page is rendered.
83 You should place this call as close to the code which actually uses the resource
84 as possible, i.e. **not** at the top of your Controller. The idea is that you
85 should @{function:require_celerity_resource} a resource only if you are actually
86 using it on a specific rendering of the page, not just because some views of the
87 page might require it.
89 = Next Steps =
91 Continue by:
93   - reading about Javascript-specific guidelines in @{article:Javascript Coding
94     Standards}; or
95   - reading about CSS-specific guidelines and features in @{article:CSS Coding
96     Standards}.