Pārlūkot izejas kodu

Clean up theme docs and add overview.

Brit Butler 12 gadi atpakaļ
vecāks
revīzija
5f76d94e42
2 mainītis faili ar 244 papildinājumiem un 340 dzēšanām
  1. 56 0
      docs/overview.md
  2. 188 340
      docs/themes.md

+ 56 - 0
docs/overview.md

@@ -0,0 +1,56 @@
1
+## Overall Structure
2
+
3
+Conceptually, coleslaw processes a blog as follows:
4
+
5
+1.  Coleslaw loads the user's config, then reads a directory containing
6
+    `.post` files and processes them into POST and INDEX objects.
7
+
8
+2.  The POST and INDEX objects are then fed to the templating engine
9
+    to produce HTML files.
10
+
11
+3.  A deploy method is called (possibly customized with plugins) to make
12
+    the resulting HTML files (and any static content) visible to the web.
13
+
14
+## What files are generated anyway?
15
+
16
+Before we dive into other details, it is useful to know the directory
17
+structure of the generated content, so you know how the relative path
18
+different content resides at.
19
+
20
+The blog's toplevel looks like this:
21
+```
22
+index.html
23
+posts/
24
+date/
25
+tag/
26
+css/
27
+static/ (optional)
28
+```
29
+
30
+### index.html
31
+
32
+This file is the blog homepage, as you'd expect.  It contains a list of
33
+the most recent posts and has links to the different archives.
34
+
35
+### posts directory
36
+
37
+This directory contains an `.html` file per post.  The name of the file
38
+is the post's `slug`.
39
+
40
+### date directory
41
+
42
+This directory contains an `.html` file per month, for each month with
43
+published content. The name of the file is of the form `yyyy-mm.html`.
44
+
45
+### tag directory
46
+
47
+This directory contains an `.html` file per tag, each containing all
48
+posts with that tag. The name of the file is the tag's `slug`.
49
+
50
+### css directory
51
+
52
+This directory is a copy of the `css/` folder of the theme.
53
+
54
+### static directory (optional)
55
+
56
+This directory is a copy of the `static/` directory of the blog's git repo.

+ 188 - 340
docs/themes.md

@@ -1,377 +1,225 @@
1 1
 # Themes
2 2
 
