Skip to content

Commit

Permalink
Omit leading slashes on links for /docs TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Apr 5, 2013
1 parent dd3b87e commit 491eba6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def nextpages
end

def toc_link page
link_text = page.split(/[-_]/).map{|s|s.capitalize}.join(' ')
link_text = page.sub(%r{^/}, '').split(/[-_]/).map{|s|s.capitalize}.join(' ')
path = page.start_with?('/') ? page : "/#{@site_name}/" + page
li do
if page == page_name
Expand Down
14 changes: 9 additions & 5 deletions spec/contents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
@meals_toc = Contents.new(site_name: 'meals', site_dir: "#{here}/sites/meals", page_name: 'prepare_a_meal')
end

it "should render absolute links absolutely" do
@docs_toc = Contents.new(site_name: 'docs', site_dir: "#{real_sites_dir}/docs", page_name: 'docs')
describe "absolute links" do
before do
docs_toc = Contents.new(site_name: 'docs', site_dir: "#{real_sites_dir}/docs", page_name: 'docs')
@toc_html = Nokogiri.parse(docs_toc.to_html)
end

toc_html = Nokogiri.parse(@docs_toc.to_html)
links = toc_html.css('a').inject({}) { |hsh, link| hsh[link.text] = link.attr('href'); hsh }
links['/curriculum'].should == '/curriculum'
it "should render absolute links absolutely" do
links = @toc_html.css('a').inject({}) { |hsh, link| hsh[link.text] = link.attr('href'); hsh }
links['Curriculum'].should == '/curriculum'
end
end

it "scans for subpage links" do
Expand Down

0 comments on commit 491eba6

Please sign in to comment.