Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

Refactor TOC tests #278

Merged
merged 13 commits into from
May 28, 2015
66 changes: 34 additions & 32 deletions lib/toc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,6 @@ def chapter_github_source_url
"https://github.com/emberjs/guides/edit/master/source/#{current_page.path.gsub('.html', '.md')}"
end

def current_guide
return @current_guide if @current_guide

path = current_page.path.gsub('.html', '')
guide_path = path.split("/")[0]

@current_guide = data.guides.find do |guide|
guide.url == guide_path
end
end

def current_guide_index
data.guides.find_index(current_guide)
end

def current_chapter
return unless current_guide

return @current_chapter if @current_chapter
path = current_page.path.gsub('.html', '')
chapter_path = path.split('/')[1..-1].join('/')

@current_chapter = current_guide.chapters.find do |chapter|
chapter.url == chapter_path
end
end

def current_chapter_index
return unless current_guide
current_guide.chapters.find_index(current_chapter)
end

def chapter_links
%Q{
<footer>
Expand Down Expand Up @@ -238,6 +206,40 @@ def next_guide
end
end

private

def current_guide
return @current_guide if @current_guide

path = current_page.path.gsub('.html', '')
guide_path = path.split("/")[0]

@current_guide = data.guides.find do |guide|
guide.url == guide_path
end
end

def current_guide_index
data.guides.find_index(current_guide)
end

def current_chapter
return unless current_guide

return @current_chapter if @current_chapter
path = current_page.path.gsub('.html', '')
chapter_path = path.split('/')[1..-1].join('/')

@current_chapter = current_guide.chapters.find do |chapter|
chapter.url == chapter_path
end
end

def current_chapter_index
return unless current_guide
current_guide.chapters.find_index(current_chapter)
end

end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/guides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
guides:
- title: "Middleman Basics"
url: "middleman-basics"
chapters:
- title: "What even is middleman?"
url: "index"
- title: "Nobody really cares about this"
url: "meh"
skip_sidebar_item: true
- title: "Secret stuff"
url: "secret"
chapters:
- title: "Don't tell anybody"
url: ""
skip_sidebar: true
- title: "Extending Middleman"
url: "extending-middleman"
chapters:
- title: "What are extensions?"
url: "index"
skip_sidebar_item: true