Permalink
Browse files

can write directly to a branch

  • Loading branch information...
1 parent 12972b7 commit ebe0a52956b3d1ecb19c063694a2e74720957ebc @schacon schacon committed Jun 14, 2011
Showing with 30 additions and 12 deletions.
  1. +3 −1 README.md
  2. +26 −11 lib/docurium.rb
  3. +1 −0 site/js/docurium.js
View
@@ -40,14 +40,16 @@ The Docurium config file looks like this:
"github": "libgit2/libgit2",
"input": "include/git2",
"prefix": "git_",
- "output": "docs",
+ "branch": "gh-pages",
"examples": "examples",
"legacy": {
"input": {"src/git": ["v0.1.0"],
"src/git2": ["v0.2.0", "v0.3.0"]}
}
}
+You can either have a `branch` or an `output` entry - `branch` will write your docs directly into a Git branch, `output` will write them to a subdirectory.
+
# Installing
$ gem install docurium
View
@@ -68,8 +68,23 @@ def generate_docs
end
end
- if @options['branch']
- write_branch
+ if br = @options['branch']
+ out "* writing to branch #{br}"
+ ref = "refs/heads/#{br}"
+ with_git_env(outdir) do
+ psha = `git rev-parse #{ref}`.chomp
+ `git add -A`
+ tsha = `git write-tree`.chomp
+ puts "\twrote tree #{tsha}"
+ if(psha == ref)
+ csha = `echo 'generated docs' | git commit-tree #{tsha}`.chomp
+ else
+ csha = `echo 'generated docs' | git commit-tree #{tsha} -p #{psha}`.chomp
+ end
+ puts "\twrote commit #{csha}"
+ `git update-ref -m 'generated docs' #{ref} #{csha}`
+ puts "\tupdated #{br}"
+ end
else
final_dir = File.join(@project_dir, @options['output'] || 'docs')
out "* output html in #{final_dir}"
@@ -145,11 +160,17 @@ def git(command)
end
def checkout(version, workdir)
+ with_git_env(workdir) do
+ `git read-tree #{version}:#{@data[:prefix]}`
+ `git checkout-index -a`
+ end
+ end
+
+ def with_git_env(workdir)
ENV['GIT_INDEX_FILE'] = mkfile_temp
ENV['GIT_WORK_TREE'] = workdir
ENV['GIT_DIR'] = File.join(@project_dir, '.git')
- `git read-tree #{version}:#{@data[:prefix]}`
- `git checkout-index -a`
+ yield
ENV.delete('GIT_INDEX_FILE')
ENV.delete('GIT_WORK_TREE')
ENV.delete('GIT_DIR')
@@ -427,11 +448,6 @@ def strip_block(block)
block.strip
end
- def write_branch
- out "Writing to branch #{@branch}"
- out "Done!"
- end
-
def mkdir_temp
tf = Tempfile.new('docurium')
tpath = tf.path
@@ -443,11 +459,10 @@ def mkdir_temp
def mkfile_temp
tf = Tempfile.new('docurium-index')
tpath = tf.path
- tf.close
+ tf.unlink
tpath
end
-
def copy_site(outdir)
here = File.expand_path(File.dirname(__FILE__))
FileUtils.mkdir_p(outdir)
View
@@ -603,6 +603,7 @@ $(function() {
},
changelog: function(version, tname) {
+ docurium.setVersion()
docurium.showChangeLog()
},

0 comments on commit ebe0a52

Please sign in to comment.