Created
April 25, 2011 06:57
-
-
Save thinkerbot/940243 to your computer and use it in GitHub Desktop.
Pagination task for an rdoc tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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