2011-09-03 14:28:45 +02:00
|
|
|
# Helper functions for site-building.
|
2011-07-31 22:51:41 +02:00
|
|
|
|
|
|
|
include Nanoc3::Helpers::Breadcrumbs
|
|
|
|
|
|
|
|
class Nanoc3::Item
|
2011-09-03 14:28:45 +02:00
|
|
|
def add_content content
|
|
|
|
@raw_content += "\n\n#{content}"
|
|
|
|
end
|
|
|
|
|
2011-07-31 22:51:41 +02:00
|
|
|
def add_references refs
|
2011-09-03 14:28:45 +02:00
|
|
|
add_content refs
|
2011-07-31 22:51:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
identifier.split("/").last
|
|
|
|
end
|
|
|
|
end
|
2011-09-03 14:28:45 +02:00
|
|
|
|
|
|
|
# print all items in a category, nicely formatted
|
|
|
|
def category name
|
|
|
|
output = []
|
|
|
|
cat_match = %r{^/#{name}/}
|
|
|
|
|
|
|
|
# find category index
|
2011-09-03 17:29:00 +02:00
|
|
|
cat_index = printed_items.find{|i| i.path.match(cat_match) and i[:is_category]}
|
2011-09-03 14:28:45 +02:00
|
|
|
|
|
|
|
# header
|
|
|
|
output << "# [#{cat_index[:title]}]"
|
|
|
|
|
|
|
|
# find items in category
|
2011-09-03 17:29:00 +02:00
|
|
|
items = printed_items.select do |i|
|
|
|
|
( not i[:is_category] and
|
2011-09-03 14:28:45 +02:00
|
|
|
i.path.match cat_match
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# items in nice list
|
2011-09-03 17:29:00 +02:00
|
|
|
items.sort_by{|i| i[:title]}.each do |i|
|
2011-09-03 14:28:45 +02:00
|
|
|
output << "- [#{i[:title]}]"
|
|
|
|
end
|
|
|
|
|
|
|
|
# output
|
|
|
|
output.map{|i| "#{i}\n"}.join
|
|
|
|
end
|
|
|
|
|
|
|
|
# only articles that actually get printed
|
|
|
|
def printed_items
|
2011-09-03 17:29:00 +02:00
|
|
|
@items.select { |i| not i[:is_hidden] and not i.binary? }
|
2011-09-03 14:28:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
#automatic links for all pages, used by reference file
|
|
|
|
def page_references
|
|
|
|
output = []
|
|
|
|
printed_items.each do |i|
|
|
|
|
output << "[#{i[:title]}]: #{i.identifier}"
|
|
|
|
|
|
|
|
unless i[:alt_titles].nil?
|
|
|
|
i[:alt_titles].each do |title|
|
|
|
|
output << "[#{title}]: #{i.identifier}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# output
|
|
|
|
output.map{|i| "#{i}\n"}.join
|
|
|
|
end
|