Module: Wordsmith::Publish
- Included in:
- Wordsmith
- Defined in:
- lib/wordsmith/publish.rb
Instance Method Summary collapse
-
#publish(args = []) ⇒ Object
publish html book to github project page.
Instance Method Details
#publish(args = []) ⇒ Object
publish html book to github project page
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wordsmith/publish.rb', line 5 def publish(args = []) = args.first @git = Git.open(local('.')) if =~ /\.git/ && !@git.remotes.map(&:to_s).include?('origin') @git.add_remote 'origin', info "Added remote origin #{}" elsif !@git.remotes.map(&:to_s).include?('origin') raise "You must add a remote origin.\ne.g: wordsmith publish [email protected]:jassa/wordsmith-example.git" end if @git.current_branch != 'master' begin @git.checkout 'master' info "Switched to branch 'master'" rescue raise "You must be in the 'master' branch to publish" end end html_dir = File.join('final', @name) unless File.exists?(File.join(html_dir, 'index.html')) raise "Exiting.. Nothing to publish.\nHave you run 'wordsmith generate'?" end # http://pages.github.com/#project_pages `git symbolic-ref HEAD refs/heads/gh-pages` info "Switched to branch 'gh-pages'" `rm .git/index` `git clean -fdx` info "Removed files" `git checkout master #{html_dir}` info "Copied files from 'master' #{html_dir}" `mv #{html_dir}/* ./` `rm -r final/` `git add .` `git rm -r final/*` begin @git.commit 'updating project page' info "git commit -m 'updating project page'" rescue Exception => e if e.to_s =~ /nothing to commit/ raise 'Already up to date. Nothing to commit.' else raise e end end @git.push 'origin', 'gh-pages' info "git push origin gh-pages" @git.checkout 'master' rescue Exception => e @git.checkout 'master' rescue nil raise e end |