Commit c0e3cd5486116326bb64800bb306a09dbbf926b2
- Diff rendering mode:
- inline
- side by side
Rakefile
(76 / 0)
|   | |||
| 33 | 33 | # ADD YOUR CUSTOM TASKS IN /lib/tasks | |
| 34 | 34 | # NAME YOUR RAKE FILES file_name.rake | |
| 35 | 35 | ############################################################################## | |
| 36 | |||
| 37 | desc "create chapter TOC" | ||
| 38 | task :create_chapter_tocs do | ||
| 39 | |||
| 40 | require 'maruku' | ||
| 41 | |||
| 42 | languages = Dir["#{Merb.root}/book-content/*"].entries.map{|f| File.basename(f) unless f.include? 'markdown'} | ||
| 43 | languages.each do |language| | ||
| 44 | chapters = Dir["#{Dir.pwd}/book-content/#{language}/*-*"].entries.map{|f| File.basename(f)[/\d-(.*)/, 1]} | ||
| 45 | chapters.each do |chapter| | ||
| 46 | save_chapter_toc(chapter, language) | ||
| 47 | end | ||
| 48 | end | ||
| 49 | |||
| 50 | end | ||
| 51 | |||
| 52 | def generate_toc_for_chapter(chapter_name, language) | ||
| 53 | require 'rexml/document' | ||
| 54 | |||
| 55 | files = Dir["#{Dir.pwd}/book-content/#{language}/*-#{chapter_name}/*-*.markdown"].entries | ||
| 56 | |||
| 57 | files.map do |page| | ||
| 58 | page_content = File.open(page).read | ||
| 59 | m_doc = Maruku::new(page_content) | ||
| 60 | |||
| 61 | if m_doc.toc.immediate_children.size > 0 | ||
| 62 | page_name = page[/\/book-content\/#{language}\/.*-#{chapter_name}\/.*-(.*)\.markdown/,1] | ||
| 63 | toc = m_doc.toc.create_toc.dup | ||
| 64 | |||
| 65 | # create a new entry for the file itself | ||
| 66 | top_li = REXML::Element.new("li") | ||
| 67 | top_li_a = REXML::Element.new("a") | ||
| 68 | top_li_a.attributes["href"] = "/#{language}/#{chapter_name}/#{page_name}" | ||
| 69 | top_li_a.text = m_doc.attributes[:title] | ||
| 70 | top_li << top_li_a | ||
| 71 | # | ||
| 72 | if REXML::XPath.first( toc, "//ul/li" ) | ||
| 73 | top_li << toc | ||
| 74 | top_li.to_s.to_s.gsub("href='#", "href='/#{language}/#{chapter_name}/#{page_name}#") | ||
| 75 | else | ||
| 76 | nil | ||
| 77 | end | ||
| 78 | |||
| 79 | else | ||
| 80 | nil | ||
| 81 | end | ||
| 82 | end.compact.join("\n\n") | ||
| 83 | |||
| 84 | # merged_files = files.map{|file| File.open(file).read}.join("\n") | ||
| 85 | # toc = "\n* This will become a table of contents (this text will be scraped).\n{:toc}\n" | ||
| 86 | # | ||
| 87 | # merged_files.gsub!(toc, "") | ||
| 88 | # merged_files = toc + merged_files | ||
| 89 | # | ||
| 90 | # mf = Maruku::new(merged_files) | ||
| 91 | # list = mf.to_html[/(<div class='maruku_toc'>.*<\/li><\/ul><\/div>)/, 1] | ||
| 92 | # | ||
| 93 | # list #? list.gsub("href='#", "href='") : nil | ||
| 94 | end | ||
| 95 | |||
| 96 | def save_chapter_toc(chapter, language) | ||
| 97 | chapter_dir = Dir["#{Dir.pwd}/book-content/#{language}/*-#{chapter}"].entries.first | ||
| 98 | filename = chapter_dir + "/toc.markdown" | ||
| 99 | File.open(filename, 'w') do |f| | ||
| 100 | f.write( "# #{chapter}\n\n #{generate_toc_for_chapter(chapter, language)} ") | ||
| 101 | end | ||
| 102 | end | ||
| 103 | |||
| 104 | # each chapter | ||
| 105 | # each page | ||
| 106 | # generate toc for the file .toc.create_toc | ||
| 107 | # gsub the links with chapter/page#anchor | ||
| 108 | # save the toc in memory | ||
| 109 | # save it in the chapter | ||
| 110 | |||
| 111 |
app/controllers/pages.rb
(7 / 3)
|   | |||
| 12 | 12 | @chapter = params[:chapter] | |
| 13 | 13 | @page_name = params[:page_name] | |
| 14 | 14 | ||
| 15 | @page_file = find_page_file(@chapter, @page_name) | ||
| 15 | @page_file = find_page_file | ||
| 16 | 16 | raise NotFound unless @page_file | |
| 17 | 17 | ||
| 18 | 18 | text = File.open(@page_file).read | |
| … | … | ||
| 21 | 21 | ||
| 22 | 22 | private | |
| 23 | 23 | # If no page name is being passed, the first page is being returned | |
| 24 | def find_page_file(chapter, page_name, format="markdown") | ||
| 25 | Dir["#{Merb.root}/book-content/#{language}/*-#{chapter}/*-#{page_name||"*"}.#{format}"].entries.first | ||
| 24 | def find_page_file(format="markdown") | ||
| 25 | if @page_name | ||
| 26 | Dir["#{Merb.root}/book-content/#{language}/*-#{@chapter}/*-#{@page_name}.#{format}"].entries.first | ||
| 27 | else | ||
| 28 | Dir["#{Merb.root}/book-content/#{language}/*-#{@chapter}/toc.#{format}"].entries.first | ||
| 29 | end | ||
| 26 | 30 | end | |
| 27 | 31 | ||
| 28 | 32 | def find_toc(format="markdown") |
|   | |||
| 1 | # front-matter | ||
| 2 | |||
| 3 |
|   | |||
| 1 | ## Merb | ||
| 1 | # Merb | ||
| 2 | 2 | ||
| 3 | 3 | Merb is the brainchild of [Ezra Zygmuntowicz](http://brainspl.at/). | |
| 4 | 4 | The very first 'public' version of Merb appeared as a pastie on September 21st, 2006. |
|   | |||
| 1 | ## DataMapper | ||
| 1 | # DataMapper |
|   | |||
| 1 | # introduction | ||
| 2 | |||
| 3 |
|   | |||
| 1 | # Getting started | ||
| 1 | # Install instruction | ||
| 2 | 2 | ||
| 3 | 3 | * This will become a table of contents (this text will be scraped). | |
| 4 | 4 | {:toc} |
|   | |||
| 1 | # getting-started | ||
| 2 | |||
| 3 | <li><a href='/en/getting-started/instructions'>Install instruction</a><ul style='list-style: none;'><li><a href='/en/getting-started/instructions#os_x'>OS X</a><ul style='list-style: none;'><li><a href='/en/getting-started/instructions#prerequisites'>Prerequisites</a></li><li><a href='/en/getting-started/instructions#ruby__rubygems'>Ruby & RubyGems</a></li><li><a href='/en/getting-started/instructions#merb'>Merb</a></li></ul></li><li><a href='/en/getting-started/instructions#linux'>Linux</a><ul style='list-style: none;'><li><a href='/en/getting-started/instructions#prerequisites'>Prerequisites</a></li><li><a href='/en/getting-started/instructions#ruby__rubygems'>Ruby & RubyGems</a></li><li><a href='/en/getting-started/instructions#merb'>Merb</a></li></ul></li><li><a href='/en/getting-started/instructions#windows'>Windows</a></li></ul></li> | ||
| 4 | |||
| 5 | <li><a href='/en/getting-started/application'>Generate an application</a><ul style='list-style: none;'><li><a href='/en/getting-started/application#types'>Types</a><ul style='list-style: none;'><li><a href='/en/getting-started/application#app'>App</a></li><li><a href='/en/getting-started/application#core'>Core</a></li><li><a href='/en/getting-started/application#flat'>Flat</a></li><li><a href='/en/getting-started/application#very_flat'>Very Flat</a></li></ul></li></ul></li> | ||
| 6 | |||
| 7 | <li><a href='/en/getting-started/structure'>Project structure</a><ul style='list-style: none;'><li><a href='/en/getting-started/structure#app'>app</a><ul style='list-style: none;'><li><a href='/en/getting-started/structure#controllers'>controllers</a></li><li><a href='/en/getting-started/structure#models'>models</a></li><li><a href='/en/getting-started/structure#views'>views</a></li></ul></li><li><a href='/en/getting-started/structure#config'>config</a><ul style='list-style: none;'><li><a href='/en/getting-started/structure#environments'>environments</a></li></ul></li><li><a href='/en/getting-started/structure#gems'>gems</a></li><li><a href='/en/getting-started/structure#public'>public</a><ul style='list-style: none;'><li><a href='/en/getting-started/structure#images'>images</a></li><li><a href='/en/getting-started/structure#javascripts'>javascripts</a></li><li><a href='/en/getting-started/structure#stylesheets'>stylesheets</a></li></ul></li><li><a href='/en/getting-started/structure#spec'>spec</a></li><li><a href='/en/getting-started/structure#tasks'>tasks</a></li></ul></li> | ||
| 8 | |||
| 9 | <li><a href='/en/getting-started/controllers'>Controllers</a><ul style='list-style: none;'><li><a href='/en/getting-started/controllers#restful_controllers'>RESTful controllers</a><ul style='list-style: none;'><li><a href='/en/getting-started/controllers#the_default_routing_style'>The Default Routing Style</a></li><li><a href='/en/getting-started/controllers#the_restful_style'>The RESTful Style</a><ul style='list-style: none;'><li><a href='/en/getting-started/controllers#index'>Index</a></li><li><a href='/en/getting-started/controllers#new'>New</a></li><li><a href='/en/getting-started/controllers#create'>Create</a></li><li><a href='/en/getting-started/controllers#show'>Show</a></li><li><a href='/en/getting-started/controllers#edit'>Edit</a></li><li><a href='/en/getting-started/controllers#update'>Update</a></li><li><a href='/en/getting-started/controllers#delete'>Delete</a></li><li><a href='/en/getting-started/controllers#destroy'>Destroy</a></li></ul></li><li><a href='/en/getting-started/controllers#adding_and_removing_methods'>Adding and Removing Methods</a></li></ul></li><li><a href='/en/getting-started/controllers#using_merbgen_with_controllers'>Using merb-gen With Controllers</a></li><li><a href='/en/getting-started/controllers#controller_action_methods'>Controller Action Methods</a><ul style='list-style: none;'><li><a href='/en/getting-started/controllers#render_and_display'>Render and Display</a></li><li><a href='/en/getting-started/controllers#interaction_with_model'>Interaction with Model</a></li><li><a href='/en/getting-started/controllers#information_from_the_request_the_params_and_request_hashes'>Information From the Request: The ‘params’ and ‘request’ Hashes</a></li><li><a href='/en/getting-started/controllers#persistant_information_about_the_client_sessions_and_cookies'>Persistant Information About the Client: Sessions and Cookies</a></li><li><a href='/en/getting-started/controllers#redirecting'>Redirecting</a></li><li><a href='/en/getting-started/controllers#exceptions_and_status_codes'>Exceptions and Status Codes</a></li></ul></li><li><a href='/en/getting-started/controllers#extending_controllers'>Extending Controllers</a><ul style='list-style: none;'><li><a href='/en/getting-started/controllers#formats'>Formats</a></li><li><a href='/en/getting-started/controllers#before_and_after_filters'>Before and After Filters</a></li><li><a href='/en/getting-started/controllers#use_of_application'>Use of ‘Application’</a></li><li><a href='/en/getting-started/controllers#private_methods'>Private Methods</a></li></ul></li></ul></li> |
|   | |||
| 1 | # interacting-with-the-database | ||
| 2 | |||
| 3 |
|   | |||
| 1 | # testing-your-application | ||
| 2 | |||
| 3 | <li><a href='/en/testing-your-application/why'>Why test</a><ul style='list-style: none;'><li><a href='/en/testing-your-application/why#types_of_tests'>Types of Tests</a><ul style='list-style: none;'><li><a href='/en/testing-your-application/why#models'>Models</a></li><li><a href='/en/testing-your-application/why#requests'>Requests</a></li><li><a href='/en/testing-your-application/why#integration'>Integration</a></li></ul></li></ul></li> |
|   | |||
| 1 | # merb-more | ||
| 2 | |||
| 3 | <li><a href='/en/merb-more/authentication'>Authentication</a><ul style='list-style: none;'><li><a href='/en/merb-more/authentication#merbauth_gems'>Merb-auth gems</a><ul style='list-style: none;'><li><a href='/en/merb-more/authentication#merbauthcore'>merb-auth-core</a></li><li><a href='/en/merb-more/authentication#merbauthmore'>merb-auth-more</a></li><li><a href='/en/merb-more/authentication#merbauthslicepassword'>merb-auth-slice-password</a></li></ul></li><li><a href='/en/merb-more/authentication#authentication_in_merb_stack'>Authentication in Merb Stack</a></li><li><a href='/en/merb-more/authentication#authenticated_hello_world'>Authenticated Hello World</a><ul style='list-style: none;'><li><a href='/en/merb-more/authentication#generate_an_application'>Generate an application</a></li><li><a href='/en/merb-more/authentication#generate_something_to_protect'>Generate something to protect</a></li><li><a href='/en/merb-more/authentication#protect_the_route'>Protect the route</a></li><li><a href='/en/merb-more/authentication#protect_the_controller'>Protect the controller</a></li><li><a href='/en/merb-more/authentication#overwrite_the_default_views'>Overwrite the default views</a></li></ul></li><li><a href='/en/merb-more/authentication#testing_an_authenticated_request'>Testing an authenticated request</a></li></ul></li> |
|   | |||
| 1 | # recipes | ||
| 2 | |||
| 3 |
|   | |||
| 1 | # deployment | ||
| 2 | |||
| 3 | <li><a href='/en/deployment/passenger'>Passenger</a><ul style='list-style: none;'><li><a href='/en/deployment/passenger#installing_ruby_enterprise_edition_ree'>Installing Ruby Enterprise Edition (REE)</a><ul style='list-style: none;'><li><a href='/en/deployment/passenger#download_ree'>Download REE</a></li><li><a href='/en/deployment/passenger#install'>Install</a></li></ul></li><li><a href='/en/deployment/passenger#installing_passenger'>Installing Passenger</a></li><li><a href='/en/deployment/passenger#configuration'>Configuration</a><ul style='list-style: none;'><li><a href='/en/deployment/passenger#configru'>config.ru</a></li></ul></li><li><a href='/en/deployment/passenger#capistrano_task'>Capistrano Task</a></li></ul></li> | ||
| 4 | |||
| 5 | <li><a href='/en/deployment/nginx'>Nginx</a><ul style='list-style: none;'><li><a href='/en/deployment/nginx#installation'>Installation</a><ul style='list-style: none;'><li><a href='/en/deployment/nginx#mac_os_x_requires_macports'>Mac OS X (requires <a href='http://macports.org/'>MacPorts</a>)</a></li><li><a href='/en/deployment/nginx#debian__ubuntu_linux'>Debian / Ubuntu Linux</a></li><li><a href='/en/deployment/nginx#gentoo_linux'>Gentoo Linux</a></li></ul></li><li><a href='/en/deployment/nginx#configuration'>Configuration</a><ul style='list-style: none;'><li><a href='/en/deployment/nginx#etcnginxnginxconf'>/etc/nginx/nginx.conf</a></li></ul></li><li><a href='/en/deployment/nginx#capistrano_task'>Capistrano Task</a></li><li><a href='/en/deployment/nginx#monit'>Monit</a></li></ul></li> |
|   | |||
| 1 | # appendix | ||
| 2 | |||
| 3 |

