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)
|
2010-11-27 23:13:47 +00:00
|
|
|
classes = [""]
|
2010-04-24 17:43:32 +00:00
|
|
|
classes += item[:classnames] || []
|
|
|
|
classes << "demo" if item.identifier =~ /^\/examples/
|
|
|
|
classes.join(" ")
|
2010-01-21 19:54:47 +00:00
|
|
|
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
|
|
|
|
|
2010-03-29 08:10:53 +00:00
|
|
|
def find(identifier)
|
|
|
|
@items.find{|i| i.identifier == identifier}
|
|
|
|
end
|
|
|
|
|
2010-04-24 17:03:34 +00:00
|
|
|
def get_var(instance_var)
|
|
|
|
instance_variable_defined?("@#{instance_var}") ? instance_variable_get("@#{instance_var}") : yield
|
|
|
|
end
|
2010-12-19 00:25:49 +00:00
|
|
|
|
|
|
|
def sidebar_item(item)
|
|
|
|
if item.nil?
|
|
|
|
nil
|
|
|
|
elsif item[:sidebar]
|
|
|
|
item
|
|
|
|
else
|
|
|
|
sidebar_item(item.parent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_stylesheet(item)
|
|
|
|
i = sidebar_item(item)
|
|
|
|
i[:stylesheet] if i
|
|
|
|
end
|
2010-04-24 17:03:34 +00:00
|
|
|
|
|
|
|
|
2010-04-21 05:43:25 +00:00
|
|
|
def item_tree(item, options = {})
|
2010-02-03 16:02:27 +00:00
|
|
|
crumb = item[:crumb] || item[:title]
|
2010-04-21 16:37:02 +00:00
|
|
|
options[:heading_level] ||= 1 if options.fetch(:headings, true)
|
2010-02-03 16:02:27 +00:00
|
|
|
child_html = ""
|
2010-04-21 05:43:25 +00:00
|
|
|
if options.fetch(:depth,1) > 0
|
2010-05-05 07:38:25 +00:00
|
|
|
child_opts = options.dup
|
|
|
|
child_opts[:depth] -= 1 if child_opts.has_key?(:depth)
|
2010-12-19 00:25:49 +00:00
|
|
|
child_opts[:heading_depth] -= 1 if child_opts.has_key?(:heading_depth)
|
2010-05-05 07:38:25 +00:00
|
|
|
child_opts[:heading_level] += 1 if child_opts[:heading_level]
|
|
|
|
child_opts.delete(:omit_self)
|
|
|
|
item.children.sort_by{|c| c[:crumb] || c[:title]}.each do |child|
|
2010-11-15 21:53:36 +00:00
|
|
|
next if child[:navigable] == false
|
2010-05-05 07:38:25 +00:00
|
|
|
child_html << item_tree(child, child_opts)
|
|
|
|
end
|
2010-04-21 05:43:25 +00:00
|
|
|
else
|
|
|
|
options.delete(:heading_level)
|
2010-02-03 16:02:27 +00:00
|
|
|
end
|
2010-05-04 02:08:15 +00:00
|
|
|
child_html = render("partials/sidebar/container", :contents => child_html) unless child_html.size == 0
|
2010-03-28 06:46:06 +00:00
|
|
|
css_class = nil
|
2010-04-21 05:43:25 +00:00
|
|
|
contents = unless options[:omit_self]
|
2010-05-04 02:08:15 +00:00
|
|
|
item_opts = {
|
|
|
|
:current_item => item,
|
2010-11-22 00:28:03 +00:00
|
|
|
:selected => !!@item.identifier[item.identifier],
|
2010-05-04 02:08:15 +00:00
|
|
|
:crumb => item[:crumb] || item[:title]
|
|
|
|
}
|
2010-12-19 00:25:49 +00:00
|
|
|
if options[:heading_level] && (options.fetch(:heading_depth, 1) > 0)
|
2010-05-04 02:08:15 +00:00
|
|
|
render("partials/sidebar/heading",
|
|
|
|
item_opts.merge(:heading => "h#{options[:heading_level]}")
|
|
|
|
)
|
2010-04-21 05:43:25 +00:00
|
|
|
else
|
2010-05-04 02:08:15 +00:00
|
|
|
render("partials/sidebar/item", item_opts)
|
2010-04-21 05:43:25 +00:00
|
|
|
end
|
2010-03-29 08:10:53 +00:00
|
|
|
end
|
|
|
|
%Q{#{contents}#{child_html}}
|
2010-02-03 16:02:27 +00:00
|
|
|
end
|
|
|
|
|
2010-04-24 17:03:34 +00:00
|
|
|
def tutorial_item(path)
|
|
|
|
path = "" if path == :root
|
|
|
|
@items.detect do |i|
|
2010-11-22 01:30:41 +00:00
|
|
|
i.identifier == "/help/tutorials/#{path}"
|
2010-04-24 17:03:34 +00:00
|
|
|
end
|
|
|
|
end
|
2010-02-03 16:02:27 +00:00
|
|
|
|
2010-04-25 18:28:56 +00:00
|
|
|
def compass_version
|
|
|
|
v = Compass.version
|
2010-11-16 01:41:18 +00:00
|
|
|
"#{v[:major]}.#{v[:minor]}#{"."+v[:state] if v[:state]}.#{v[:build]}"
|
2010-04-25 18:28:56 +00:00
|
|
|
end
|
|
|
|
|