4 require 'git-blog/core'
7 desc 'Setup the blog repository'
9 path = File.expand_path '.'
11 # Will create the repo if it doesn't exist
12 until (blog = Git.open path rescue false)
19 cp GitBlog::Scope / :prepped / '.gitignore', '.'
20 %w(welcome_to_your_git_blog.markdown .gitignore).each do |file|
21 cp GitBlog::Scope / :prepped / :posts / file, 'posts'
23 %w(main.css post.haml index.haml).each do |file|
24 cp GitBlog::Scope / :prepped / :design / file, 'design'
27 Dir['**/**'].each do |file|
28 if File.directory? file
35 chmod 0664, '.gitignore'
36 chmod 0664, :posts / '.gitignore'
39 blog.commit_all("A bird... no, a plane... no, a git-blog!")
42 desc 'Attach the blog to a GitHub repository - can also clone an existing git-blog repository here'
43 task :github, :user_name, :repo_name do |_, params|
44 path = File.expand_path '.'
45 user_name = params[:user_name].nil? ? %x(whoami).chomp : params[:user_name]
46 repo_name = params[:repo_name].nil? ? File.basename(path) : params[:repo_name]
50 if File.directory? File.join(path, 'posts') and
51 (blog = Git.open path rescue false)
53 github = blog.add_remote 'github', github_url
57 system "git remote add -f github #{github_url}"
58 system "git checkout -b master github/master"
62 desc 'Prepare the blog to be served (configures hooks)'
64 should_be_initialized File.expand_path('.')
66 mv '.git' / :hooks / 'post-receive', '.git' / :hooks / 'post-receive.old'
67 cp GitBlog::Scope / :prepped / 'post-receive.hook', '.git' / :hooks / 'post-receive'
68 chmod 0775, '.git' / :hooks / 'post-receive'
70 puts '** git-blog is prepared for serving (git post-recieve hook prepared)'
73 desc 'Create and open for editing a new post'
76 temporary_post = :post_in_progress.markdown
78 should_be_initialized File.expand_path('.')
80 if File.file? temporary_post
81 puts '** You have an unfinished post from before,'
82 puts 'do you want to r)esume it or overwrite it with a n)ew one? '
87 # do nothing, go on to overwriting it
89 raise 'Invalid entry, exiting out'
94 File.open temporary_post, File::RDWR|File::TRUNC|File::CREAT, 0664 do |post|
95 post.puts 'Replace this text with your title!'
96 post.puts '=================================='
97 post.print "\n"; post.close