Skip to content

Commit

Permalink
optimized navigation code and renamed folders
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Jan 31, 2009
1 parent cdc87f0 commit e633549
Show file tree
Hide file tree
Showing 29 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/helpers/global_helpers.rb
Expand Up @@ -24,10 +24,10 @@ def rtl_support_class
def page_nav_links(format = 'markdown')
return if params[:action] != 'show' || @page.nil? # Don't need navigation for the TOC (index).
links = []
links << previous_page_url
links << previous_page_url unless @page.previous_file.include?('table-of-contents')
# Stick a link to the TOC in the middle of the array.
links << link_to(language_text(language, 'Home'), url(:toc, :language => language))
links << next_page_url
links << next_page_url unless @page.next_file.include?('table-of-contents')
links.join(' | ')
end

Expand Down
13 changes: 7 additions & 6 deletions app/models/page.rb
Expand Up @@ -38,7 +38,7 @@ def next_file
return @next_file unless @next_file.nil?
n_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number}-*/#{page_number + 1}-*.*"].entries.first
if n_file.nil?
n_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number + 1}-*/**"].entries.first
n_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number + 1}-*/toc.*"].entries.first
# We're on the last page of the last chapter, just return the TOC.
n_file = "#{Merb.root}/book-content/#{language}/table-of-contents" if n_file.nil?
end
Expand All @@ -61,7 +61,8 @@ def previous_file
return @previous_file unless @previous_file.nil?
p_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number}-*/#{page_number - 1}-*.*"].entries.first
if p_file.nil?
p_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number - 1}-*/**"].entries.last
p_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number - 1}-*/[0-9]*?*.*"].entries.last
p_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number - 1}-*/toc.*"].entries.first if p_file.nil?
# We're on the last page of the last chapter, just return the TOC.
p_file = "#{Merb.root}/book-content/#{language}/table-of-contents" if p_file.nil?
end
Expand Down Expand Up @@ -91,8 +92,8 @@ def find_page_file
end

def extract_chapter_and_page_number
file =~ /book-content\/\w{2}\/(\d{1,})-[a-z-]+\/(\d{1,})-[a-z-]+[.]\w+/
@chapter_number, @page_number = $1.to_i, $2.to_i
file =~ /book-content\/\w{2}\/(\d{1,})-[a-z-]+\/((\d{1,})-[a-z-]+|toc)[.]\w+/
@chapter_number, @page_number = $1.to_i, $3.to_i
end

def extract_next_chapter_and_page_name
Expand All @@ -105,8 +106,8 @@ def extract_previous_chapter_and_page_name

# Returns an array with the chapter name and the page name of the file to process
def extract_chapter_and_page_number_for_file(file_to_process)
file_to_process.grep(/book-content\/\w{2}\/\d{1,}-([a-z-]+)\/\d{1,}-([a-z-]+)[.]\w+/)
[$1, $2]
file_to_process.grep(/book-content\/\w{2}\/\d{1,}-([a-z-]+)\/(\d{1,}-([a-z-]+)|(toc))[.]\w+/)
[$1, $3]
end

end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e633549

Please sign in to comment.