d-mark 0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,14 +2,16 @@ module DMark
2
2
  class Translator
3
3
  attr_reader :out
4
4
 
5
- def initialize(tree)
6
- @tree = tree
5
+ def initialize(nodes)
6
+ @nodes = nodes
7
7
 
8
8
  @out = ''
9
9
  end
10
10
 
11
11
  def run
12
- handle(@tree)
12
+ @nodes.each do |node|
13
+ handle(node)
14
+ end
13
15
  @out
14
16
  end
15
17
 
@@ -0,0 +1,3 @@
1
+ module DMark
2
+ VERSION = '0.2.0'.freeze
3
+ end
@@ -35,7 +35,7 @@ listing[lang=ruby].
35
35
  identifier = Nanoc::Identifier.new('/about.md')
36
36
 
37
37
  identifier.without_ext
38
- # => "/about"
38
+ # => "/about"
39
39
 
40
40
  identifier.ext
41
41
  # => "md"
@@ -120,3 +120,420 @@ dl.
120
120
 
121
121
  dt. %code{+}
122
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.