3
-The theming support in coleslaw is very flexible, and relatively easy
4
-to use.  However it does require some knowledge of HTML, CSS and
5
-[Closure Templates][clt], and of course how coleslaw converts
6
-posts into a collection of HTML files.
7
-
8
-This document will focus mainly on the part of how coleslaw converts
9
-posts into a blog, and how you can influence the resulting HTML.
10
-
11
-## Overall Structure
12
-
13
-Conceptually the process of creating a blog with coleslaw is the following:
14
-
15
-1.  Coleslaw read a directory containt `.post` files and processes them
16
-	into HTML fragments.
17
-
18
-2.  The HTML fragments of the posts are processed with the templating engine,
19
-	to produce different HTML files.
20
-
21
-And for theming purposes, an important final step
22
-
23
-3.  A browser renders the generated HTML and styles it with CSS.
24
-
25
-The first step, the translation from markdown to HTML fragments is fixed, you cannot
26
-really influence that in a (theming) meaningful way.
27
-
28
-The theming is done in the last two steps, the templating and the CSS.
29
-
30
-Now both steps have a different role:
31
-
32
-1.  **Templating**, this determines the file structure of the
33
-	generated HTML.   This part inserts headers, footers, include
34
-    the CSS stylesheets and other resources.
35
-
36
-	This is also the place where you can add for example a table of contents
37
-    of the posts, or where the list of tags will be inserted etc.
38
-
39
-	Also, very importantly, by generating the right HTML `<div>` elements
40
-	it will make it easy to style the resulting HTML with CSS.
41
-	
42
-
43
-2.  **CSS**, this is the part which will determine the look of all the components.
44
-	For example the font and font size of the titles and sub titles.
45
-
46
-	But *CSS* is very well covered in the literature and we will not
47
-	cover how to use *CSS* in this document.  But it is good to remember that
48
-	if you are struggling to achieve a certain effect with CSS, it might
49
-    be easy to solve by modifying the template.  Either by changing the structure
50
-	of the document or by adding the right `id` or `class` attributes.
51
-
52
-
53
-**NOTE** It is not possible to change the generated file names or the generated
54
-file structure on disk.  The templating/theming support allows changing the resulting
55
-HTML but nothing more.
56
-
57
-
58
-## What Files are generated anyway?
59
-
60
-Before we dive into the templating itself, it is important to know the
61
-directory structure of the generated content, because when writing a
62
-template you need to be aware of how coleslaw lays out the blog on disk.
63
-
64
-The toplevel looks like this:
65
-
66
-
67
-    index.html
68
-    posts/
69
-    tags/
70
-    date/
71
-    static/
72
-    css/
73
-
74
-
75
-### index.html
76
-
77
-This file is the front page of the blog.  It contains a list of the most recent posts and
78
-has links to the different archives.
79
-
80
-### posts directory
81
-
82
-This directory contains an `.html` file per post.  The name of the file
83
-is the `slug` of the post.
84
-
85
-### tags directory
86
-
87
-This directory contains an `.html` file per tag.  Such a file contains
88
-all posts which contain the tag.  The name of a tag file is the `slug` of the tag.
89
-
90
-### date directory
91
-
92
-This directory contains files of the form `yyyy-mm.html` with `yyyy`
93
-the year as a 4 digit number and `mm` as a two digit month number.
94
-These files contain all the posts of the indicated month.
95
-
96
-### static directory
97
-
98
-This directory is a copy of the `static/` directory of the source folder of coleslaw.
99
-
100
-### css directory
101
-
102
-This directory is a copy of the `css/` folder of the theme.
103
-
104
-## Two type of HTML files
105
-
106
-Coleslaw generate two types of HTML files: `index` files and `post` files.
107
-Except for the files in the `posts/` directory all files are `index` files.
108
-
109
-The HTML files, as mentioned before, are created by filling in the [Closure Templates] [clt].
110
-And to generate all the HTML files there are three templates relevant:
111
-
112
-*  `base.tmpl` This template generates the outer shell of the HTML.  This is used
113
-   to generate a consist look and feel and structure for all pages in the blog.
114
-
115
-   The actual content (besides fixed headers and footers etc.) is generated by one of the
116
-   other two templates
117
-
118
-*  `index.tmpl` This template generates the content of the `index` files, remember,
119
-   these are all files containing more than one post, so including the front page.
120
-
121
-
122
-*  `post.tmpl` This generates the HTML files for the individual posts.
123
-   Remember that Coleslaw already converts the content of the individual
124
-   post to HTML by using markdown (or ReST).  So this template is NOT
125
-   used to format or convert an individual post.  This template is used
126
-   to create the HTML containing that post
127
-
128
-Visual it might be clearer this way:
129
-
130
-
131
-     INDEX HTML FILES                    INDIVIDUAL POST HTML FILES
132
-	 
133
-     |-------------------------|         |-------------------------|
134
-	 | base.tmpl               |         | base.tmpl               |
135
-	 |                         |         |                         |
136
-	 |  |-------------------|  |         | |------------------|    |
137
-     |  |  index.tmpl       |  |         | | post.tmpl        |    |
138
-	 |  |                   |  |         | |                  |    |
139
-	 |  |-------------------|  |         | |------------------|    |
140
-	 |                         |         |                         |
141
-	 |-------------------------|         |-------------------------|
142
-
3
+The theming support in coleslaw is very flexible and relatively easy
4
+to use. However it does require some knowledge of HTML, CSS, and how
5
+coleslaw processes content.
6
+
7
+To understand how coleslaw processes a blog, a look at the [overview][ovr]
8
+documentation may prove useful. This document will focus mainly on the
9
+template engine and how you can influence the resulting HTML.
10
+
11
+**NOTE**: Themes are not able to change the generated file names or the
12
+generated file structure on disk. They can change the resulting HTML, nothing more.
13
+
14
+## High-Level Overview
15
+
16
+Themes are written using [Closure Templates][clt]. Those templates are
17
+then compiled into functions that Lisp calls with the blog data to get
18
+HTML. Since the Lisp code to use theme functions is already written,
19
+your theme must follow a few rules.
20
+
21
+Every theme **must** be in a folder under "themes/" named after the
22
+theme. The theme's templates must start with a namespace declaration
23
+like so: `{namespace coleslaw.theme.$MY-THEME-NAME}`.
24
+
25
+A theme must have three templates which take *specific arguments*
26
+(to be described later).
27
+1. Base
28
+2. Post
29
+3. Index
30
+
31
+## Two types of pages
32
+
33
+Coleslaw generates two types of pages: `index` pages and `post` pages.
34
+Every page other than those in the `posts/` directory is an `index`.
35
+**Every** page uses the `base.tmpl` and fills in the content using
36
+either the `post` or `index` templates.
37
+
38
+*  `base.tmpl` This template generates the outer shell of the HTML.
39
+   It keeps a consistent look and feel for all pages in the blog. The
40
+   actual content (i.e., not header/footer/css) comes from other templates.
41
+
42
+*  `index.tmpl` This template generates the content of the `index` pages.
43
+   That is, any page with more than one content object, e.g. the homepage.
44
+
45
+*  `post.tmpl` This templates generates content for the individual posts.
46
+   Coleslaw already converts the content of the individual post to HTML
47
+   by using markdown (or RST). So this template is **not** used to
48
+   convert an individual post, merely to give it a standard layout.
49
+
50
+Here's a visual example to make things clearer:
51
+```
52
+INDEX HTML FILES                    INDIVIDUAL POST HTML FILES
53
+|-------------------------|         |-------------------------|
54
+| base.tmpl               |         | base.tmpl               |
55
+|                         |         |                         |
56
+|  |-------------------|  |         | |------------------|    |
57
+|  |  index.tmpl       |  |         | | post.tmpl        |    |
58
+|  |                   |  |         | |                  |    |
59
+|  |-------------------|  |         | |------------------|    |
60
+|                         |         |                         |
61
+|-------------------------|         |-------------------------|
62
+```
63
+
64
+## Note on Style Sheets (css)
65
+
66
+If you only want to change the way the blog is styled, it is probably
67
+simplest to either modify the existing default theme, `hyde`, or copy
68
+it in entirety and then tweak only the CSS of your new theme. A large
69
+amount of visual difference can be had with a minimum of (or no)
70
+template hacking. There is plenty of advice on CSS styling on the web.
71
+I'm no expert but feel free to send patches to hyde's `style.css` or a
72
+recommended CSS resource for this guide.
143 73
 
