class FubuDocs
Attributes
branch[RW]
export_dir[RW]
prefix[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/fubudocs.rb, line 34 def initialize(options) # :host, :include, :nested, :dump @branch = options.fetch(:branch, 'gh-pages') @repository = options[:repository] @prefix = options.fetch(:prefix, 'docs') @export_dir = options.fetch(:dir, 'fubudocs-export') @options = options end
Public Instance Methods
clean()
click to toggle source
# File lib/fubudocs.rb, line 64 def clean cleanDirectory @export_dir Dir.delete @export_dir unless !Dir.exists?(@export_dir) end
commit_new()
click to toggle source
# File lib/fubudocs.rb, line 114 def commit_new # commit and push the generated docs Dir.chdir @export_dir if !File.exists?('.nojekyll') writeNoJekyll end sh "git add ." sh 'git commit -a -m "Doc generation version ' + @options[:version] + '"' do |ok, res| if ok sh "git push origin #{@branch}" puts "Documentation generation and push to #{@repository}/#{@branch} is successful" else puts "commit failed, might be because there are no differences in the content" end end Dir.chdir '..' end
create_branch()
click to toggle source
# File lib/fubudocs.rb, line 69 def create_branch sh "ripple gitignore #{@export_dir}" sh "git clone #{@repository} #{@export_dir}" Dir.chdir @export_dir sh "git checkout --orphan #{@branch}" sh "git rm -rf ." writeNoJekyll sh "git add ." sh 'git commit -a -m "initial clean slate"' sh 'git push origin #{@branch}' Dir.chdir '..' end
dump_task()
click to toggle source
# File lib/fubudocs.rb, line 156 def dump_task dumpTask = Rake::Task.define_task "#{@prefix}:dump" do clean @options[:dump] = true export end dumpTask.add_description "Export the generated documentation to #{@export_dir} for local usage" end
export()
click to toggle source
# File lib/fubudocs.rb, line 43 def export cmd = "fubudocs export #{@export_dir}" if (@options[:host] != nil) cmd += " --host #{@options[:host]}" end if (@options[:include] != nil) cmd += " -i #{@options[:include]}" end if (@options[:nested] == true) cmd += " -m GhPagesChildFolder" elsif (@options[:dump] == true) cmd += " -m HtmlDump" else cmd += ' -m GhPagesRooted' end sh cmd end
export_tasks()
click to toggle source
# File lib/fubudocs.rb, line 135 def export_tasks initTask = Rake::Task.define_task "#{@prefix}:init_branch" do clean create_branch end initTask.add_description "Initializes the #{@branch} branch in git repository #{@repository}" exportTaskName = "#{@prefix}:export" exportTask = Rake::Task.define_task exportTaskName do clean fetch_existing export commit_new end exportTask.add_description "Export the generated documentation to #{@repository}/#{@branch}" #exportTask.enhance [:compile] return exportTaskName end
fetch_existing()
click to toggle source
# File lib/fubudocs.rb, line 94 def fetch_existing Dir.mkdir @export_dir # fetch the gh-pages branch from the server Dir.chdir @export_dir sh 'git init' sh "git remote add -t #{@branch} -f origin #{@repository}" sh "git checkout #{@branch}" # clean the existing content sleep 0.5 # let the file system try to relax its locks content_files = FileList['*.*'].exclude('.nojekyll').exclude('CNAME') content_files.each do |f| FileUtils.rm_r f end # do the actual export Dir.chdir '..' end
writeNoJekyll()
click to toggle source
# File lib/fubudocs.rb, line 88 def writeNoJekyll output = File.new( ".nojekyll", "w+" ) output << "Just a marker" output.close end