class GitBlog::Workflow

Public Instance Methods

need_setup?() click to toggle source

Test if config is setup

   # File lib/git-blog/workflow.rb
54 def need_setup?
55         !File.file?(GitBlog::Storage.config_path) ||
56         !File.file?(GitBlog::Storage.prepare_commit_msg_template_path) ||
57         !File.file?(GitBlog::Storage.commit_msg_script_path)
58 end
setup() click to toggle source

Setup basic configuration

   # File lib/git-blog/workflow.rb
28 def setup
29         conf = GitBlog::Configuration.new
30         print "Path to blog: "
31         $stdin.flush
32         conf.blog_path = File.expand_path $stdin.gets.chomp
33         conf.write
34 
35         # Also, create the hook files
36         current_path = File.expand_path(File.dirname(__FILE__))
37         hook_path = File.join current_path, "hooks"
38         source_template_path = File.join hook_path, "prepare-commit-msg"
39         target_template_path = GitBlog::Storage.prepare_commit_msg_template_path
40         if !File.file? target_template_path
41                 FileUtils.cp source_template_path, target_template_path
42                 FileUtils.chmod 0755, target_template_path
43         end
44 
45         source_commit_script_path = File.join hook_path, "commit-msg"
46         target_commit_script_path = GitBlog::Storage.commit_msg_script_path
47         if !File.file? target_commit_script_path
48                 FileUtils.cp source_commit_script_path, target_commit_script_path
49                 FileUtils.chmod 0755, target_commit_script_path
50         end
51 end
start_blogging(cli_params) click to toggle source

Do the job

    # File lib/git-blog/workflow.rb
 61                 def start_blogging cli_params
 62                         current_path = Dir.pwd
 63 
 64                         if !current_path.repo?
 65                                 puts "Error: please run git-blog inside a git repo."
 66                                 return
 67                         end
 68 
 69                         if need_setup?
 70                                 puts "Haven't setup git-repo, setting up now"
 71                                 setup
 72                         end
 73 
 74                         git_root_path = %x(git rev-parse --show-toplevel).strip
 75                         hooks_path = File.join git_root_path, ".git", "hooks"
 76                         source_template_path = GitBlog::Storage.prepare_commit_msg_template_path
 77 
 78                         script = <<EOF
 79 #!/usr/bin/env ruby
 80 
 81 $commit_file_path = ARGV[0]
 82 
 83 content = <<EOC
 84 #{File.read(source_template_path)}
 85 EOC
 86 
 87 File.write($commit_file_path, content)
 88 EOF
 89 
 90                         target_template_path = File.join hooks_path, "prepare-commit-msg"
 91                         File.open(target_template_path, "w") { |file| file.write script }
 92                         FileUtils.chmod 0755, target_template_path
 93 
 94                         source_commit_script_path = GitBlog::Storage.commit_msg_script_path
 95                         target_commit_script_path = File.join hooks_path, "commit-msg"
 96                         FileUtils.cp source_commit_script_path, target_commit_script_path
 97                         FileUtils.chmod 0755, target_commit_script_path
 98 
 99                         # Pass to git commit
100                         system("git commit #{cli_params.join(" ")}")
101 
102                         # Clean up
103                         FileUtils.rm target_template_path
104                         FileUtils.rm target_commit_script_path
105                 end