144 74
 ## Creating a Theme from Scratch (with code)
145 75
 
146
-### Step 1. Pick a name
147
-
148
-A theme name should satisfy two conditions:
149
-
150
-1.  It is a valid lisp symbol name (not containing `:`)
151
-2.  It is a valid directory name.
152
-
153
-So for this example lets pick `trivial`.
154
-
155
-### Step 2. Create the right directory
156
-
157
-Now we need to create a directory containing the theme files.
158
-In the coleslaw system directory should be a directory called `themes/`.
159
-The directory for the theme files is a sub directory of the `themes/` directory,
160
-named after the theme name we picked in step 1.
76
+### Step 1. Create the directory.
161 77
 
162
-So in our case, we have to create the directory `themes/trivial/`.
78
+A theme name must be a valid lisp symbol. For this example, we'll use
79
+`trivial`, so create a `themes/trivial` directory in the *coleslaw* repo.
163 80
 
164
-### Step 3. Create the 3 template files
81
+### Step 2. Create the templates.
165 82
 
166
-As described above, we need the 3 template files `base.tmpl`, `post.tmpl` and `index.tmpl`.
167
-Before we customize them, create the with the following content:
83
+As described above, we need 3 template files `base.tmpl`, `post.tmpl`
84
+and `index.tmpl`. Initially, let's just create the simplest theme that
85
+compiles correctly.
168 86
 
