lib/middleman-tansu/helpers.rb in middleman-tansu-0.0.2 vs lib/middleman-tansu/helpers.rb in middleman-tansu-0.0.3
- old
+ new
@@ -13,20 +13,64 @@
paths
end
def breadcrumbs(klass = 'breadcrumbs', root = "Top")
li = []
+ root = page_title("/") || root
li.push("<li class=\"root\">#{link_to(root, "/")}</li>")
paths = path_list(current_resource.path)
paths.each do |path|
+ name = page_title(path[:path]) || path[:name]
if path == paths.last
- li.push("<li class=\"current\">#{path[:name]}</li>")
+ li.push("<li class=\"current\">#{h(name)}</li>")
else
- li.push("<li>#{link_to(path[:name], path[:path])}</li>")
+ li.push("<li>#{link_to(name, path[:path])}</li>")
end
end
"<ul class=\"#{klass}\">\n#{li.join("\n")}\n</ul>"
+ end
+
+ def page_title(path)
+ if /\.html$/ !~ path
+ path = File.join(path, config.tansu[:default_document])
+ end
+ sitemap.find_resource_by_path(path).data.title
+ end
+
+ def page_title_or_path(path)
+ page_title(path) || path.gsub(/(index)?\.html$/, "")
+ end
+
+ def title(splitter = ' - ')
+ base_title = base_title()
+ page_title = page_title_or_path(current_resource.path)
+
+ if !page_title.empty?
+ "#{page_title}#{splitter}#{base_title}"
+ else
+ base_title
+ end
+ end
+
+ def heading
+ base_title = base_title()
+ page_title = page_title_or_path(current_resource.path)
+
+ if !page_title.empty?
+ page_title
+ else
+ base_title
+ end
+ end
+
+ def base_title
+ config[:site_title] || "Middleman-Tansu"
+ end
+
+ def index?
+ regex = Regexp.new("#{config.tansu[:default_document]}$")
+ regex =~ current_resource.path || "/" == current_resource.path
end
def children_pages(key = :date, order_by = :asc)
dirs = []
pages = []