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:
authorScott Chacon <schacon@gmail.com>2012-03-08 21:09:45 +0400
committerScott Chacon <schacon@gmail.com>2012-03-08 21:09:45 +0400
commitd04f24a68684defd255969655202224a92f198a5 (patch)
tree5fad9aed6e0b365fbbc5898dcbbb84ceccab55b2
parent809c70009405caea73b4f56e0f186f9a3fe97f78 (diff)
add basic doc db structure and task to fill them from disk
-rw-r--r--Rakefile1
-rw-r--r--app/models/doc.rb3
-rw-r--r--app/models/doc_file.rb3
-rw-r--r--app/models/doc_version.rb5
-rw-r--r--app/models/version.rb6
-rw-r--r--config/routes.rb57
-rw-r--r--db/migrate/20120308153738_create_versions.rb12
-rw-r--r--db/migrate/20120308153855_create_doc_files.rb9
-rw-r--r--db/migrate/20120308153921_create_docs.rb11
-rw-r--r--db/migrate/20120308160013_create_doc_versions.rb10
-rw-r--r--db/schema.rb39
-rw-r--r--lib/tasks/index.rake54
-rw-r--r--public/index.html241
-rw-r--r--test/fixtures/doc_files.yml7
-rw-r--r--test/fixtures/doc_versions.yml11
-rw-r--r--test/fixtures/docs.yml9
-rw-r--r--test/fixtures/versions.yml9
-rw-r--r--test/unit/doc_file_test.rb7
-rw-r--r--test/unit/doc_test.rb7
-rw-r--r--test/unit/doc_version_test.rb7
-rw-r--r--test/unit/helpers/site_helper_test.rb4
-rw-r--r--test/unit/version_test.rb7
22 files changed, 222 insertions, 297 deletions
diff --git a/Rakefile b/Rakefile
index 97a4874b..8434d0b4 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,3 +5,4 @@
require File.expand_path('../config/application', __FILE__)
Gitscm::Application.load_tasks
+
diff --git a/app/models/doc.rb b/app/models/doc.rb
new file mode 100644
index 00000000..8ac1c2db
--- /dev/null
+++ b/app/models/doc.rb
@@ -0,0 +1,3 @@
+class Doc < ActiveRecord::Base
+ has_many :doc_versions
+end
diff --git a/app/models/doc_file.rb b/app/models/doc_file.rb
new file mode 100644
index 00000000..2270e129
--- /dev/null
+++ b/app/models/doc_file.rb
@@ -0,0 +1,3 @@
+class DocFile < ActiveRecord::Base
+ has_many :doc_versions
+end
diff --git a/app/models/doc_version.rb b/app/models/doc_version.rb
new file mode 100644
index 00000000..08eabd51
--- /dev/null
+++ b/app/models/doc_version.rb
@@ -0,0 +1,5 @@
+class DocVersion < ActiveRecord::Base
+ belongs_to :doc
+ belongs_to :version
+ belongs_to :doc_file
+end
diff --git a/app/models/version.rb b/app/models/version.rb
new file mode 100644
index 00000000..cb9149f2
--- /dev/null
+++ b/app/models/version.rb
@@ -0,0 +1,6 @@
+class Version < ActiveRecord::Base
+ validates :name, :uniqueness => true
+
+ has_many :doc_versions
+ has_many :docs, :through => :doc_versions
+end
diff --git a/config/routes.rb b/config/routes.rb
index 6545e5bc..1b0bcde0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,58 +1,5 @@
Gitscm::Application.routes.draw do
- # The priority is based upon order of creation:
- # first created -> highest priority.
+ get "site/index"
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id))(.:format)'
+ root :to => 'site#index'
end
diff --git a/db/migrate/20120308153738_create_versions.rb b/db/migrate/20120308153738_create_versions.rb
new file mode 100644
index 00000000..091b35f5
--- /dev/null
+++ b/db/migrate/20120308153738_create_versions.rb
@@ -0,0 +1,12 @@
+class CreateVersions < ActiveRecord::Migration
+ def change
+ create_table :versions do |t|
+ t.string :name
+ t.string :commit_sha
+ t.string :tree_sha
+ t.datetime :committed
+ t.timestamps
+ end
+ add_index :versions, [:name]
+ end
+end
diff --git a/db/migrate/20120308153855_create_doc_files.rb b/db/migrate/20120308153855_create_doc_files.rb
new file mode 100644
index 00000000..ca7ace74
--- /dev/null
+++ b/db/migrate/20120308153855_create_doc_files.rb
@@ -0,0 +1,9 @@
+class CreateDocFiles < ActiveRecord::Migration
+ def change
+ create_table :doc_files do |t|
+ t.string :name
+ t.timestamps
+ end
+ add_index :doc_files, [:name]
+ end
+end
diff --git a/db/migrate/20120308153921_create_docs.rb b/db/migrate/20120308153921_create_docs.rb
new file mode 100644
index 00000000..3b943607
--- /dev/null
+++ b/db/migrate/20120308153921_create_docs.rb
@@ -0,0 +1,11 @@
+class CreateDocs < ActiveRecord::Migration
+ def change
+ create_table :docs do |t|
+ t.text :blob_sha
+ t.text :plain
+ t.text :html
+ t.timestamps
+ end
+ add_index :docs, [:blob_sha]
+ end
+end
diff --git a/db/migrate/20120308160013_create_doc_versions.rb b/db/migrate/20120308160013_create_doc_versions.rb
new file mode 100644
index 00000000..a281aef5
--- /dev/null
+++ b/db/migrate/20120308160013_create_doc_versions.rb
@@ -0,0 +1,10 @@
+class CreateDocVersions < ActiveRecord::Migration
+ def change
+ create_table :doc_versions do |t|
+ t.belongs_to :version
+ t.belongs_to :doc
+ t.belongs_to :doc_file
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 671c0dae..99e5aaa8 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,6 +10,43 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 20120308160013) do
+
+ create_table "doc_files", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "doc_files", ["name"], :name => "index_doc_files_on_name"
+
+ create_table "doc_versions", :force => true do |t|
+ t.integer "version_id"
+ t.integer "doc_id"
+ t.integer "doc_file_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "docs", :force => true do |t|
+ t.text "blob_sha"
+ t.text "plain"
+ t.text "html"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "docs", ["blob_sha"], :name => "index_docs_on_blob_sha"
+
+ create_table "versions", :force => true do |t|
+ t.string "name"
+ t.string "commit_sha"
+ t.string "tree_sha"
+ t.datetime "committed"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "versions", ["name"], :name => "index_versions_on_name"
end
diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake
new file mode 100644
index 00000000..7100b1f0
--- /dev/null
+++ b/lib/tasks/index.rake
@@ -0,0 +1,54 @@
+# fill in the db from a local git clone
+task :preindex => :environment do
+ dir = ENV["GIT_REPO"]
+ Dir.chdir(dir) do
+ # find all tags
+ tags = `git tag | grep v1`.strip.split("\n")
+ tags = tags.select { |tag| tag =~ /v\d(\.\d)+$/ } # just get release tags
+
+ # for each tag, get a date and a list of file/shas
+ tags.each do |tag|
+ stag = Version.where(:name => tag).first_or_create
+
+ # extract metadata
+ commit_sha = `git rev-parse #{tag}`.chomp
+ tree_sha = `git rev-parse #{tag}^{tree}`.chomp
+ tagger = `git cat-file commit #{tag} | grep committer`.chomp.split(' ')
+ tz = tagger.pop
+ ts = tagger.pop
+ ts = Time.at(ts.to_i)
+
+ # save metadata
+ puts "#{tag}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}"
+ stag.commit_sha = commit_sha
+ stag.tree_sha = tree_sha
+ stag.committed = ts
+ stag.save
+
+ # find all the doc entries
+ entries = `git ls-tree #{tag}:Documentation`.strip.split("\n")
+ tree = entries.map do |e|
+ mode, type, sha, path = e.split(' ')
+ [path, sha, type]
+ end
+ tree = tree.select { |t| t.first =~ /.*\.txt/ }
+
+ puts "Found #{tree.size} entries"
+
+ tree.each do |entry|
+ path, sha, type = entry
+ path = path.gsub('.txt', '').gsub('v', '')
+ file = DocFile.where(:name => path).first_or_create
+ doc = Doc.where(:blob_sha => sha).first_or_create
+ if !doc.plain
+ content = `git cat-file blob #{sha}`.chomp
+ doc.plain = content
+ doc.save
+ end
+ DocVersion.where(:version_id => stag.id, :doc_id => doc.id, :doc_file_id => file.id).first_or_create
+ end
+
+ end
+ end
+end
+
diff --git a/public/index.html b/public/index.html
deleted file mode 100644
index a1d50995..00000000
--- a/public/index.html
+++ /dev/null
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
diff --git a/test/fixtures/doc_files.yml b/test/fixtures/doc_files.yml
new file mode 100644
index 00000000..0227c609
--- /dev/null
+++ b/test/fixtures/doc_files.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
diff --git a/test/fixtures/doc_versions.yml b/test/fixtures/doc_versions.yml
new file mode 100644
index 00000000..c63aac0b
--- /dev/null
+++ b/test/fixtures/doc_versions.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
diff --git a/test/fixtures/docs.yml b/test/fixtures/docs.yml
new file mode 100644
index 00000000..e0f4fe77
--- /dev/null
+++ b/test/fixtures/docs.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ plain: MyText
+ html: MyText
+
+two:
+ plain: MyText
+ html: MyText
diff --git a/test/fixtures/versions.yml b/test/fixtures/versions.yml
new file mode 100644
index 00000000..aea222f8
--- /dev/null
+++ b/test/fixtures/versions.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ committed: 2012-03-08
+
+two:
+ name: MyString
+ committed: 2012-03-08
diff --git a/test/unit/doc_file_test.rb b/test/unit/doc_file_test.rb
new file mode 100644
index 00000000..69820de0
--- /dev/null
+++ b/test/unit/doc_file_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class DocFileTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/doc_test.rb b/test/unit/doc_test.rb
new file mode 100644
index 00000000..93ef0aba
--- /dev/null
+++ b/test/unit/doc_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class DocTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/doc_version_test.rb b/test/unit/doc_version_test.rb
new file mode 100644
index 00000000..e0fc676f
--- /dev/null
+++ b/test/unit/doc_version_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class DocVersionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/helpers/site_helper_test.rb b/test/unit/helpers/site_helper_test.rb
new file mode 100644
index 00000000..fda64d0b
--- /dev/null
+++ b/test/unit/helpers/site_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class SiteHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb
new file mode 100644
index 00000000..d6d1a85b
--- /dev/null
+++ b/test/unit/version_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class VersionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end