169 87
 base.tmpl:
170
-	 
171
-       {namespace coleslaw.theme.trivial}
172
-       {template base}
173
-       {/template}
174
-	
175
-
176
-post.tmpl
177
-
178
-       {namespace coleslaw.theme.trivial}
179
-       {template post}
180
-       {/template}
181
-
182
-index.tmpl
183
-
184
-       {namespace coleslaw.theme.trivial}
185
-       {template index}
186
-       {/template}
187
-
188
-
189
-The first line in these files, declares the namespace of the template.  The namespace must be
190
-`coleslaw.theme.` followed by the theme name.
191
-
192
-The remaining two lines `{template ...}{/template ...}` create the empty templates.
193
-
194
-### Step 4. Test
195
-
196
-This is enough to make coleslaw happy.  You can now use the new `trivial` theme in coleslaw
197
-by changing the `:theme` in `.coleslawrc` file to `trivial`.
198
-
199
-If you do this and generate the blog with `(coleslaw:main "")`, coleslaw will not complain
200
-and generate all the post files, tag files and front page files as normal.  Except that all
201
-these files are empty.
202
-
203
-The HTML files are empty because the templates are empty.
204
-
205
-### Step 5. Generating valid HTML
206
-
207
-The `base.tmpl` generates all the HTML pages, so if we change the base template to:
208
-
209
-       {namespace coleslaw.theme.trivial}
210
-       {template base}
211
-          <html>
212
-     	   <head><title>Trivial Theme For Coleslaw</title></head>
213
-     	   <body>
214
-     	   <h1>All my pages have this title</h1>
215
-     	   </body>
216
-    	   </html>
217
-       {/template}
218
-
219
-We will generate valid HTML.  Of course every page is still the same, but at least
220
-it shows that the templating engine works.
221
-
88
+```
89
+{namespace coleslaw.theme.trivial}
90
+{template base}
91
+{/template}
92
+```
93
+post.tmpl:
94
+```
95
+{namespace coleslaw.theme.trivial}
96
+{template post}
97
+{/template}
98
+```
99
+index.tmpl:
100
+```
101
+{namespace coleslaw.theme.trivial}
102
+{template index}
103
+{/template}
104
+```
105
+
106
+This will create three template functions that coleslaw can find, named
107
+`base`, `post`, and `index`.
108
+
109
+### Step 3. Use it in your config.
110
+
111
+At this point, you can change the `:theme` in your `.coleslawrc` to
112
+`trivial` and then generate your blog with `(coleslaw:main)`. However,
113
+all the HTML files will be empty because our templates are empty!
222 114
 
223 115
 ### Intermezzo I, The Templating Language
224 116
 
225
-The templating language is documented at [Google closure templates][clt].
117
+The templating language is documented [elsewhere][clt].
226 118
 However as a short primer:
227 119
 
228
-*   Everyting is outputed literally, except template commands
229
-*   Template commands are enclosed in `{` and `}`
230
-*   Variables, which are provided by coleslaw are referenced
231
-    as `$variable.key` inside a template command.
232
-	So to insert a variable you have to use `{$variable.key}`.
233
-
234
-	Variables are either simple variables, which are referenced as `{$var}`
235
-	Or are indexed by a key and written as `{$var.key}`.
236
-	
237
-*   If statements are written as
238
-
239
-           {if ...} ... {else} ... {/if}
240
-
241
-	Typical examples are:
242
-
243
-           {if $injections.body} ... {/fi}
244
-
245
-    Or
246
-
247
-           {if not isLast($link)} ... {/fi}
248
-
249
-*   Loops are typically written as
250
-
251
-           {foreach $var in $index.posts} ... {/foreach}
252
-
253
-
254
-
120
+*  Everything is output literally, except template commands.
121
+*  Template commands are enclosed in `{` and `}`
122
+*  Variables, which are provided by coleslaw, can be referenced
123
+   inside a template command. So to use a variable you have to say
124
+   `{$variable}` or `{$variable.key}`.
125
+*  If statements are written as `{if ...} ... {else} ... {/if}`.
126
+   Typical examples are: `{if $injections.body} ... {/if}` or
127
+   `{if not isLast($link)} ... {/if}`.
128
+*  Loops can be written as `{foreach $var in $sequence} ... {/foreach}`.
255 129
 
256
-### Intermezzo II, Variables provided by coleslaw
130
+### Intermezzo II, Variables provided by Coleslaw
257 131
 
258 132
 The variable that is available in all templates is:
259
-
260
-- **config** This contains the .coleslawrc content
133
+- **config**       This contains the `.coleslawrc` content.
261 134
 
262 135
 #### Base Template Variables
263 136
 
264
-- **raw**          the HTML generated by the sub templates, `index.tmpl` or `post.tmpl`
265
-- **content**      the data which was used to generate **raw** HTML.
266
-- **pubdate**      A string containing the publication date
267
-- **injections**   A list containg all injections.  Injections are for the plugins to
268
-                   communicate additional content to be included.
269
-
137
+- **raw**          HTML generated by a sub template, `index` or `post`.
138
+- **content**      The object which was used to generate **raw**.
139
+- **pubdate**      A string containing the publication date.
140
+- **injections**   A list containing the injections. Injections are used
141
+                   by plugins mostly to add Javascript to the page.
270 142
 
271 143
 #### Index Template Variables
272 144
 
273
-- **tags**         A list containing all the tags, A tag has values `.name` and `.slug`.
274
-- **months**       A list of all months for which there are posts.  This is a list
275
-                   of strings.  The strings are formatted as `yyyy-mm`.
276
-- **index**        This is the meat of the content.  This variable has as keys
145
+- **tags**         A list containing all the tags, each with keys
146
+                   `.name` and `.slug`.
147
+- **months**       A list of all months with posts as `yyyy-mm` strings.
148
+- **index**        This is the meat of the content. This variable has
149
+                   the following keys
277 150
  - `id`, the name of the page that will be rendered
278
- - `posts` a list of posts (see below)
279
- - `title` The title under which this index is know.  This should be used
280
-	       to display a title for the user.
151
+ - `posts`, a list of posts (see below)
152
+ - `title`, a string title to display to the user
281 153
 - **prev**         If this index file is part of a chain, the `id`
282 154
                    of the previous index html in the chain.
283
-				   If this is the first file, the value will be empty.
155
+                   If this is the first file, the value will be empty.
284 156
 - **next**         If this index file is part of a chain, the `id`
285 157
                    of the next index html in the chain.
286
-				   If this is the last file, the value will be empty.
287
-
158
+                   If this is the last file, the value will be empty.
288 159
 
289 160
 #### Post Template Variable
290 161
 
