Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: README.md

Issue 5718243582935040: Issue 2127 - Adapt README.md for cms repository (Closed)
Patch Set: Addressed comments Created March 12, 2015, 4:39 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cms/bin/test_server.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # adblockplus.org web content # 1 # CMS #
2 2
3 The web content of the adblockplus.org domain is generated automatically from 3 We use this CMS for [adblockplus.org](https://github.com/adblockplus/web.adblock plus.org/)
4 the files in this repository. 4 and related websites. It converts a directory with content data into static
5 files. You are free to use it for other projects but please keep in mind that we
6 make no stability guarantees whatsoever and might change functionality any time.
5 7
6 ## Testing your changes ## 8 ## How to use ##
7 9
8 You can easily test your changes to these files locally. What you need: 10 ### Running the test server ###
11
12 The test server will convert your content directory on the fly, your changes
13 will become visible immediately. To run it you need:
9 14
10 * Python 2.7 15 * Python 2.7
11 * [Flask](http://flask.pocoo.org/), [Jinja2](http://jinja.pocoo.org/) and 16 * [Flask](http://flask.pocoo.org/), [Jinja2](http://jinja.pocoo.org/) and
12 [Markdown](https://pypi.python.org/pypi/Markdown) modules (can be installed by 17 [Markdown](https://pypi.python.org/pypi/Markdown) modules (can be installed by
13 running `easy_install Flask Jinja2 Markdown` from the command line) 18 running `easy_install Flask Jinja2 Markdown` from the command line)
14 * A current copy of the 19 * A current copy of the
15 [sitescripts repository](https://hg.adblockplus.org/sitescripts/) (can be 20 [cms repository](https://github.com/adblockplus/cms/) (can be
16 downloaded from the web or cloned via 21 [downloaded as ZIP file](https://github.com/adblockplus/cms/archive/master.zip )
17 `hg clone https://hg.adblockplus.org/sitescripts/`) 22 or cloned via `git clone https://github.com/adblockplus/cms.git`)
18 23
19 Run the following command from the directory of the sitescripts repository: 24 Run the `runserver.py` script from your content directory, e.g.:
20 25
21 python -m sitescripts.cms.bin.test_server www_directory 26 python ../cms/runserver.py
22 27
23 Here `www_directory` should be replaced by the directory of this repository. 28 Alternatively, the content directory could also be specified as command line
24 This will start a local web server on port 5000, e.g. you can open the about 29 parameter of `runserver.py`. This will start a local web server on port 5000,
25 page as [http://localhost:5000/en/about](http://localhost:5000/en/about). 30 e.g. the page the page `pages/example.md` will be accessible under
31 `http://localhost:5000/en/example`.
26 32
27 ## Configuration ## 33 Note that the test server is inefficient and shouldn't be run in production.
34 There you should generate static files as explained below.
28 35
29 Repository configuration is stored in the `settings.ini` file. The following 36 ### Generating the standalone test server ###
30 sections can be defined: 37
38 The standalone test server is a single binary, without any further dependencies.
39 It can be copied to another system and will no longer require Python or any of
40 its modules. In order to generate the standalone test server you need all the
41 prerequisites required to run the test server and
42 [PyInstaller](https://github.com/pyinstaller/pyinstaller/wiki). PyInstaller can
43 be installed by running `easy_install pyinstaller`.
44
45 Run the following command from the directory of the `cms` repository:
46
47 pyinstaller runserver.spec
48
49 If successful, this will put the standalone test server into the `dist`
50 directory.
51
52 ### Generating static files ###
53
54 On your production server you should convert the content directory into static
55 files. To do that you need:
56
57 * Python 2.7
58 * [Jinja2](http://jinja.pocoo.org/) and
59 [Markdown](https://pypi.python.org/pypi/Markdown) modules (can be installed by
60 running `easy_install Jinja2 Markdown` from the command line)
61 * A current copy of the
62 [cms repository](https://github.com/adblockplus/cms/) (can be
63 [downloaded as ZIP file](https://github.com/adblockplus/cms/archive/master.zip )
64 or cloned via `git clone https://github.com/adblockplus/cms.git`)
65
66 Run the following command from the directory of the `cms` repository:
67
68 python -m cms.bin.generate_static_pages www_directory target_directory
69
70 Here `www_directory` should be replaced by the path to your content directory.
71 `target_directory` is the path where static files will be placed..
72
73 ## Content structure ##
74
75 Currently, the following directories of your content directory will be
76 considered:
77
78 * `filters`: Custom Jinja2 filters
79 * `includes`: Various include files
80 * `locales`: Localization files
81 * `pages`: User-visible pages
82 * `static`: Static content
83 * `templates`: Page layout templates
84
85 There should also be a `settings.ini` file with configuration.
86
87 All of these are explained in more detail below.
88
89 ### Configuration (settings.ini) ###
90
91 The following sections can be defined in `settings.ini`:
31 92
32 * `[general]`: following settings should be listed here: 93 * `[general]`: following settings should be listed here:
33 * `defaultlocale`: The fallback locale, to be used whenever no localized 94 * `defaultlocale`: The fallback locale, to be used whenever no localized
34 page/strings can be found for a locale. 95 page/strings can be found for a locale.
35 * `defaultpage`: the default page which is displayed by the server if the URL 96 * `defaultpage`: the default page which is displayed by the server if the URL
36 doesn't contain a page name. Note that while the test server will consider 97 doesn't contain a page name. Note that while the test server will consider
37 that setting automatically, the real server might need to be configured 98 that setting automatically, the real server might need to be configured
38 accordingly. 99 accordingly.
39 * `[langnames]`: defines the language names correspoding to particular language 100 * `[langnames]`: defines the language names correspoding to particular language
40 codes. 101 codes.
41 * `[rtl]`: any language codes listed here are treated as right-to-left languages . 102 * `[rtl]`: any language codes listed here are treated as right-to-left languages .
42 The values of the settings are ignored. 103 The values of the settings are ignored.
43 * `[locale_overrides]`: every entry defines that a page should use a different 104 * `[locale_overrides]`: every entry defines that a page should use a different
44 locale file, not the one matching its name (to be used when multiple pages 105 locale file, not the one matching its name (to be used when multiple pages
45 share localization data). 106 share localization data).
46 107
47 ## Locales ## 108 ### Localization files ###
48 109
49 The language-specific data is stored in the `locales` directory. Each language 110 The language-specific data is stored in the `locales` directory. Each language
50 (identified by its locale code) is given a subdirectory here. The `json` files 111 (identified by its locale code) is given a subdirectory here. The `.json` files
51 contain localizable strings using the following format: 112 contain localizable strings using the following format:
52 113
53 { 114 {
54 "stringid": { 115 "stringid": {
55 "message": "Translated string", 116 "message": "Translated string",
56 "description": "Optional string description" 117 "description": "Optional string description"
57 }, 118 },
58 ... 119 ...
59 } 120 }
60 121
61 Any other files are considered localizable files and will be available on the 122 Any other files are considered localizable files and will be available on the
62 server unchanged. This is useful for images for example: a language-dependent 123 server unchanged. This is useful for images for example: a language-dependent
63 image can be placed into the `locales/en` directory and a German version 124 image can be placed into the `locales/en` directory and a German version
64 of the same image into the `locales/de` directory. E.g. the file 125 of the same image into the `locales/de` directory. E.g. the file
65 `locales/en/foo.png` will be available on the server under the URL `/en/foo.png` . 126 `locales/en/foo.png` will be available on the server under the URL `/en/foo.png` .
66 127
67 ## Pages ## 128 ### Pages ###
68 129
69 The pages are defined in the `pages` directory. The file extension defines the 130 The pages are defined in the `pages` directory. The file extension defines the
70 format in which a page is specified and won't be visible on the web server. 131 format in which a page is specified and won't be visible on the web server.
71 The page name is prepended by the locale code in the URL, e.g. `pages/foo.md` 132 The page name is prepended by the locale code in the URL, e.g. `pages/foo.md`
72 can be available under the URLs `/en/foo` and `/de/foo` (the English and German 133 can be available under the URLs `/en/foo` and `/de/foo` (the English and German
73 versions respectively). Regardless of the format, a page can define a number of 134 versions respectively). Regardless of the format, a page can define a number of
74 settings using the following format: 135 settings using the following format:
75 136
76 setting = value 137 setting = value
77 138
(...skipping 12 matching lines...) Expand all
90 151
91 The following tag inserts an include file into the page (can be in a different 152 The following tag inserts an include file into the page (can be in a different
92 format): 153 format):
93 154
94 <? include foo ?> 155 <? include foo ?>
95 156
96 Include files should be placed into the `includes` directory of the repository. 157 Include files should be placed into the `includes` directory of the repository.
97 In the case above the contents of `includes/foo.md` or `includes/foo.tmpl` will 158 In the case above the contents of `includes/foo.md` or `includes/foo.tmpl` will
98 be inserted (whichever is present). 159 be inserted (whichever is present).
99 160
100 ### Markdown format (md) ### 161 #### Markdown format (md) ####
101 162
102 This format should normally be used, it allows the pages to be defined using the 163 This format should normally be used, it allows the pages to be defined using the
103 [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax. Raw HTML 164 [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax. Raw HTML
104 tags are allowed and can be used where Markdown syntax isn't sufficient. The 165 tags are allowed and can be used where Markdown syntax isn't sufficient. The
105 [Attribute Lists](http://pythonhosted.org/Markdown/extensions/attr_list.html) 166 [Attribute Lists](http://pythonhosted.org/Markdown/extensions/attr_list.html)
106 extension is active and allows specifying custom attributes for the generated 167 extension is active and allows specifying custom attributes for the generated
107 HTML tags. 168 HTML tags.
108 169
109 Localizable strings are retrieved from the locale file with the name matching 170 Localizable strings are retrieved from the locale file with the name matching
110 the page name. The following syntax can be used: `$foo$` inserts a string named 171 the page name. The following syntax can be used: `$foo$` inserts a string named
111 `foo` from the locale (no HTML code or Markdown syntax allowed in the string). 172 `foo` from the locale (no HTML code or Markdown syntax allowed in the string).
112 The syntax `$foo(foopage, http://example.com/)$` will work similarly but will 173 The syntax `$foo(foopage, http://example.com/)$` will work similarly but will
113 look for `<a>...</a>` blocks in the string: the first will be turned into a link 174 look for `<a>...</a>` blocks in the string: the first will be turned into a link
114 to the page `foopage`, the second will become a link to `http://example.com/`. 175 to the page `foopage`, the second will become a link to `http://example.com/`.
115 176
116 Any content between `<head>` and `</head>` tags will be inserted into the head 177 Any content between `<head>` and `</head>` tags will be inserted into the head
117 of the generated web page, this is meant for styles, scripts and the like. 178 of the generated web page, this is meant for styles, scripts and the like.
118 Other pages should be linked by using their name as link target (relative links) , 179 Other pages should be linked by using their name as link target (relative links) ,
119 these links will be resolved to point to the most appropriate page language. 180 these links will be resolved to point to the most appropriate page language.
120 Embedding localizable images works the same, use the image name as image source. 181 Embedding localizable images works the same, use the image name as image source.
121 182
122 ### Raw HTML format (raw) ### 183 #### Raw HTML format (raw) ####
123 184
124 This format is similar to the Markdown format but uses regular HTML syntax. 185 This format is similar to the Markdown format but uses regular HTML syntax.
125 No processing is performed beyond inserting localized strings and resolving 186 No processing is performed beyond inserting localized strings and resolving
126 links to pages and images. This format is mainly meant for legacy content. 187 links to pages and images. This format is mainly meant for legacy content.
127 188
128 ### Jinja2 format (tmpl) ### 189 #### Jinja2 format (tmpl) ####
129 190
130 Complicated pages can be defined using the 191 Complicated pages can be defined using the
131 [Jinja2 template format](http://jinja.pocoo.org/docs/templates/). Automatic 192 [Jinja2 template format](http://jinja.pocoo.org/docs/templates/). Automatic
132 escaping is active so by default values inserted into the page cannot contain 193 escaping is active so by default values inserted into the page cannot contain
133 any HTML code. Any content between `<head>` and `</head>` tags will be inserted 194 any HTML code. Any content between `<head>` and `</head>` tags will be inserted
134 into the head of the generated web page, everything else defined the content of 195 into the head of the generated web page, everything else defined the content of
135 the page. 196 the page.
136 197
137 The following variables can be used: 198 The following variables can be used:
138 199
139 * `page`: The page name 200 * `page`: The page name
140 * `config`: Contents of the `settings.ini` file in this repository (a 201 * `config`: Contents of the `settings.ini` file in this repository (a
141 [configparser object](http://docs.python.org/2/library/configparser.html)) 202 [configparser object](http://docs.python.org/2/library/configparser.html))
142 * `locale`: Locale code of the page language 203 * `locale`: Locale code of the page language
143 * `available_locales`: Locale codes of all languages available for this page 204 * `available_locales`: Locale codes of all languages available for this page
144 205
145 Following custom filters can be used: 206 Following custom filters can be used:
146 207
147 * `translate(string, locale=None)`: retrieves a string from a locale file. 208 * `translate(string, locale=None)`: retrieves a string from a locale file.
148 Unless a locale is specified the locale file matching the page name is used. 209 Unless a locale is specified the locale file matching the page name is used.
149 * `linkify(url)`: generates an `<a href="...">` tag for the URL. If the URL is 210 * `linkify(url)`: generates an `<a href="...">` tag for the URL. If the URL is
150 a page name it will be converted into a link to the most appropriate page 211 a page name it will be converted into a link to the most appropriate page
151 language. 212 language.
152 * `toclist(html)`: extracts a list of headings from HTML code, this can be used 213 * `toclist(html)`: extracts a list of headings from HTML code, this can be used
153 to generate a table of contents. 214 to generate a table of contents.
154 215
155 ## Static files ## 216 ### Static files ###
156 217
157 Any files located in the `static` directory will be available on the server 218 Any files located in the `static` directory will be available on the server
158 unchanged. The file `static/css/foo.css` will be available under the URL 219 unchanged. The file `static/css/foo.css` will be available under the URL
159 `/css/foo.css`. 220 `/css/foo.css`.
160 221
161 ## Templates ## 222 ### Templates ###
162 223
163 The templates specified in the `templates` directory specify the overall 224 The templates specified in the `templates` directory specify the overall
164 structure that is common for all pages. These templates should have the file 225 structure that is common for all pages. These templates should have the file
165 extension `tmpl` and use the [Jinja2 template format](http://jinja.pocoo.org/doc s/templates/). 226 extension `tmpl` and use the [Jinja2 template format](http://jinja.pocoo.org/doc s/templates/).
166 The differences to pages using the same format are: 227 The differences to pages using the same format are:
167 228
168 * No special treatment of the `<head>` tag. 229 * No special treatment of the `<head>` tag.
169 * Additional variables `head` and `body` are defined with the HTML code that 230 * Additional variables `head` and `body` are defined with the HTML code that
170 should be added to the head and content of the page respectively. 231 should be added to the head and content of the page respectively.
171 232
172 By default, `default.tmpl` will be used for all pages. If other templates are 233 By default, `default.tmpl` will be used for all pages. If other templates are
173 defined, the pages need to choose them explicitly using the `template` setting. 234 defined, the pages need to choose them explicitly using the `template` setting.
235
236 ### Custom filters ###
237
238 The `filters` directory can define custom Jinja2 filters which will be available
239 in all Jinja2 templates. The file name defines the filter name, e.g.
240 `myfilter.py` will define a filter named `myfilter`. This file should also
241 contain a function called `myfilter`, this one will be called when the filter is
242 invoked. For more information on Jinja2 filters see
243 [official documentation](http://jinja.pocoo.org/docs/dev/api/#writing-filters).
OLDNEW
« no previous file with comments | « no previous file | cms/bin/test_server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld