Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 207cc2e0a8
Fetching contributors…

Cannot retrieve contributors at this time

file 28 lines (23 sloc) 0.7 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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
Something went wrong with that request. Please try again.