Skip to content

Instantly share code, notes, and snippets.

@killme2008
Last active May 15, 2017 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killme2008/274758b79b72fd6b1e1ff6af487e2c7d to your computer and use it in GitHub Desktop.
Save killme2008/274758b79b72fd6b1e1ff6af487e2c7d to your computer and use it in GitHub Desktop.
周报 Rake task
# coding: utf-8
# Description: 用于生成周报模板
## 将本文件保存为 Rakefile,放在存放周报的目录。
## 在周报目录创建一个名为 .title 的文件,设置标题,例如 『存储与网站工作周报』,用于设置标题,如果没有提供,默认为『工作周报』。
## 命令:
## rake new -- 创建周报
## rake clean -- 删除周报
task default: %w[new]
def file_name
"./#{Time.now.strftime "%Y%m%d"}.md"
end
def title
date = Time.now.strftime "%Y-%m-%d"
if File.exists? "./.title"
"#{date} #{File.read './.title'}"
else
"#{date} 工作周报"
end
end
task :new, [:title] do |t, args|
args.with_defaults(:title => title)
if File.exists?(file_name)
puts "File '#{file_name}' already exists, please execute 'rake clean' to to delete it."
exit 1
end
File.open(file_name,"w") do |f|
f.puts <<-EOF
# #{args[:title]}
## 上周工作总结
### 上周新功能
### 上周 bug 修复
## 本周工作计划
### 本周新功能
### 本周 bug 修复
Created by [Rake](https://gist.github.com/killme2008/274758b79b72fd6b1e1ff6af487e2c7d).
EOF
end
puts "#{file_name} created!"
system "open #{file_name}"
end
task :clean do
File.delete file_name if File.exists? file_name
puts "#{file_name} deleted!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment