d-mark 1.0.0a1 → 1.0.0b2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,539 +0,0 @@
1
- p. In Nanoc, every item (page or asset) and every layout has a unique %firstterm{identifier}: a string derived from the file’s path. A %firstterm{pattern} is an expression that is used to select items or layouts based on their identifier.
2
-
3
- h2. Identifiers
4
-
5
- p. Identifiers come in two types: the %emph{full} type, new in Nanoc 4, and the %emph{legacy} type, used in Nanoc 3.
6
-
7
- dl.
8
- dt. full
9
- dd. An identifier with the full type is the filename, with the path to the content directory removed. For example, the file %filename{/Users/denis/stoneship/content/about.md} will have the full identifier %identifier{/about.md}.
10
-
11
- dt. legacy
12
- dd. An identifier with the legacy type is the filename, with the path to the content directory removed, the extension removed, and a slash appended. For example, the file %filename{/Users/denis/stoneship/content/about.md} will have the legacy identifier %identifier{/about/}. This corresponds closely with paths in clean URLs.
13
-
14
- p. The following methods are useful for full identifiers:
15
-
16
- dl.
17
- dt. %code{identifier.without_ext} → %class{String}
18
- dd. identifier with the last extension removed
19
-
20
- dt. %code{identifier.without_exts} → %class{String}
21
- dd. identifier with all extensions removed
22
-
23
- dt. %code{identifier.ext} → %class{String}
24
- dd. the last extension of this identifier
25
-
26
- dt. %code{identifier.exts} → %class{String}
27
- dd. all extensions of this identifier
28
-
29
- dt. %code{identifier + string} → %class{String}
30
- dd. identifier with the given string appended
31
-
32
- p. Here are some examples:
33
-
34
- listing[lang=ruby].
35
- identifier = Nanoc::Identifier.new('/about.md')
36
-
37
- identifier.without_ext
38
- # => "/about"
39
-
40
- identifier.ext
41
- # => "md"
42
-
43
- p. The following method is useful for legacy identifiers:
44
-
45
- dl[legacy].
46
- dt. %code{identifier.chop} → %class{String}
47
- dd. identifier with the last character removed
48
-
49
- p. Here are some examples:
50
-
51
- listing[lang=ruby].
52
- identifier = Nanoc::Identifier.new('/about/', type: :legacy)
53
-
54
- identifier.chop
55
- # => "/about"
56
-
57
- identifier.chop + '.html'
58
- # => "/about.html"
59
-
60
- identifier + 'index.html'
61
- # => "/about/index.html"
62
-
63
- h2. Patterns
64
-
65
- p. Patterns are used to find items and layouts based on their identifier. They come in three varieties:
66
-
67
- ul.
68
- li. glob patterns
69
- li. regular expression patterns
70
- li. legacy patterns
71
-
72
- h3. Glob patterns
73
-
74
- p. Glob patterns are strings that contain wildcard characters. Wildcard characters are characters that can be substituted for other characters in a identifier. An example of a glob pattern is %glob{/projects/*.md}, which matches all files with a %filename{md} extension in the %filename{/projects} directory.
75
-
76
- p. Globs are commonplace in Unix-like environments. For example, the Unix command for listing all files with the %filename{md} extension in the current directory is %command{ls *.md}. In this example, the argument to the %command{ls} command is a wildcard.
77
-
78
- p. Nanoc supports the following wildcards in glob patterns:
79
-
80
- dl.
81
- dt. %code{*}
82
- dd. Matches any file or directory name. Does not cross directory boundaries. For example, %glob{/projects/*.md} matches %identifier{/projects/nanoc.md}, but not %identifier{/projects/cri.adoc} nor %identifier{/projects/nanoc/about.md}.
83
-
84
- dt. %code{**/}
85
- dd. Matches zero or more levels of nested directories. For example, %glob{/projects/**/*.md} matches both %identifier{/projects/nanoc.md} and %identifier{/projects/nanoc/history.md}.
86
-
87
- dt. %code{?}
88
- dd. Matches a single character.
89
-
90
- dt. %code{[abc]}
91
- dd. Matches any single character in the set. For example, %glob{/people/[kt]im.md} matches only %identifier{/people/kim.md} and %identifier{/people/tim.md}.
92
-
93
- dt. %code{{foo,bar%}}
94
- dd. Matches either string in the comma-separated list. More than two strings are possible. For example, %glob{/c{at,ub,ount%}s.txt} matches %identifier{/cats.txt}, %identifier{/cubs.txt} and %identifier{/counts.txt}, but not %identifier{/cabs.txt}.
95
-
96
- p. A glob pattern that matches every item is %glob{/**/*}. A glob pattern that matches every item/layout with the extension %filename{md} is %glob{/**/*.md}.
97
-
98
- h3. Regular expression patterns
99
-
100
- p. You can use a regular expression to select items and layouts.
101
-
102
- p. For matching identifiers, the %code{%%r{…%}} syntax is (arguably) nicer than the %code{/…/} syntax. The latter is not a good fit for identifiers (or filenames), because all slashes need to be escaped. The %code{\A} and %code{\z} anchors are also useful to make sure the entire identifier is matched.
103
-
104
- p. An example of a regular expression pattern is %code{%%r{\A/projects/(cri|nanoc)\.md\z%}}, which matches both %identifier{/projects/nanoc.md} and %identifier{/projects/cri.md}.
105
-
106
- h3. Legacy patterns
107
-
108
- p. Legacy patterns are strings that contain wildcard characters. The wildcard characters behave differently than the glob wildcard characters.
109
-
110
- p. To enable legacy patterns, set %code{string_pattern_type} to %code{"legacy"} in the configuration. For example:
111
-
112
- listing[lang=yaml].
113
- string_pattern_type: "legacy"
114
-
115
- p. For legacy patterns, Nanoc supports the following wildcards:
116
-
117
- dl.
118
- dt. %code{*}
119
- dd. Matches zero or more characters, including a slash. For example, %glob{/projects/*/} matches %glob{/projects/nanoc/} and %identifier{/projects/nanoc/about/}, but not %identifier{/projects/}.
120
-
121
- dt. %code{+}
122
- dd. Matches one or more characters, including a slash. For example, %glob{/projects/+} matches %identifier{/projects/nanoc/} and %identifier{/projects/nanoc/about/}, but not %identifier{/projects/}.
123
-
124
- p. Install Nanoc using RubyGems:
125
-
126
- listing.
127
- %prompt{%%} %kbd{gem install nanoc}
128
-
129
- note. %entity{sudo-gem-install}
130
-
131
- p. After installing, head over to %ref[item=/doc/tutorial.*]{}! For detailed installation instructions, read on.
132
-
133
- h2. Installing Ruby
134
-
135
- p. Nanoc requires %ref[url=http://ruby-lang.org/]{Ruby} in order to run. Nanoc supports the official Ruby interpreter from version 2.1 up, as well as JRuby from version 9000 up.
136
-
137
- p. Ruby may already be installed on your system. To check, open a terminal window and type %kbd{ruby --version}. If you get “command not found”, Ruby is not yet installed. Otherwise, you will see which version of Ruby you have:
138
-
139
- listing.
140
- %prompt{%%} %kbd{ruby --version}
141
- %erb{config[:ruby_version_info]}
142
- %prompt{%%}
143
-
144
- p. To install Ruby, follow the %ref[url=https://www.ruby-lang.org/en/documentation/installation/]{installation instructions on the Ruby web site}.
145
-
146
- h2. Installing Nanoc
147
-
148
- p. All dependencies are now taken care of, and installing Nanoc should now be easy:
149
-
150
- listing.
151
- %prompt{%%} %kbd{gem install nanoc}
152
-
153
- note. %entity{sudo-gem-install}
154
-
155
- p. To make sure that Nanoc was installed correctly, run %kbd{nanoc --version}. It should print the version number along with some other information, like this:
156
-
157
- listing.
158
- %prompt{%%} %kbd{nanoc --version}
159
- %erb{config[:nanoc_version_info]}
160
- %prompt{%%}
161
-
162
- p. If you get a “command not found” error when trying to run %command{nanoc}, you might have to adjust your %code{$PATH} to include the path to the directory where RubyGems installs executables.
163
-
164
- p. The current version of Nanoc is is %erb{latest_release_info[:version]}, released on %erb{latest_release_info[:date].format_as_date}. You can find the release notes for this version as well as release notes for older versions on %ref[item=/release-notes]{}.
165
-
166
- p. If you’re on Windows and are using the Windows console, it’s probably a good idea to install the %productname{win32console} gem using %kbd{gem install win32console} to allow Nanoc to use pretty colors when writing stuff to the terminal.
167
-
168
- h3. Installing from git
169
-
170
- p. You can also install Nanoc from the repository if you want to take advantage of the latest features and improvements in Nanoc. Be warned that the versions from the repository may be unstable, so it is recommended to install Nanoc from RubyGems if you want to stay safe. You can install Nanoc from the git repository like this:
171
-
172
- listing.
173
- %prompt{~%%} %kbd{git clone git://github.com/nanoc/nanoc.git}
174
- %prompt{~%%} %kbd{cd nanoc}
175
- %prompt{~/nanoc%%} %kbd{gem build nanoc.gemspec}
176
- %prompt{~/nanoc%%} %kbd{gem install nanoc-*.gem}
177
-
178
- p. Nanoc 4 takes a clean break from the past, removing anything that was holding back future development.
179
-
180
- p. The good news is that Nanoc 4.0 is quite similar to 3.8. Upgrading a Nanoc 3.x site to Nanoc 4.0 only takes minutes.
181
-
182
- h2. Why upgrade?
183
-
184
- ul[spacious].
185
- li. Nanoc 4 brings identifiers with extensions, and thereby solves a long-standing usability issue. It also introduces glob patterns, which makes rules easier to write.
186
-
187
- li. Nanoc 4 paves the way for new features and performance improvements. Nanoc 3 exposed its internals in a public API, making it hard to make significant changes.
188
-
189
- li. Nanoc 3 is in maintenance mode, which means it will only get critical bug fixes.
190
-
191
- h2. Installing Nanoc 4
192
-
193
- p. Before installing, ensure you have a supported version of Ruby. Nanoc supports Ruby 2.2 and up, and JRuby 9000 and up:
194
-
195
- listing.
196
- %prompt{%%} %kbd{ruby --version}
197
- %erb{config[:ruby_version_info]}
198
- %prompt{%%}
199
-
200
- p. To upgrade Ruby, follow the %ref[url=https://www.ruby-lang.org/en/documentation/installation/]{installation instructions on the Ruby web site}.
201
-
202
- p. You can install Nanoc 4 using RubyGems:
203
-
204
- listing.
205
- %prompt{%%} %kbd{gem install nanoc}
206
-
207
- note. %entity{sudo-gem-install}
208
-
209
- p. We recommend using %ref[url=http://bundler.io/]{Bundler} to manage dependencies. When using Bundler, ensure there is a line for Nanoc in the %filename{Gemfile} that looks like this:
210
-
211
- listing[lang=ruby].
212
- gem 'nanoc', '~> 4.0'
213
-
214
- h2[id=quick-upgrade-guide]. Quick upgrade guide
215
-
216
- p. The following steps will get a Nanoc 3 site working on Nanoc 4 with a minimal amount of changes.
217
-
218
- ol[spacious].
219
- li. Change mentions of %code{Nanoc3} to %code{Nanoc}.
220
-
221
- li. Change mentions of %code{@site.config} to %code{@config}.
222
-
223
- li. Add %code{identifier_type: legacy} to the individual data source configurations. For example:
224
-
225
- listing[lang=yaml,legacy].
226
- data_sources:
227
- -
228
- type: filesystem
229
-
230
- listing[lang=yaml,new].
231
- data_sources:
232
- -
233
- type: filesystem
234
- identifier_type: legacy
235
-
236
- li. Add %code{string_pattern_type: legacy} to the configuration file. For example:
237
-
238
- listing[lang=yaml,legacy].
239
- data_sources:
240
- -
241
- type: filesystem
242
- identifier_type: legacy
243
-
244
- listing[lang=yaml,new].
245
- string_pattern_type: legacy
246
- data_sources:
247
- -
248
- type: filesystem
249
- identifier_type: legacy
250
-
251
- li. In Rules, remove the %code{rep.} prefix from %code{filter}, %code{layout} and %code{snapshot}. For example:
252
-
253
- listing[lang=ruby,legacy].
254
- compile '*' do
255
- rep.filter :erb
256
- rep.layout 'default'
257
- end
258
-
259
- listing[lang=ruby,new].
260
- compile '*' do
261
- filter :erb
262
- layout 'default'
263
- end
264
-
265
- li. In the %code{preprocess} block, use %code{@items.create} rather than instantiating %code{Nanoc::Item}. For example:
266
-
267
- listing[lang=ruby,legacy].
268
- @items << Nanoc::Item.new('Hello', {%}, '/hello/')
269
-
270
- listing[lang=ruby,new].
271
- @items.create('Hello', {%}, '/hello/')
272
-
273
- li. In data sources, use %code{#new_item} or %code{#new_layout} rather than instantiating %code{Nanoc::Item} or %code{Nanoc::Layout}. For example:
274
-
275
- listing[lang=ruby,legacy].
276
- def items
277
- [Nanoc::Item.new('Hello', {%}, '/hello/')]
278
- end
279
-
280
- listing[lang=ruby,new].
281
- def items
282
- [new_item('Hello', {%}, '/hello/')]
283
- end
284
-
285
- li. Replace %code{.reps[0]} by %code{.reps[:default]}. For example:
286
-
287
- listing[lang=ruby,legacy].
288
- item.reps[0].path
289
-
290
- listing[lang=ruby,new].
291
- item.reps[:default].path
292
-
293
- li. Replace calls to %code{#rep_named} by %code{reps[%var{something}]}, where %var{something} is the argument to %code{#rep_named}. For example:
294
-
295
- listing[lang=ruby,legacy].
296
- item.rep_named(:raw).path
297
-
298
- listing[lang=ruby,new].
299
- item.reps[:raw].path
300
-
301
- li. If you use the static data source, disable it for now and follow the extended upgrade instructions below.
302
-
303
- h2. Extended upgrade guide
304
-
305
- p. This section describes how to upgrade a site to identifiers with extensions and glob patterns. For details, see %ref[item=/doc/identifiers-and-patterns.*]{}.
306
-
307
- p. This section assumes you have already upgraded the site following the instructions in %ref[frag=quick-upgrade-guide]{} above.
308
-
309
- p. Before you start, add %code{enable_output_diff: true} to the configuration file. This will let the %command{compile} command write out a diff with the changes to the compiled output. This diff will allow you to verify that no unexpected changes occur.
310
-
311
- tip. If you use a filter that minifies HTML content, such as %code{html5small}, we recommend turning it off before upgrading the site, so that the output diff becomes easier to read.
312
-
313
- h3. Enabling glob patterns
314
-
315
- p. Before enabling them, ensure you are familiar with glob patterns. For details, see %ref[item=/doc/identifiers-and-patterns.*,frag=glob-patterns]{}.
316
-
317
- p. To use glob patterns:
318
-
319
- ol[spacious].
320
- li. Set %code{string_pattern_type} to %code{glob} in the configuration file. For example:
321
-
322
- listing[lang=yaml,legacy].
323
- string_pattern_type: legacy
324
-
325
- listing[lang=yaml,new].
326
- string_pattern_type: glob
327
-
328
- li. Ensure that all string patterns in the %filename{Rules} file, as well as in calls to %code{@items[…]}, %code{@layouts[…]}, and %code{#render} throughout the site, start and end with a slash. This is an intermediate step. For example:
329
-
330
- listing[lang=ruby,legacy].
331
- # Before
332
- compile 'articles/*' do
333
- layout 'default'
334
- end
335
-
336
- listing[lang=ruby,legacy].
337
- # After
338
- compile '/articles/*/' do
339
- layout '/default/'
340
- end
341
-
342
- listing[lang=ruby,legacy].
343
- # Before
344
- @items['foo']
345
- @layouts['/bar']
346
-
347
- listing[lang=ruby,legacy].
348
- # After
349
- @items['/foo/']
350
- @layouts['/bar/']
351
-
352
- listing[lang=rhtml,legacy].
353
- <!-- Before -->
354
- <%%= render 'header' %%>
355
-
356
- listing[lang=rhtml,legacy].
357
- <!-- After -->
358
- <%%= render '/header/' %%>
359
-
360
- li. Replace %code{*} and %code{+} with %code{**/*} in all string patterns in the %filename{Rules} file, as well as in calls to %code{@items[…]}, %code{@layouts[…]}, and %code{#render} throughout the site. For example:
361
-
362
- listing[lang=ruby,legacy].
363
- compile '/articles/*/' do
364
- layout '/default/'
365
- end
366
-
367
- listing[lang=ruby,new].
368
- compile '/articles/**/*/' do
369
- layout '/default/'
370
- end
371
-
372
- listing[lang=ruby,legacy].
373
- @items['/articles/*/']
374
-
375
- listing[lang=ruby,new].
376
- @items['/articles/**/*/']
377
-
378
- p. This approach should work out of the box: Nanoc should not raise errors and the output diff should be empty.
379
-
380
- h3. Enabling identifiers with extensions
381
-
382
- note. This section assumes that glob patterns have been enabled.
383
-
384
- p. Before enabling them, ensure you are familiar with identifiers with extensions. See %ref[item=/doc/identifiers-and-patterns.*,frag=identifiers]{} section for documentation.
385
-
386
- p. To use identifiers with extensions:
387
-
388
- ol[spacious].
389
- li. Set %code{identifier_type} to %code{full} in the configuration file. For example:
390
-
391
- listing[lang=yaml,legacy].
392
- identifier_type: legacy
393
-
394
- listing[lang=yaml,new].
395
- identifier_type: full
396
-
397
- li. Remove the trailing slash from any argument to %code{#compile}, %code{#route} and %code{#layout} in the %filename{Rules} file, as well as in calls to %code{@items[…]}, %code{@layouts[…]}, and %code{#render} throughout the site. If the pattern does not end with a “%code{*}”, add “%code{.*}”. For example:
398
-
399
- listing[lang=ruby,legacy].
400
- compile '/articles/**/*/' do
401
- filter :kramdown
402
- layout '/default/'
403
- end
404
-
405
- compile '/about/' do
406
- layout '/default/'
407
- end
408
-
409
- listing[lang=ruby,new].
410
- compile '/articles/**/*' do
411
- filter :kramdown
412
- layout '/default.*'
413
- end
414
-
415
- compile '/about.*' do
416
- layout '/default.*'
417
- end
418
-
419
- listing[lang=ruby,legacy].
420
- @items['/about/']
421
- @layouts['/default/']
422
-
423
- listing[lang=ruby,new].
424
- @items['/about.*']
425
- @layouts['/default.*']
426
-
427
- listing[lang=rhtml,legacy].
428
- <%%= render '/root/' %%>
429
-
430
- listing[lang=rhtml,new].
431
- <%%= render '/root.*' %%>
432
-
433
- li. Update the routing rules to output the correct path. For example:
434
-
435
- listing[lang=ruby,legacy].
436
- route '/articles/*/' do
437
- # /articles/foo/ gets written to /articles/foo/index.html
438
- item.identifier + 'index.html'
439
- end
440
-
441
- listing[lang=ruby,new].
442
- route '/articles/**/*' do
443
- # /articles/foo.md gets written to /articles/foo/index.html
444
- item.identifier.without_ext + '/index.html'
445
- end
446
-
447
- li. Create a routing rule that matches index files in the content directory (such as %filename{content/index.md} or %filename{content/blog/index.md}). For example, put the following _before_ any rules matching %code{/**/*}:
448
-
449
- listing[lang=ruby,new].
450
- route '/**/index.*' do
451
- # /projects/index.md gets written to /projects/index.html
452
- item.identifier.without_ext + '.html'
453
- end
454
-
455
- li. Replace calls to %code{#children} with a call to %code{#find_all}, passing a pattern that matches the children. For example:
456
-
457
- listing[lang=ruby,legacy].
458
- @items['/articles/'].children
459
- @item.children
460
-
461
- listing[lang=ruby,new].
462
- @items.find_all('/articles/*')
463
- @items.find_all(@item.identifier.without_ext + '/*')
464
-
465
- li. Replace calls to %code{#parent} with a call to %code{#[]}, passing a pattern that matches the parent. For example:
466
-
467
- listing[lang=ruby,legacy].
468
- @item.parent
469
-
470
- listing[lang=ruby,new].
471
- @items[@item.identifier.to_s.sub(/[^\/]+$/, '').chop + '.*']
472
-
473
- note. When using identifiers with extensions, the children and parent of an item are no longer unambiguous. For example, the two items %filename{/foo.md} and %filename{/foo.adoc} both have %filename{/foo/bar.md} as a child, and %filename{/foo/bar.md} has two parents.
474
-
475
- h3. Upgrading from the static data source
476
-
477
- note. This section assumes that glob patterns and identifiers with extensions have been enabled.
478
-
479
- p. The static data source no longer exists in Nanoc 4. It existed in Nanoc 3 to work around the problem of identifiers not including the file extension, which is no longer the case in Nanoc 4.
480
-
481
- p. Theoretically, with identifiers with extensions enabled, it is possible to move the contents of the %filename{static/} directory into %filename{content/}. This can be tricky, however, because some rules that did not match any items in %filename{static/} might now match.
482
-
483
- p. Because of this, the recommend approach for upgrading is to keep the %filename{static/} directory, and set up a new data source that reads from this directory.
484
-
485
- p. In the site configuration, re-enable the static data source, change its type to %code{filesystem}, set %code{content_dir} to %code{"static"} and %code{layouts_dir} to %code{null}:
486
-
487
- listing[lang=yaml,new].
488
- data_sources:
489
- -
490
- type: filesystem
491
- -
492
- type: filesystem
493
- items_root: /static
494
- content_dir: 'static'
495
- layouts_dir: null
496
-
497
- p. The null value for the %code{layouts_dir} option prevents this data source from loading layouts—the other data source already does so.
498
-
499
- p. Lastly, update the rules to copy these items as-is, but without the %code{/static} prefix:
500
-
501
- listing[lang=ruby,new].
502
- compile '/static/**/*' do
503
- end
504
-
505
- route '/static/**/*' do
506
- # /static/foo.html → /foo.html
507
- item.identifier.to_s.sub(/\A\/static/, '')
508
- end
509
-
510
- p. This approach should work out of the box: Nanoc should not raise errors and the output diff should be empty.
511
-
512
- p. A final improvement would be to move the contents of the %filename{static/} directory into %filename{content/}. The main thing to watch out for with this approach is rules that accidentally match the wrong items.
513
-
514
- h2. Troubleshooting
515
-
516
- ol[spacious].
517
- li. If you use Nanoc with a Gemfile, ensure you call Nanoc as %kbd{bundle exec nanoc}. Nanoc no longer attempts to load the Gemfile.
518
-
519
- li. If you get a %code{NoMethodError} error on %code{Nanoc::Identifier}, call %code{.to_s} on the identifier before doing anything with it. In Nanoc 4.x, identifiers have their own class and are no longer strings.
520
-
521
- listing[lang=ruby,legacy].
522
- item.identifier[7..-2]
523
-
524
- listing[lang=ruby,new].
525
- item.identifier.to_s[7..-2]
526
-
527
- li. If you get a %code{NoMethodError} that you did not expect, you might be using a private API that is no longer present in Nanoc 4.0. In case of doubt, ask for help on the %ref[url=http://nanoc.ws/community/#discussion-groups]{discussion group}.
528
-
529
- h2. Removed features
530
-
531
- p. The %code{watch} and %code{autocompile} commands have been removed. Both were deprecated in Nanoc 3.6. Use %ref[url=https://github.com/guard/guard-nanoc]{%productname{guard-nanoc}} instead.
532
-
533
- p. Because Nanoc’s focus is now more clearly on compiling content rather than managing it, the following features have been removed:
534
-
535
- ol.
536
- li. the %code{create-item} and %code{create-layout} commands
537
- li. the %code{update} and %code{sync} commands
538
- li. VCS integration (along with %code{Nanoc::Extra::VCS})
539
- li. the %code{DataSource#create_item} and %code{DataSource#create_layout} methods.