2010-01-21 06:25:44 +00:00
|
|
|
# All files in the 'lib' directory will be loaded
|
|
|
|
# before nanoc starts compiling.
|
|
|
|
|
2010-01-21 19:54:47 +00:00
|
|
|
include Nanoc3::Helpers::LinkTo
|
2010-01-23 09:09:59 +00:00
|
|
|
include Nanoc3::Helpers::Capturing
|
|
|
|
include Nanoc3::Helpers::Rendering
|
2010-01-25 00:06:34 +00:00
|
|
|
include Nanoc3::Helpers::Breadcrumbs
|
2010-01-21 19:54:47 +00:00
|
|
|
|
|
|
|
def body_class(item)
|
|
|
|
(item[:classnames] || []).join(" ")
|
|
|
|
end
|
|
|
|
|
|
|
|
def body_id(item)
|
2010-01-31 18:01:04 +00:00
|
|
|
if item[:body_id]
|
|
|
|
item[:body_id]
|
|
|
|
elsif id = item.identifier.chop[1..-1]
|
2010-01-22 19:41:08 +00:00
|
|
|
id.gsub(/\/|_/, "-")
|
|
|
|
end
|
2010-01-21 19:54:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def body_attributes(item)
|
|
|
|
{
|
|
|
|
:id => body_id(item),
|
|
|
|
:class => body_class(item)
|
|
|
|
}
|
2010-01-24 03:48:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Recycler
|
|
|
|
attr_accessor :values
|
|
|
|
attr_accessor :index
|
|
|
|
def initialize *values
|
|
|
|
self.values = values
|
|
|
|
self.index = 0
|
|
|
|
end
|
|
|
|
def next
|
|
|
|
values[index]
|
|
|
|
ensure
|
|
|
|
self.index += 1
|
|
|
|
self.index = 0 if self.index >= self.values.size
|
|
|
|
end
|
|
|
|
def reset!
|
|
|
|
self.index = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cycle(*args)
|
|
|
|
yield Recycler.new *args
|
|
|
|
end
|
2010-02-03 16:02:27 +00:00
|
|
|
|
|
|
|
def default_path(item)
|
|
|
|
item.reps.find{|r| r.name == :default}.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def item_tree(item)
|
|
|
|
crumb = item[:crumb] || item[:title]
|
|
|
|
child_html = ""
|
|
|
|
if item.children.any?
|
|
|
|
child_html << "<ol>"
|
|
|
|
item.children.each do |child|
|
|
|
|
child_html << item_tree(child)
|
|
|
|
end
|
|
|
|
child_html << "</ol>"
|
|
|
|
end
|
2010-03-28 06:46:06 +00:00
|
|
|
css_class = nil
|
|
|
|
prefix = nil
|
|
|
|
suffix = nil
|
|
|
|
if item.identifier == @item.identifier
|
|
|
|
css_class = %Q{class="selected"}
|
|
|
|
prefix = "»"
|
|
|
|
suffix = "«"
|
|
|
|
end
|
|
|
|
%Q{<li><a href="#{default_path(item)}"#{css_class}>#{prefix}#{crumb}#{suffix}</a></li>#{child_html}}
|
2010-02-03 16:02:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|