Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git-scm.com.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock5
-rw-r--r--TODO.txt4
-rw-r--r--app/controllers/doc_controller.rb32
-rw-r--r--app/controllers/site_controller.rb33
-rw-r--r--app/models/book.rb1
-rw-r--r--app/models/chapter.rb2
-rw-r--r--app/models/doc.rb32
-rw-r--r--app/models/section.rb68
-rw-r--r--app/views/doc/_versions.html.erb5
-rw-r--r--app/views/doc/book.html.erb115
-rw-r--r--app/views/doc/book_section.html.erb7
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20120418152515_add_chapter_title_numbers.rb11
-rw-r--r--db/schema.rb4
-rw-r--r--lib/tasks/book.rake53
16 files changed, 206 insertions, 170 deletions
diff --git a/Gemfile b/Gemfile
index ae2f0c99..de336273 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,6 +21,8 @@ gem 'octokit'
gem 'dalli'
gem 'diff-lcs'
gem 'redcarpet'
+gem 'nestful'
+gem 'slugize'
# Gems used only for assets and not required
# in production environments by default.
diff --git a/Gemfile.lock b/Gemfile.lock
index 379efacc..ed3b22bd 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -99,6 +99,8 @@ GEM
mime-types (1.18)
multi_json (1.3.2)
multipart-post (1.1.5)
+ nestful (0.0.8)
+ activesupport (>= 3.0.0.beta)
netrc (0.7.1)
octokit (1.0.2)
addressable (~> 2.2)
@@ -147,6 +149,7 @@ GEM
rack (>= 1.0)
sinatra (1.0)
rack (>= 1.0)
+ slugize (0.0.2)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -195,6 +198,7 @@ DEPENDENCIES
json
launchy
less-rails-bootstrap
+ nestful
netrc
octokit
pg
@@ -204,6 +208,7 @@ DEPENDENCIES
rubyzip
sass-rails
shotgun
+ slugize
sqlite3
sqlite3-ruby
taps
diff --git a/TODO.txt b/TODO.txt
index 3c3edf5e..ace56790 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -4,6 +4,7 @@ Content Linking:
# get company logo perms
* SFC donate page?
* change win download repo to msys when they start uploading
+ * page titles filled out
Functionality:
@@ -13,9 +14,6 @@ Functionality:
* dlist dd with nested ulist with continuations (eg. git-blame -L)
* "admonition block" (eg. NOTE at the end of git-blame)
-* Downloads
- - /download/gui/(mac/win/linux)
-
* Version Dropdown
* highlight current version
* all versions page
diff --git a/app/controllers/doc_controller.rb b/app/controllers/doc_controller.rb
index df6af8c1..966d3313 100644
--- a/app/controllers/doc_controller.rb
+++ b/app/controllers/doc_controller.rb
@@ -1,3 +1,4 @@
+
class DocController < ApplicationController
layout "layout"
@@ -31,16 +32,43 @@ class DocController < ApplicationController
def book
lang = params[:lang] || 'en'
+ @book = Book.where(:code => lang).first
end
def book_section
+ lang = params[:lang]
+ slug = params[:slug]
+ @content = Book.where(:code => lang).first.sections.where(:slug => slug).first
end
def book_update
- # TODO: check credentials
+ if params[:token] != ENV['UPDATE_TOKEN']
+ return render :text => 'nope'
+ end
+
lang = params[:lang]
- section = params[:section]
+ chapter = params[:chapter].to_i
+ section = params[:section].to_i
+ chapter_title = params[:chapter_title]
+ section_title = params[:section_title]
content = params[:content]
+
+ # create book (if needed)
+ book = Book.where(:code => lang).first_or_create
+
+ # create chapter (if needed)
+ chapter = book.chapters.where(:number => chapter).first_or_create
+ chapter.title = chapter_title
+ chapter.save
+
+ # create/update section
+ section = chapter.sections.where(:number => section).first_or_create
+ section.title = section_title
+ section.html = content
+ section.save
+
+ # TODO: find and index commands
+ render :text => 'ok'
end
# API Methods to update book content #
diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb
index 14855548..8304df12 100644
--- a/app/controllers/site_controller.rb
+++ b/app/controllers/site_controller.rb
@@ -12,36 +12,19 @@ class SiteController < ApplicationController
def search
sname = params['search'].downcase
- query_options = {
- "bool" => {
- "should" => [
- { "prefix" => { "name" => { "value" => sname, "boost" => 12.0 } } },
- { "term" => { "text" => sname } }
- ],
- "minimum_number_should_match" => 1
- }
+ @data = {
+ :term => sname,
+ :results => []
}
- resp = BONSAI.search( 'doc',
- 'query' => query_options,
- 'size' => 10)
-
- #pp resp
- ref_hits = []
+ if results = Doc.search(sname)
+ @data[:results] << results
+ end
- resp['hits']['hits'].each do |hit|
- name = hit["_source"]["name"]
- ref_hits << {
- :name => name,
- #:meta => hit["_score"],
- :url => "/ref/#{name}"
- }
+ if results = Section.search(sname)
+ @data[:results] << results
end
- @data = {
- :term => sname,
- :results => [{ :category => "Reference", :term => sname, :matches => ref_hits }]
- }
render :partial => 'shared/search'
end
end
diff --git a/app/models/book.rb b/app/models/book.rb
index e7245b0a..f5839916 100644
--- a/app/models/book.rb
+++ b/app/models/book.rb
@@ -2,4 +2,5 @@
# t.timestamps
class Book < ActiveRecord::Base
has_many :chapters
+ has_many :sections, :through => :chapters
end
diff --git a/app/models/chapter.rb b/app/models/chapter.rb
index f7074127..51c1f680 100644
--- a/app/models/chapter.rb
+++ b/app/models/chapter.rb
@@ -1,7 +1,9 @@
# t.string :title
+# t.integer :number
# t.belongs_to :book
# t.timestamps
class Chapter < ActiveRecord::Base
+ default_scope :order => 'number'
belongs_to :book
has_many :sections
end
diff --git a/app/models/doc.rb b/app/models/doc.rb
index 6eddf9f0..72a6ab25 100644
--- a/app/models/doc.rb
+++ b/app/models/doc.rb
@@ -8,6 +8,38 @@ require 'pp'
class Doc < ActiveRecord::Base
has_many :doc_versions
+ def self.search(term)
+ query_options = {
+ "bool" => {
+ "should" => [
+ { "prefix" => { "name" => { "value" => term, "boost" => 12.0 } } },
+ { "term" => { "text" => term } }
+ ],
+ "minimum_number_should_match" => 1
+ }
+ }
+
+ resp = BONSAI.search('doc',
+ 'query' => query_options,
+ 'size' => 10)
+
+ ref_hits = []
+ resp['hits']['hits'].each do |hit|
+ name = hit["_source"]["name"]
+ ref_hits << {
+ :name => name,
+ #:meta => hit["_score"],
+ :url => "/ref/#{name}"
+ }
+ end
+
+ if ref_hits.size > 0
+ return { :category => "Reference", :term => term, :matches => ref_hits }
+ else
+ nil
+ end
+ end
+
# returns an array of the differences with 3 entries
# 0: additions
# 1: subtractions
diff --git a/app/models/section.rb b/app/models/section.rb
index 9f4e4b57..6e8891c6 100644
--- a/app/models/section.rb
+++ b/app/models/section.rb
@@ -1,4 +1,7 @@
+require 'slugize'
+
# t.string :title
+# t.integer :number
# t.string :slug
# t.text :plain
# t.text :html
@@ -6,5 +9,70 @@
# t.belongs_to :chapter
# t.timestamps
class Section < ActiveRecord::Base
+ default_scope :order => 'number'
+
belongs_to :chapter
+ before_save :set_slug
+ after_save :index
+
+ def set_slug
+ if self.title
+ self.slug = (self.chapter.title + '-' + self.title).slugize
+ end
+ end
+
+ def cs_number
+ self.chapter.number.to_s + '.' + self.number.to_s
+ end
+
+ def index
+ if BONSAI
+ data = {
+ 'chapter' => self.chapter.title,
+ 'section' => self.title,
+ 'number' => self.cs_number,
+ 'lang' => self.chapter.book.code,
+ 'html' => self.html,
+ }
+ BONSAI.add 'book', self.slug, data
+ end
+ end
+
+ def self.search(term)
+ query_options = {
+ "bool" => {
+ "should" => [
+ { "prefix" => { "section" => { "value" => term, "boost" => 12.0 } } },
+ { "term" => { "html" => term } }
+ ],
+ "minimum_number_should_match" => 1
+ }
+ }
+
+ resp = BONSAI.search('book',
+ 'query' => query_options,
+ 'size' => 10)
+
+ ref_hits = []
+ resp['hits']['hits'].each do |hit|
+ name = hit["_source"]["section"]
+ name = hit["_source"]["chapter"] if name.empty?
+ slug = hit["_id"]
+ lang = hit["_source"]["lang"]
+ meta = "Chapter " + hit["_source"]['number'] + ' : ' + hit["_source"]["chapter"]
+ ref_hits << {
+ :name => name,
+ :meta => meta,
+ :url => "/book/#{lang}/#{slug}"
+ }
+ end
+
+ if ref_hits.size > 0
+ return { :category => "Book", :term => term, :matches => ref_hits }
+ else
+ nil
+ end
+
+ end
+
end
diff --git a/app/views/doc/_versions.html.erb b/app/views/doc/_versions.html.erb
index 7e523620..ce2504a6 100644
--- a/app/views/doc/_versions.html.erb
+++ b/app/views/doc/_versions.html.erb
@@ -25,9 +25,8 @@
<li class="no-change"><span><%=raw v[:name] %></span></li>
<% end %>
<% end %>
- <li>
- <a class="more" href="#">See more previous releases →</a>
- </li>
+ <li>&nbsp;</li>
+ <!-- <li><a class="more" href="#">See more previous releases →</a></li> -->
</ol>
<footer>
<span class="light">Check your version of git by running<br></span>
diff --git a/app/views/doc/book.html.erb b/app/views/doc/book.html.erb
index cc01e44c..1dd5831b 100644
--- a/app/views/doc/book.html.erb
+++ b/app/views/doc/book.html.erb
@@ -8,115 +8,26 @@
The entire Pro Git book, written by Scott Chacon and published by Apress, is available here. All content is licensed under the <a href="#">Creative Commons Attribution Non Commercial Share Alike 3.0 license</a>. Print versions of the book are <a href="#">available on Amazon.com</a>.
</p>
<ol class='book-toc'>
+ <% @book.chapters.each do |chapter| %>
<li class='chapter'>
- <h2>1. <a href="#">Getting Started</a></h2>
+ <h2><%= chapter.number %>. <a href="/book/<%= @book.code %>/<%= chapter.title.slugize %>"><%= chapter.title %></a></h2>
<ol>
- <li>1.1 <a href="#">About Version Control</a></li>
- <li>1.2 <a href="#">A Short History of Git</a></li>
- <li>1.3 <a href="#">Git Basics</a></li>
- <li>1.4 <a href="#">Installing Git</a></li>
- <li>1.5 <a href="#">First-Time Git Setup</a></li>
- <li>1.6 <a href="#">Getting Help</a></li>
- <li>1.7 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>2. <a href="#">Git Basics</a></h2>
- <ol>
- <li>2.1 <a href="#">Getting a Git Repository</a></li>
- <li>2.2 <a href="#">Recording Changes to the Repository</a></li>
- <li>2.3 <a href="#">Viewing the Commit History</a></li>
- <li>2.4 <a href="#">Undoing Things</a></li>
- <li>2.5 <a href="#">Working with Remotes</a></li>
- <li>2.6 <a href="#">Tagging</a></li>
- <li>2.7 <a href="#">Tips and Tricks</a></li>
- <li>2.8 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>3. <a href="#">Git Branching</a></h2>
- <ol>
- <li>3.1 <a href="#">What a Branch Is</a></li>
- <li>3.2 <a href="#">Basic Branching and Merging</a></li>
- <li>3.3 <a href="#">Branch Management</a></li>
- <li>3.4 <a href="#">Branching Workflows</a></li>
- <li>3.5 <a href="#">Remote Branches</a></li>
- <li>3.6 <a href="#">Rebasing</a></li>
- <li>3.7 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>4. <a href="#">Git on the Server</a></h2>
- <ol>
- <li>4.1 <a href="#">The Protocols</a></li>
- <li>4.2 <a href="#">Getting Git on a Server</a></li>
- <li>4.3 <a href="#">Generating Your SSH Public Key</a></li>
- <li>4.4 <a href="#">Setting Up the Server</a></li>
- <li>4.5 <a href="#">Public Access</a></li>
- <li>4.6 <a href="#">GitWeb</a></li>
- <li>4.7 <a href="#">Gitosis</a></li>
- <li>4.8 <a href="#">Gitolite</a></li>
- <li>4.9 <a href="#">Git Daemon</a></li>
- <li>4.10 <a href="#">Hosted Git</a></li>
- <li>4.11 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>5. <a href="#">Distributed Git</a></h2>
- <ol>
- <li>5.1 <a href="#">Distributed Workflows</a></li>
- <li>5.2 <a href="#">Contributing to a Project</a></li>
- <li>5.3 <a href="#">Maintaining a Project</a></li>
- <li>5.4 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>6. <a href="#">Git Tools</a></h2>
- <ol>
- <li>6.1 <a href="#">Revision Selection</a></li>
- <li>6.2 <a href="#">Interactive Staging</a></li>
- <li>6.3 <a href="#">Stashing</a></li>
- <li>6.4 <a href="#">Rewriting History</a></li>
- <li>6.5 <a href="#">Debugging with Git</a></li>
- <li>6.6 <a href="#">Submodules</a></li>
- <li>6.7 <a href="#">Subtree Merging</a></li>
- <li>6.8 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>7. <a href="#">Customizing Git</a></h2>
- <ol>
- <li>7.1 <a href="#">Git Configuration</a></li>
- <li>7.2 <a href="#">Git Attributes</a></li>
- <li>7.3 <a href="#">Git Hooks</a></li>
- <li>7.4 <a href="#">An Example Git-Enforced Policy</a></li>
- <li>7.5 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>8. <a href="#">Git and Other Systems</a></h2>
- <ol>
- <li>8.1 <a href="#">Git and Subversion</a></li>
- <li>8.2 <a href="#">Migrating to Git</a></li>
- <li>8.3 <a href="#">Summary</a></li>
- </ol>
- </li>
- <li class='chapter'>
- <h2>9. <a href="#">Git Internals</a></h2>
- <ol>
- <li>9.1 <a href="#">Plumbing and Porcelain</a></li>
- <li>9.2 <a href="#">Git Objects</a></li>
- <li>9.3 <a href="#">Git References</a></li>
- <li>9.4 <a href="#">Packfiles</a></li>
- <li>9.5 <a href="#">The Refspec</a></li>
- <li>9.6 <a href="#">Transfer Protocols</a></li>
- <li>9.7 <a href="#">Maintenance and Data Recovery</a></li>
- <li>9.8 <a href="#">Summary</a></li>
+ <% chapter.sections.each do |section| %>
+ <% if !section.title.empty? %>
+ <li>
+ <%= chapter.number %>.<%= section.number %>
+ <a href="/book/<%= @book.code %>/<%= section.slug %>"><%= section.title %></a>
+ </li>
+ <% end %>
+ <% end %>
</ol>
</li>
+ <% end %>
+ <!--
<li class='chapter'>
<h2><a href="#">Index of Commands</a></h2>
</li>
+ -->
</ol>
</div>
diff --git a/app/views/doc/book_section.html.erb b/app/views/doc/book_section.html.erb
new file mode 100644
index 00000000..01d36ba8
--- /dev/null
+++ b/app/views/doc/book_section.html.erb
@@ -0,0 +1,7 @@
+<% @section = 'documentation' %>
+<% @subsection = 'book' %>
+
+<div id='main'>
+ <h1><%= @content.cs_number %> <%= @content.chapter.title %> - <%= @content.title %></h1>
+ <div><%=raw @content.html %></div>
+</div>
diff --git a/config/routes.rb b/config/routes.rb
index 700fe4ec..eb38666a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -12,7 +12,7 @@ Gitscm::Application.routes.draw do
match "/book" => "doc#book"
match "/book/:lang" => "doc#book"
match "/book/:lang/:slug" => "doc#book_section"
- match "/book/update" => "doc#book_update"
+ match "/publish" => "doc#book_update"
match "/about" => "about#index"
match "/community" => "community#index"
diff --git a/db/migrate/20120418152515_add_chapter_title_numbers.rb b/db/migrate/20120418152515_add_chapter_title_numbers.rb
new file mode 100644
index 00000000..2e0a2dae
--- /dev/null
+++ b/db/migrate/20120418152515_add_chapter_title_numbers.rb
@@ -0,0 +1,11 @@
+class AddChapterTitleNumbers < ActiveRecord::Migration
+ def up
+ add_column :chapters, :number, :integer
+ add_column :sections, :number, :integer
+ end
+
+ def down
+ remove_column :chapters, :number
+ remove_column :sections, :number
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index cf55e750..6b30943b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120417224143) do
+ActiveRecord::Schema.define(:version => 20120418152515) do
create_table "books", :force => true do |t|
t.string "code"
@@ -26,6 +26,7 @@ ActiveRecord::Schema.define(:version => 20120417224143) do
t.integer "book_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "number"
end
add_index "chapters", ["book_id"], :name => "index_chapters_on_book_id"
@@ -74,6 +75,7 @@ ActiveRecord::Schema.define(:version => 20120417224143) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "source_url"
+ t.integer "number"
end
add_index "sections", ["chapter_id"], :name => "index_sections_on_chapter_id"
diff --git a/lib/tasks/book.rake b/lib/tasks/book.rake
index 3d84a02a..de208428 100644
--- a/lib/tasks/book.rake
+++ b/lib/tasks/book.rake
@@ -1,7 +1,11 @@
require 'redcarpet'
+require 'nestful'
require 'awesome_print'
# export GITBOOK_DIR=../../writing/progit/
+# export GITBOOK_DIR=../../writing/progit/
+
+CONTENT_SERVER = ENV["CONTENT_SERVER"] || "http://localhost:3000"
def generate_pages(lang, chapter, content)
toc = {:title => '', :sections => []}
@@ -35,7 +39,6 @@ def generate_pages(lang, chapter, content)
end
full_title = section_match ? "#{chapter_title} #{section_title}" : chapter_title
- layout = lang == 'en' ? 'master' : 'translation'
html = ''
if section_match
@@ -46,13 +49,24 @@ def generate_pages(lang, chapter, content)
html += sec
- nav = "<div id='nav'>
-<a href='[[nav-prev]]'>prev</a> | <a href='[[nav-next]]'>next</a>
-</div>"
+ nav = "<div id='nav'><a href='[[nav-prev]]'>prev</a> | <a href='[[nav-next]]'>next</a></div>"
html += nav
- # TODO: post to git-scm site endpoint
- puts "\t\t#{chapter}.#{section} : #{chapter_title} . #{section_title} - #{html.size}"
+ data = {
+ :lang => lang,
+ :chapter => chapter,
+ :section => section,
+ :chapter_title => chapter_title,
+ :section_title => section_title,
+ :content => html,
+ :token => ENV['UPDATE_TOKEN']
+ }
+
+ url = CONTENT_SERVER + "/publish"
+ result = Nestful.post url, :format => :form, :params => data
+
+ puts "\t\t#{chapter}.#{section} : #{chapter_title} . #{section_title} - #{html.size} (#{result})"
+
section += 1
end
toc
@@ -99,30 +113,3 @@ task :genbook do
end
end
-
-# generate the site
-desc "Convert images"
-task :convert_images do
- Dir.chdir('figures') do
- Dir.glob("*").each do |chapter|
- Dir.chdir(chapter) do
- Dir.glob("*").each do |image|
- puts image
- (im, ending) = image.split('.')
- if ending == 'png' and im[-3, 3] != '-tn'
- convert_image = "#{im}-tn.png"
- if !File.exists?(convert_image)
- width_out = `exiftool #{image} | grep 'Image Width'`
- width = width_out.scan(/: (\d+)/).first.first.to_i
- if width > 500
- `convert -thumbnail 500x #{image} #{convert_image}`
- else
- `cp #{image} #{convert_image}`
- end
- end
- end
- end
- end
- end
- end
-end