Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move some codes to books controller

  • Loading branch information...
commit ef01c37b0c69bda0e16f380462b03c27910cb5d9 1 parent c9f7973
@bry4n bry4n authored
View
3  app/assets/javascripts/books.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/books.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the books controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
49 app/controllers/books_controller.rb
@@ -0,0 +1,49 @@
+class BooksController < ApplicationController
+
+ layout 'layout'
+
+ before_filter :book_resource, :only => [:section, :chapter]
+
+ def show
+ @book = Book.includes(:sections).where(:code => (params[:lang] || "en")).first
+ raise PageNotFound unless @book
+ end
+
+ def commands
+ @related = {}
+ ri = RelatedItem.where(:content_type => 'reference', :related_type => 'book')
+ ri.each do |item|
+ cmd = item.name.gsub('git-', '')
+ if s = Section.where(:slug => item.related_id).first
+ @related[cmd] ||= []
+ @related[cmd] << [s.cs_number, s.slug, item.score]
+ @related[cmd].sort!
+ end
+ end
+ @groups = CMD_GROUPS
+ end
+
+ def section
+ @content = @book.sections.where(:slug => params[:slug]).first
+ return redirect_to "/book/#{@book.code}" unless @content
+ @related = @content.get_related(8)
+ end
+
+ def chapter
+ chapter = params[:chapter].to_i
+ section = params[:section].to_i
+ chapter = @book.chapters.where(:number => chapter).first
+ @content = chapter.sections.where(:number => section).first
+ raise PageNotFound unless @content
+ render 'section'
+ end
+
+ private
+
+ def book_resource
+ @book ||= Book.where(:code => (params[:lang] || "en")).first
+ raise PageNotFound unless @book
+ @book
+ end
+
+end
View
38 app/controllers/doc_controller.rb
@@ -1,7 +1,7 @@
class DocController < ApplicationController
layout "layout"
- before_filter :book_resource, :only => [:index, :book_section, :progit]
+ before_filter :book_resource, :only => [:index]
def index
@videos = VIDEOS
@@ -67,32 +67,6 @@ def man
end
end
- def book
- @book = Book.includes(:sections).where(:code => (params[:lang] || "en")).first
- raise PageNotFound unless @book
- end
-
- def book_section
- @content = @book.sections.where(:slug => params[:slug]).first
- return redirect_to "/book/#{@book.code}" unless @content
- @related = @content.get_related(8)
- end
-
- # commands index
- def commands
- @related = {}
- ri = RelatedItem.where(:content_type => 'reference', :related_type => 'book')
- ri.each do |item|
- cmd = item.name.gsub('git-', '')
- if s = Section.where(:slug => item.related_id).first
- @related[cmd] ||= []
- @related[cmd] << [s.cs_number, s.slug, item.score]
- @related[cmd].sort!
- end
- end
- @groups = CMD_GROUPS
- end
-
def related_update
if params[:token] != ENV['UPDATE_TOKEN']
return render :text => 'nope'
@@ -104,16 +78,6 @@ def related_update
render :text => 'ok'
end
- # so we can display urls old progit.org style
- def progit
- chapter = params[:chapter].to_i
- section = params[:section].to_i
- chapter = @book.chapters.where(:number => chapter).first
- @content = chapter.sections.where(:number => section).first
- raise PageNotFound unless @content
- render 'book_section'
- end
-
# API Methods to update book content #
def book_update
View
2  app/helpers/books_helper.rb
@@ -0,0 +1,2 @@
+module BooksHelper
+end
View
1  app/views/books/_ebooks.html.erb
@@ -0,0 +1 @@
+<p>Download this book in <a href="https://github.s3.amazonaws.com/media/progit.en.pdf">PDF</a>, <a href="https://github.s3.amazonaws.com/media/pro-git.en.mobi">mobi</a>, or <a href="https://github.s3.amazonaws.com/media/progit.epub">ePub</a> form for free.</p>
View
23 app/views/books/_translations.html.erb
@@ -0,0 +1,23 @@
+<p>
+This book is translated into
+ <a href="/book/de">German</a>,
+ <a href="/book/zh">Chinese</a>,
+ <a href="/book/fr">French</a>,
+ <a href="/book/ja">Japanese</a> and
+ <a href="/book/nl">Dutch</a>.
+</p>
+
+<p>
+Partial translations available in
+ <a href="/book/ar">Arabic</a>,
+ <a href="/book/cs">Czech</a>,
+ <a href="/book/es">Spanish</a>,
+ <a href="/book/id">Indonesian</a>,
+ <a href="/book/it">Italian</a>,
+ <a href="/book/mk">Macedonian</a>,
+ <a href="/book/pl">Polish</a>,
+ <a href="/book/th">Thai</a> and
+ <a href="/book/ru">Russian</a>.
+</p>
+
+<hr class="sidebar"/>
View
30 app/views/books/commands.html.erb
@@ -0,0 +1,30 @@
+<% @section = 'documentation' %>
+<% @subsection = 'book' %>
+
+<div id='main' class='book'>
+ <h1>Index of Commands</h1>
+ <table class="commands">
+ <% @groups.each do |title, commands| %>
+ <tr>
+ <td colspan="10"><h2><%= title %></h2></td>
+ </tr>
+ <% commands.each do |cmd| %>
+ <tr>
+ <th>&nbsp;</th>
+ <th><%= cmd %></th>
+ <% if @related[cmd] %>
+ <% count = 0 %>
+ <% @related[cmd].each do |number, slug, score| %>
+ <% count += 1 %>
+ <% if count > 10 %>
+ <% count = 1 %>
+ </tr><tr><th>&nbsp;</th><td></td>
+ <% end %>
+ <td nowrap><a href="/book/en/<%= slug %>"><%= number %></a> <small>(<%= score %>)</small></td>
+ <% end %>
+ <% end %>
+ </tr>
+ <% end %>
+ <% end %>
+ </table>
+</div>
View
15 app/views/books/section.html.erb
@@ -0,0 +1,15 @@
+<% @section = 'documentation' %>
+<% @subsection = 'book' %>
+
+<% content_for :sidebar do %>
+ <%= render 'ebooks' %>
+ <%= render 'translations' %>
+ <%= render 'shared/related' %>
+<% end %>
+
+<div id='main' class="book">
+ <% if !@content.title.empty? %>
+ <h1><%= @content.cs_number %> <%=raw @content.chapter.title %> - <%=raw @content.title %></h1>
+ <% end %>
+ <div><%=raw linkify(@content.html, @content) %></div>
+</div>
View
37 app/views/books/show.html.erb
@@ -0,0 +1,37 @@
+<%- @section = 'documentation' %>
+<%- @subsection = 'book' %>
+<%- @page_title = "Git - Book" %>
+
+<% content_for :sidebar do %>
+ <%= render 'ebooks' %>
+ <%= render 'translations' %>
+<% end %>
+
+<div id='main'>
+ <h1>Book</h1>
+ <img style="float:right;margin: -20px 40px 0 40px;" src="/images/pro-git-118x157.jpg" />
+ <p>
+ The entire Pro Git book, written by Scott Chacon and published by Apress, is available here. All content is licensed under the <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution Non Commercial Share Alike 3.0 license</a>. Print versions of the book are available on <a href="http://www.amazon.com/gp/product/1430218339?ie=UTF8&tag=prgi-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1430218339">Amazon.com</a>.</>
+ </p>
+ <ol class='book-toc'>
+ <% @book.chapters.each do |chapter| %>
+ <li class='chapter'>
+ <h2><%= chapter.number %>. <a href="/book/<%= @book.code %>/<%= chapter.sections.first.slug %>"><%=raw chapter.title %></a></h2>
+ <ol>
+ <% chapter.sections.each do |section| %>
+ <% if !section.title.empty? %>
+ <li>
+ <%= chapter.number %>.<%= section.number %>
+ <a href="/book/<%= @book.code %>/<%= u(section.slug) %>"><%=raw section.title %></a>
+ </li>
+ <% end %>
+ <% end %>
+ </ol>
+ </li>
+ <% end %>
+ <li class='chapter'>
+ <h2><a href="/book/commands">Index of Commands</a></h2>
+ </li>
+ </ol>
+</div>
+
View
16 config/routes.rb
@@ -29,13 +29,15 @@
:version => /[^\/]+/
end
- match "/book" => "doc#book"
- match "/book/index" => "doc#book"
- match "/book/commands" => "doc#commands"
- match "/book/ch:chapter-:section.html" => "doc#progit"
- match "/book/:lang/ch:chapter-:section.html" => "doc#progit"
- match "/book/:lang" => "doc#book"
- match "/book/:lang/:slug" => "doc#book_section"
+ resource :book do
+ match "/index" => redirect("/book")
+ match "/commands" => "books#commands"
+ match "/:lang" => "books#show"
+ match "/:lang/:slug" => "books#section"
+ match "/ch:chapter-:section.html" => "books#chapter"
+ match "/:lang/ch:chapter-:section.html" => "books#chapter"
+ end
+
match "/publish" => "doc#book_update"
match "/related" => "doc#related_update"
match "/:year/:month/:day/:slug" => "doc#blog", :year => /\d{4}/,
View
19 test/functional/books_controller_test.rb
@@ -0,0 +1,19 @@
+require 'test_helper'
+
+class BooksControllerTest < ActionController::TestCase
+ test "gets the book page" do
+ book = FactoryGirl.create(:book, :code =>'en')
+ get :show, :lang => 'en'
+ assert_response :success
+ end
+
+ test "gets the book section page" do
+ end
+
+ test "gets the progit page" do
+ section = FactoryGirl.create(:section)
+ get :chapter, :chapter => section.chapter.number, :section => section.number
+ assert_response :success
+ end
+
+end
View
15 test/functional/doc_controller_test.rb
@@ -45,21 +45,6 @@ class DocControllerTest < ActionController::TestCase
assert_response :success
end
- test "gets the book page" do
- book = FactoryGirl.create(:book, :code =>'en')
- get :book, :lang => 'en'
- assert_response :success
- end
-
- test "gets the book section page" do
- end
-
- test "gets the progit page" do
- section = FactoryGirl.create(:section)
- get :progit, :chapter => section.chapter.number, :section => section.number
- assert_response :success
- end
-
test "gets the videos page" do
get :videos
assert_response :success
View
4 test/unit/helpers/books_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class BooksHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.