291
-- **prev**          
292
-- **next**          
293
-- **post**         All these variables are of the same type, they represent a post.
294
-                   The **prev** and **next** are the post before this one, or the one
295
-				   after this one when put in chronological order.
296
-                   These variables have the following keys
297
-   - `tags` a list of tags (a tag has keys `name` and `slug`)
298
-   - `slug` the slug of the post
299
-   - `date` the date of posting
300
-   - `text` the HTML version of the posts body.
301
-   - `title` The title of the post
302
-                   
303
-
304
-### Step 6.  Including the content
305
-
306
-We improve the `base.tmpl` to include the content generated by the sub templates.
307
-This is done by adding the line `{$raw |noAutoescape}` to the template in the body section.
308
-
309
-The `|noAutoescape` is added because the `$raw` variable is already html and we do
310
-not want the templating engine to escape the html.
311
-
312
-So the `base.tmpl` now looks like this:
313
-
314
-       {namespace coleslaw.theme.trivial}
315
-       {template base}
316
-
317
-	   <html>
318
-	   <head><title>Trivial Theme For Coleslaw</title></head>
319
-	   <body>
320
-	   <h1>All my pages have this title</h1>
321
-     	   {$raw |noAutoescape}
322
-	   </body>
323
-	   </html>
324
-
325
-       {/template}
326
-
327
-If we run this through coleslaw we do not see any difference and this is because
328
-we have not modified the `index.tmpl` and the `post.tmpl`.
329
-
330
-A simple `index.tmpl` looks like this
331
-
332
-     {namespace coleslaw.theme.trivial}
333
-     {template index}
334
-		 {foreach $post in $index.posts}
335
-		    <h1>{$post.title}</h1>
336
-		    {$post.text |noAutoescape}
337
-		 {/foreach}
338
-     {/template}
339
-
340
-     
341
-And a simple `post.tmpl` is similarly
342
-
343
-    {namespace coleslaw.theme.trivial}
344
-    {template post}
345
-    <h1>{$post.title}</h1>
346
-    {$post.text |noAutoescape}
347
-    {/template}
348
-
349
-### Wrapup of Example
350
-
351
-Basically all the files are now populated with content.  There are a few huge gaps still, for example there is no
352
-linking between the pages.  So although the archives are fully populated, you cannot get there from the
353
-front page, but if you know the URL it is there.
354
-
355
-However linking is not very difficult see next section.
356
-
162
+- **prev**
163
+- **next**
164
+- **post**         All these variables are post objects. **prev** and
165
+                   **next** are the adjacent posts when put in
166
+                   chronological order. Each post has the following keys:
167
+   - `tags`, a list of tags (each with keys `name` and `slug`)
168
+   - `slug`, the slug of the post
169
+   - `date`, the date of posting
170
+   - `text`, the HTML of the post's body
171
+   - `title`, the title of the post
172
+
173
+### Step 4. Include the content
174
+
175
+*NOTE*: We can keep the template engine from escaping raw HTML by
176
+adding a `|noAutoescape` clause to commands, like so: `{$raw |noAutoescape}`.
177
+
178
+Let's now rewrite `base.tmpl` like this:
179
+```
180
+{namespace coleslaw.theme.trivial}
181
+{template base}
182
+<html>
183
+  <head><title>Trivial Theme For Coleslaw</title></head>
184
+  <body>
185
+    <h1>All my pages have this title</h1>
186
+    {$raw |noAutoescape}
187
+  </body>
188
+</html>
189
+{/template}
190
+```
191
+
192
+A simple `index.tmpl` looks like this:
193
+```
194
+{namespace coleslaw.theme.trivial}
195
+{template index}
196
+{foreach $post in $index.posts}
197
+<h1>{$post.title}</h1>
198
+  {$post.text |noAutoescape}
199
+{/foreach}
200
+{/template}
201
+```
202
+
203
+And a simple `post.tmpl` is similarly:
204
+```
205
+{namespace coleslaw.theme.trivial}
206
+{template post}
207
+<h1>{$post.title}</h1>
208
+  {$post.text |noAutoescape}
209
+{/template}
210
+```
211
+
212
+### Conclusion
213
+
214
+All of the files are now populated with content. There are still no links
215
+between the pages so navigation is cumbersome but adding links is simple.
216
+Good luck!
357 217
 
358 218
 ## Note on adding links
359 219
 
360
-As mentioned in the beginning, most files have a file name which is a slug of some sort. So if you want to create a link
361
-to a tag file you should do something like this:
362
-
363
-      <a href="${config.domain}/tags/$tag.slug">$tag.name</a>
364
-
365
-
366
-## Note on adding style sheets
367
-
368
-Style sheets are nothing special.  In order to get them to work, you
369
-have to add a `css` folder in your theme folder.  The content of this folder
370
-will be copied to the `css` folder at the place where the `html` is generated.
371
-
372
-Now to actual use them, you have to include in the head section of the html
373
-(which is in the `base.tmpl`) a link to include the CSS.
374
-
375
-
220
+As mentioned earlier, most files have a file name which is a slug of
221
+some sort. So if you want to create a link to a tag file you should
222
+do something like this: `<a href="${config.domain}/tags/$tag.slug">$tag.name</a>`.
376 223
 
377 224
 [clt]: https://developers.google.com/closure/templates/
225
+[ovr]: https://github.com/redline6561/coleslaw/blob/master/docs/overview.md