Skip to content
This repository was archived by the owner on May 8, 2021. It is now read-only.

Commit 6f7e116

Browse files
committed
Add Rakefile to automatically generate checklist items
1 parent 31d3113 commit 6f7e116

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Rakefile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require "rubygems"
2+
require 'rake'
3+
require 'yaml'
4+
require 'time'
5+
6+
SOURCE = "."
7+
CONFIG = {
8+
'version' => "0.2.13",
9+
'themes' => File.join(SOURCE, "_includes", "themes"),
10+
'layouts' => File.join(SOURCE, "_layouts"),
11+
'posts' => File.join(SOURCE, "_posts"),
12+
'post_ext' => "markdown",
13+
'theme_package_version' => "0.1.0"
14+
}
15+
16+
# Path configuration helper
17+
module JB
18+
class Path
19+
SOURCE = "."
20+
Paths = {
21+
:layouts => "_layouts",
22+
:themes => "_includes/themes",
23+
# :theme_assets => "assets/themes",
24+
# :theme_packages => "_theme_packages",
25+
:posts => "_posts"
26+
}
27+
28+
def self.base
29+
SOURCE
30+
end
31+
32+
# build a path relative to configured path settings.
33+
def self.build(path, opts = {})
34+
opts[:root] ||= SOURCE
35+
path = "#{opts[:root]}/#{Paths[path.to_sym]}/#{opts[:node]}".split("/")
36+
path.compact!
37+
File.__send__ :join, path
38+
end
39+
40+
end #Path
41+
end #JB
42+
43+
# Usage: rake post title="A Title" [date="2012-02-09"] [cat="Category"]
44+
desc "Begin a new post in #{CONFIG['posts']}"
45+
task :post do
46+
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
47+
title = ENV['title'] || "new-post"
48+
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
49+
begin
50+
date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d')
51+
date_time = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d-%H-%M')
52+
rescue Exception => e
53+
puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
54+
exit -1
55+
end
56+
cat = ENV['cat'] || ""
57+
58+
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
59+
if File.exist?(filename)
60+
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
61+
end
62+
63+
puts "Creating new post: #{filename}"
64+
open(filename, 'w') do |post|
65+
post.puts "---"
66+
post.puts "layout: checklist"
67+
post.puts "date: #{date_time}"
68+
post.puts "title: \"#{title.gsub(/-/,' ')}\""
69+
post.puts "category: #{cat}"
70+
post.puts "example: "
71+
post.puts "example_title: "
72+
post.puts "read_more: "
73+
post.puts "read_more_title: "
74+
post.puts "---"
75+
end
76+
end # task :post

0 commit comments

Comments
 (0)