Last active
December 21, 2015 13:59
-
-
Save opattison/6316368 to your computer and use it in GitHub Desktop.
A simple "notes" Rakefile based on the Octopress default Rakefile. I created this for a notes project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'stringex' | |
# rake command that generates a new post and opens in default text editor | |
desc "Generates a new note" | |
task :post, :title do |t, name| | |
if name.title | |
title = name.title | |
else | |
title = get_stdin("Enter a title: ") | |
end | |
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.md" | |
open(filename, 'w') do |post| | |
post.puts "---" | |
post.puts "layout: note" | |
post.puts "title: \'#{title.gsub(/&/,'&')}\'" | |
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}" | |
post.puts "---" | |
end | |
puts "Created new post: #{filename}" | |
system "open #{filename}" | |
end | |
# --- | |
# helper function | |
# --- | |
def get_stdin(message) | |
print message | |
STDIN.gets.chomp | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment