Commit 9b7e7c9176e56164336425ef575cfc65857a7301
- Diff rendering mode:
- inline
- side by side
app/controllers/pages.rb
(8 / 8)
|   | |||
| 1 | 1 | class Pages < Application | |
| 2 | 2 | ||
| 3 | 3 | def index | |
| 4 | page_file = find_toc | ||
| 5 | raise NotFound unless page_file | ||
| 4 | @page_file = find_toc | ||
| 5 | raise NotFound unless @page_file | ||
| 6 | 6 | ||
| 7 | text = File.open(page_file).read | ||
| 7 | text = File.open(@page_file).read | ||
| 8 | 8 | render Maruku::new(text).to_html | |
| 9 | 9 | end | |
| 10 | 10 | ||
| 11 | 11 | def show | |
| 12 | chapter = params[:chapter] | ||
| 13 | page_name = params[:page_name] | ||
| 12 | @chapter = params[:chapter] | ||
| 13 | @page_name = params[:page_name] | ||
| 14 | 14 | ||
| 15 | page_file = find_page_file(chapter, page_name) | ||
| 16 | raise NotFound unless page_file | ||
| 15 | @page_file = find_page_file(@chapter, @page_name) | ||
| 16 | raise NotFound unless @page_file | ||
| 17 | 17 | ||
| 18 | text = File.open(page_file).read | ||
| 18 | text = File.open(@page_file).read | ||
| 19 | 19 | render Maruku::new(text).to_html | |
| 20 | 20 | end | |
| 21 | 21 |
|   | |||
| 22 | 22 | ||
| 23 | 23 | # Returns links to the previous and next pages. | |
| 24 | 24 | def page_nav_links(format = 'markdown') | |
| 25 | return unless params[:action] == 'show' # Don't need navigation for the TOC (index). | ||
| 25 | return if params[:action] != 'show' # Don't need navigation for the TOC (index). | ||
| 26 | 26 | links = [] | |
| 27 | chapter = params[:chapter] | ||
| 28 | page_name = params[:page_name] | ||
| 29 | current_file = Dir["#{Merb.root}/book-content/#{language}/*-#{chapter}/*-#{page_name||"*"}.#{format}"].entries.first | ||
| 30 | if current_file | ||
| 31 | current_file.grep(/book-content\/\w{2}\/(\d{1,})-[a-z-]+\/(\d{1,})-[a-z-]+[.]\w+/) | ||
| 32 | chapter_number, page_number = $1, $2 | ||
| 33 | end | ||
| 27 | @current_file =~ /book-content\/\w{2}\/(\d{1,})-[a-z-]+\/(\d{1,})-[a-z-]+[.]\w+/ | ||
| 28 | chapter_number, page_number = $1, $2 | ||
| 34 | 29 | ||
| 35 | 30 | chapter_name, page_name = extract_previous_page(chapter_number, page_number) | |
| 36 | 31 | links << previous_page(chapter_name, page_name) |

