summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
authorJade Dominguez <plusjade@gmail.com>2012-01-18 15:35:10 -0800
committerJade Dominguez <plusjade@gmail.com>2012-01-18 15:54:34 -0800
commit9d7d4eb4f946a895ee79219813355af86a17c120 (patch)
tree1aa523be874aa602280548f88491a077e5708c6e /Rakefile
parent246e91a7493a2eb9e79fb6ed552ce4b7b1c633ae (diff)
reorganize rakefile
Namely standardized some logic and put config variables in hash
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile61
1 files changed, 31 insertions, 30 deletions
diff --git a/Rakefile b/Rakefile
index 826e7bc..f55c099 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,61 +1,48 @@
require "rubygems"
require 'rake'
-## -- Misc Configs --##
-jekyll_dir = "."
-posts_dir = "_posts"
-new_post_ext = "md"
+SOURCE = "."
+CONFIG = {
+ 'themes' => File.join(SOURCE, "_includes", "themes"),
+ 'layouts' => File.join(SOURCE, "_layouts"),
+ 'posts' => File.join(SOURCE, "_posts"),
+ 'post_ext' => "md"
+}
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
-desc "Begin a new post in #{jekyll_dir}/#{posts_dir}"
+desc "Begin a new post in #{CONFIG['posts']}"
task :new_post, :title do |t, args|
- raise "### Cannot locate the #{posts_dir}." unless File.directory?(posts_dir)
- mkdir_p "#{jekyll_dir}/#{posts_dir}"
+ abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
args.with_defaults(:title => 'new-post')
slug = args.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
- title = args.title.gsub(/-/,' ')
- filename = "#{jekyll_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{new_post_ext}"
+ filename = File.join(CONFIG['posts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{CONFIG['post_ext']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
+
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
- post.puts "title: \"#{title}\""
+ post.puts "title: \"#{args.title.gsub(/-/,' ')}\""
post.puts "comments: true"
post.puts "category: "
post.puts "tags: []"
post.puts "---"
end
-end
-
-def ask(message, valid_options)
- if valid_options
- answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
- else
- answer = get_stdin(message)
- end
- answer
-end
-
-def get_stdin(message)
- print message
- STDIN.gets.chomp
-end
+end # task :new_post
desc "Switch between Jekyll-bootstrap themes."
task :switch_theme, :theme do |t, args|
- theme_path = File.join(File.dirname(__FILE__), "_includes", "themes", args.theme)
- layouts_path = File.join(File.dirname(__FILE__), "_layouts")
+ theme_path = File.join(CONFIG['themes'], args.theme)
- abort("rake aborted: './_includes/themes/#{args.theme}' directory not found.") unless FileTest.directory?(theme_path)
- abort("rake aborted: './_layouts' directory not found.") unless FileTest.directory?(layouts_path)
+ abort("rake aborted: '#{CONFIG['themes']}/#{args.theme}' directory not found.") unless FileTest.directory?(theme_path)
+ abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts'])
Dir.glob("#{theme_path}/*") do |filename|
puts "Generating '#{args.theme}' layout: #{File.basename(filename)}"
- open("#{layouts_path}/#{File.basename(filename)}", 'w') do |page|
+ open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page|
if File.basename(filename, ".html").downcase == "default"
page.puts "---"
page.puts "---"
@@ -73,4 +60,18 @@ end # task :switch_theme
desc "Launch preview environment"
task :preview do
system "jekyll --auto --server"
+end # task :preview
+
+def ask(message, valid_options)
+ if valid_options
+ answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
+ else
+ answer = get_stdin(message)
+ end
+ answer
end
+
+def get_stdin(message)
+ print message
+ STDIN.gets.chomp
+end \ No newline at end of file