Skip to content

Instantly share code, notes, and snippets.

@tommoor
Created November 25, 2013 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommoor/7640701 to your computer and use it in GitHub Desktop.
Save tommoor/7640701 to your computer and use it in GitHub Desktop.
def get_menu(directory)
pages = Dir.glob(Rails.root.join("app/views/docs/api/#{directory}/*.md"))
pages.map do |page|
heading = ''
pages = []
File.open(page, "rb").each do |line|
matches = /^\s?# (.+)/.match(line)
heading = matches[1] if matches
matches = /^\s?## (.+)/.match(line)
pages << matches[1] if matches
end
{
path: File.basename(page, ".md"),
heading: heading,
pages: pages
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment