Dat workflow

22 November 2013 Tagged with: rake, ruby, automation, and profanities

An interesting look through my jekyll workflow of creating a new entry ala Thug Kitchen

Creating a new post? Lets gather what we will need before we even put pen hand to keyboard:

  • today’s date
  • post title
  • YAML properties
  • awkward as fuck file name

Ain’t nobody got time for that.

rake post

task :post do
  post__name =  ask "New post title:"
  template(post__name)
  # ...
end

This fucker is so minimal he don’t even need arguments. post__name comes up in this handy ass prompt. Simple as shit command line input, hells yeah. Quicker than you can hit ‘enter’, template(post__name) has already been called to drop some efficiency on your punk ass.

template(post__name)

def template(post__name)
  date = Time.new.strftime('%Y-%m-%d')
  extension = "md"
  dir = "_posts/"
  fileName = post__name.downcase.gsub( /[^a-zA-Z0-9_\.]/, '-')
  newFile = dir + date + "-#{fileName}." + extension

  if File.exists? newFile then
    puts "#{newFile} already exists. cheese it!"
    return
  end
  #...

Creating files like a fucking bawse. He takes your post__name, drops a fucking downcase on him while making it a valid web address1. Multi-talented shit right there. Don’t even worry about making the same post twice, this crafty fucker has your back.

  #...
  File.open(newFile, "wb") do |post|
    post.puts("---")
    post.puts("layout : default")
    post.puts("title: #{post__name}")
    post.puts("excerpt : !required")
    post.puts("comments : true")
    post.puts("---")
    post.puts("!required intro text")
    post.puts("<!-- /intro -->")
    post.puts("\n!required content")
  end
end

Whoa, where are you going? Shit hasn’t even started to get real. Mother effing boilerplate is what’s going on here. Son this function lives for that shit. Gets some scaffolding all up your face, ready for some mad blogging to go down.

Better find that file and open your text editor. Wat, hells no! Back the fuck up now. sh "subl -w #{newFile}:10" opens sublime with your newly created post in a flash. You’re fucking welcome. Write the shit out of that post, save and close. BAM! Instantly back in the terminal. Hardcore shit right there if you ask me.

Back to rake post

#...
isRunSite = ask "Run site too? (y/n):"
if isRunSite.downcase == "y" then
  Rake::Task["local"].execute
end

All this and we are only up to the third line of :post. This son of a bitch has one more card to play. Another terminal prompt, answer with a mother fucking yes and your wish of more automation shall be granted. rake local steps in to build the site for your lazy ass. Evens open the damn browser for you. Respect.

An entire post created by simply runing one rake post2

Efficient. As. Fuck.

  1. Literally pulled from David Lynch’s work

  2. The rake file can be seen in full on the githubs

Recent posts are recent

  1. Oct 28 2014
    This is !normal
    It took over a year and a lot of help from some close friends to realise that my job was making me unhappy.
  2. Feb 16 2014
    New feature - Coderay
    After some behind-the-scenes drama, syntax highlighting is finnaly running!
  3. Feb 13 2014
    jQuery conventions
    Javascript (read: jQuery) was something I struggled with in my early days as it can be quite intimidating at times. Here are some of the techniques I have picked up over the years.