Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created April 25, 2011 06:57
Show Gist options
  • Save thinkerbot/940243 to your computer and use it in GitHub Desktop.
Save thinkerbot/940243 to your computer and use it in GitHub Desktop.
Pagination task for an rdoc tutorial
desc "Setup pagination links for tutorial"
task :paginate_tutorial do
pages = Dir.glob File.expand_path('../Tutorial/*', __FILE__)
pages.each_with_index do |page, index|
content = File.read(page)
content.gsub!(/^(Previous|Next)\[link:.*\]$/, '').strip!
previous_page = pages[index - 1]
next_page = pages[index + 1] || pages[0]
links = "Previous[link:files/Tutorial/#{File.basename(previous_page).gsub(/\s/, '%20')}.html]\n"
links += "Next[link:files/Tutorial/#{File.basename(next_page).gsub(/\s/, '%20')}.html]\n"
File.open(page, 'w') do |io|
io.puts links
io.puts
io.puts content
io.puts
io.puts links
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment