Skip to content

Instantly share code, notes, and snippets.

@opattison
Last active December 21, 2015 13:59
Show Gist options
  • Save opattison/6316368 to your computer and use it in GitHub Desktop.
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.
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