enable slickmap

This commit is contained in:
tdreyno 2009-10-06 16:29:51 -07:00
parent d40111d67e
commit 332a0be737
3 changed files with 109 additions and 12 deletions

View file

@ -48,6 +48,10 @@ module Generators
glob! File.basename(Middleman::Base.public), Middleman::Base.supported_formats glob! File.basename(Middleman::Base.public), Middleman::Base.supported_formats
glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats
if Middleman::Base.slickmap?
template :slickmap, "sitemap.html", "sitemap.html"
end
end end
add :build, Builder add :build, Builder
@ -72,7 +76,7 @@ class Templater::Actions::Template
def identical? def identical?
if ::File.exists?(destination) if ::File.exists?(destination)
return true if File.mtime(source) < File.mtime(destination) return true if File.exists?(source) && File.mtime(source) < File.mtime(destination)
::File.read(destination) == render ::File.read(destination) == render
else else
false false

View file

@ -25,9 +25,9 @@ module Generators
glob! :views glob! :views
glob! :public glob! :public
empty_directory :stylesheets, File.join("public", css_dir) empty_directory :stylesheets, "public/stylesheets"#, File.join("public", css_dir)
empty_directory :javascripts, File.join("public", js_dir) empty_directory :javascripts, "public/javascripts"#, File.join("public", js_dir)
empty_directory :images, File.join("public", images_dir) empty_directory :images, "public/images"#, File.join("public", images_dir)
end end
add :setup, NewSite add :setup, NewSite

View file

@ -1,16 +1,83 @@
begin
require 'slickmap' require 'slickmap'
::Compass.configure_sass_plugin!
rescue LoadError
puts "Slickmap not available. Install it with: gem install compass-slickmap"
end
Entry = Struct.new(:dir, :children)
class Middleman::Base class Middleman::Base
def build_sitemap(&block) def build_sitemap(&block)
# views - stylesheets html_files = Dir[File.join(File.dirname(Middleman::Base.views), "**", "*.html*")]
# public
# .select @@utility = []
# block.call(this) [recurse_sitemap(Middleman::Base.views, &block), @@utility]
end
def recurse_sitemap(path, &block)
bad_ext = path.split('.html')[1]
path = path.gsub(bad_ext, '') if bad_ext
entry = Entry.new(path, [])
#no "." or ".." dirs
Dir[File.join(path, "*")].each do |e|
next if !File.directory?(e) && !e.include?(".html")
if File.directory?(e)
entry.children << recurse_sitemap(e, &block)
elsif block_given?
how_to_handle = block.call(e)
if how_to_handle == :valid
entry.children << recurse_sitemap(e, &block)
elsif how_to_handle == :utility
bad_ext = e.split('.html')[1]
e = e.gsub(bad_ext, '') if bad_ext
@@utility << e.gsub(Middleman::Base.views + "/", '')
end
end
end
entry
end
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
# we are a dir
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 end
get '/sitemap.html' do get '/sitemap.html' do
@tree = build_sitemap do |file_name| # Return :utility to put it util top menu. False to ignore
true @tree, @utility = build_sitemap do |file_name|
:valid
end end
haml :sitemap, :layout => false haml :sitemap, :layout => false
end end
@ -21,4 +88,30 @@ end
__END__ __END__
@@ sitemap @@ sitemap
%div.title Hello world!!!!! !!!
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
%head
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-type" }
%title Sitemap
%style{ :type => "text/css" }
:sass
@import slickmap.sass
+slickmap
:javascript
window.onload = function() {
document.getElementById('primaryNav').className = "col" + document.querySelectorAll("#primaryNav > li:not(#home)").length;
};
%body
.logo
%h1= @project_name || "Sitemap"
- if @project_subtitle
%h2= @project_subtitle
- if @utility.length > 0
%ul#utilityNav
- @utility.each do |u|
%li= link_to u, u
%ul#primaryNav
- sitemap_node(@tree, true)