Class: Nanoc2::Routers::NoDirs

Inherits:
Nanoc2::Router show all
Defined in:
lib/nanoc2/routers/no_dirs.rb

Overview

The no-directories router organises pages very similarly to the default router, but does not create directories unless necessary. This router will therefore generate pages with less pretty URLs.

For example, a page with path /about/ will be written to /about.html instead of /about/index.html.

Constant Summary

Constants inherited from Plugin

Plugin::MAP

Instance Method Summary collapse

Methods inherited from Nanoc2::Router

#disk_path_for, #initialize, #web_path_for

Methods inherited from Plugin

identifier, identifiers, named, register

Constructor Details

This class inherits a constructor from Nanoc2::Router

Instance Method Details

#path_for_asset_rep(asset_rep) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nanoc2/routers/no_dirs.rb', line 37

def path_for_asset_rep(asset_rep)
  # Get data we need
  extension     = asset_rep.attribute_named(:extension)
  modified_path = asset_rep.asset.path[0..-2]
  version       = asset_rep.attribute_named(:version)

  # Initialize path
  assets_prefix = @site.config[:assets_prefix] || '/assets'
  path = assets_prefix + modified_path

  # Add version if necessary
  unless version.nil?
    path += '-v' + version.to_s
  end

  # Add rep name
  unless asset_rep.name == :default
    path += '-' + asset_rep.name.to_s
  end

  # Add extension
  path += '.' + extension

  # Done
  path
end

#path_for_page_rep(page_rep) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nanoc2/routers/no_dirs.rb', line 13

def path_for_page_rep(page_rep)
  # Get data we need
  filename   = page_rep.attribute_named(:filename)
  extension  = page_rep.attribute_named(:extension)

  # Initialize path
  if page_rep.page.path == '/'
    path = '/' + filename
  else
    path = page_rep.page.path[0..-2]
  end

  # Add rep name if necessary
  unless page_rep.name == :default
    path += '-' + page_rep.name.to_s
  end

  # Add extension
  path += '.' + extension

  # Done
  path
end