Skip to content
Browse files

rake new asks for the title of the new article

By asking for the title, we don't have to worry about escaping quotes or
other shell-interpolation issues relating to punctuation.  Additionally,
non-word characters are stripped from the title before it is used in the
filename.

Signed-off-by: cloudhead <self@cloudhead.net>
  • Loading branch information...
1 parent 3fbb1b0 commit 15d95de72cb6918b71da11c9555002fb1de9f646 @hyperbolist hyperbolist committed with cloudhead Feb 6, 2010
Showing with 14 additions and 9 deletions.
  1. +14 −9 Rakefile
View
23 Rakefile
@@ -2,18 +2,18 @@ require 'toto'
@config = Toto::Config::Defaults
-desc "Run 'rake new[\"My Article Title\"]' to create a new article."
-task :new, [:title] do |t, args|
- if args.title.nil?
- toto "Please provide an article title with 'rake new[\"My Article Title\"]'"
- exit
- end
- title = args.title.strip.downcase.gsub(/ /, '-')
+task :default => :new
+
+desc "Create a new article."
+task :new do
+ title = ask('Title: ')
+ slug = title.empty?? nil : title.strip.slugize
+
article = {'title' => title, 'date' => Time.now.strftime("%d/%m/%Y"), 'author' => @config[:author]}.to_yaml
article << "\n"
article << "Once upon a time...\n\n"
- path = "#{Toto::Paths[:articles]}/#{Time.now.strftime("%Y-%m-%d")}-#{title}.#{@config[:ext]}"
+ path = "#{Toto::Paths[:articles]}/#{Time.now.strftime("%Y-%m-%d")}#{'-' + slug if slug}.#{@config[:ext]}"
unless File.exist? path
File.open(path, "w") do |file|
@@ -27,11 +27,16 @@ end
desc "Publish my blog."
task :publish do
- toto "publishing your article(s)..."
+ toto "Publishing your article(s)..."
`git push heroku master`
end
def toto msg
puts "\n toto ~ #{msg}\n\n"
end
+def ask message
+ print message
+ STDIN.gets.chomp
+end
+

0 comments on commit 15d95de

Please sign in to comment.
Something went wrong with that request. Please try again.