5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/middleman/features/slickmap.rb', line 5
def registered(app)
require 'slickmap'
@sitemap_url = config[:url] || "sitemap.html"
if Middleman::Server.environment == :build
Middleman::Builder.template :slickmap, @sitemap_url, @sitemap_url
end
Middleman::Server.helpers do
def sitemap_node(n, first=false)
if n.children.length < 1
if !first && File.extname(n.dir).length > 0
haml_tag :li do
path = n.dir.gsub(self.class.views, '')
haml_concat link_to(File.basename(path), path)
end
end
else
haml_tag(:li, :id => first ? "home" : nil) do
if first
haml_concat link_to("Homepage", "/" + self.class.index_file)
else
index = n.children.find { |c| c.dir.include?(self.class.index_file) }
haml_concat link_to(index.dir.gsub(self.class.views + "/", '').gsub("/" + File.basename(index.dir), '').capitalize, index.dir.gsub(self.class.views, ''))
end
other_children = n.children.select { |c| !c.dir.include?(self.class.index_file) }
if other_children.length > 0
if first
other_children.each { |i| sitemap_node(i) }
else
haml_tag :ul do
other_children.each { |i| sitemap_node(i) }
end
end
end
end
end
end
end
Middleman::Server.get "/#{@sitemap_url}" do
@tree, @utility = Middleman::Features::Slickmap.build_sitemap do |file_name|
:valid
end
haml "template.html".to_sym, :layout => false, :views => File.expand_path(File.join(File.dirname(__FILE__), "slickmap"))
end
end
|