Permalink
Browse files

Add guide_chapter_link helper

  • Loading branch information...
indirect committed Jul 5, 2011
1 parent 4d68931 commit a837a2aa23060dc2737cf8a7877091095f335bd8
Showing with 13 additions and 3 deletions.
  1. +13 −3 lib/guides/helpers.rb
View
@@ -58,18 +58,28 @@ def code(&block)
content_tag(:code, c)
end
- def guide_link(guide)
+ def guide_exists?(guide)
# Might be able to use build in view_paths methods but I couldn't figure them out - PW
exists = view_paths.any? do |p|
Guides::Generator::EXTENSIONS.any?{|e| File.exist? "#{p}/#{guide["url"]}.#{e}" }
end
+ end
- if exists
+ def guide_link(guide)
+ if guide_exists?(guide)
link_to guide["title"], "#{guide["url"]}.html"
else
guide["title"]
end
end
+
+ def guide_chapter_link(guide, chapter)
+ if guide_exists?(guide)
+ anchor = chapter.gsub(/\s/, '-').downcase
+ link_to(chapter, "#{guide["url"]}.html##{anchor}")
+ else
+ chapter
+ end
+ end
end
end
-

0 comments on commit a837a2a

Please sign in to comment.