Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (23 sloc) 0.7 kB
require "fileutils"
class Blog < Thor
TEMPLATE = (<<-TEXT).gsub(/^ +/, '')
---
layout: post
title: TITLE
author: YOUR NAME
author_url: http://sinatra.github.com/
publish_date: #{Time.now.strftime('%A, %B %d, %Y')}
---
POST CONTENT HERE
TEXT
desc "new", "Create a new blog post and open in EDITOR"
def new(title=nil)
abort("usage: thor blog:new 'Post Title'") if title.nil?
post = TEMPLATE.sub('TITLE', title)
date = Time.now.strftime('%Y-%m-%d')
file = "_posts/#{date}-#{title.downcase.gsub(/[!.,;:+=-]/, '').gsub(/\W+/, '-')}.markdown"
File.open(file, 'wb') { |f| f.write(post) }
system "$EDITOR #{file}"
end
end
# vim: ft=ruby
Jump to Line
Something went wrong with that request. Please try again.