Skip to content
Browse files

Added new-post option which creates a new post with the current date

  • Loading branch information...
1 parent 313f58e commit 7d7c0df087a8bfdef3bea485de5677d2899dac96 @owengriffin committed Jun 1, 2010
Showing with 32 additions and 1 deletion.
  1. +10 −1 bin/who-needs-wp
  2. +22 −0 lib/who-needs-wp.rb
View
11 bin/who-needs-wp
@@ -98,6 +98,11 @@ Choice.options do
desc 'The domain and path hosting the the Piwick used to track website statistics. This should be a URL excluding "http://" and "https//". E.g. "piwik.domain.com/"'
end
+ option :new_post do
+ long '--new-post'
+ desc 'Create a new post for today\'s date.'
+ end
+
option :help do
long '--help'
desc 'Show this message'
@@ -118,4 +123,8 @@ end
Choice.choices.each do |key, value|
options[key.to_sym] = value
end
-WhoNeedsWP::generate(options)
+if options[:new_post]
+ WhoNeedsWP::new_post(options[:new_post])
+else
+ WhoNeedsWP::generate(options)
+end
View
22 lib/who-needs-wp.rb
@@ -33,6 +33,28 @@ module WhoNeedsWP
# Logger
@logger = Logger.new(STDOUT)
+
+ def self.new_post(title)
+ safe_title = title.gsub(/ /, '_')
+ now = Time.new
+ dir = "posts/#{now.strftime('%Y/%m/%d')}"
+ filename = "#{dir}/#{safe_title}.markdown"
+
+ count = 0
+ splits = dir.split('/')
+ splits.each do |d|
+ path = splits[0..count].join('/')
+ if not File.exists? path
+ @logger.debug "Creating: #{path}"
+ Dir.mkdir path
+ end
+ count = count + 1
+ end
+
+ File.new(filename, "w")
+ @logger.info("Created file #{filename}")
+ end
+
# Generate the site with the specified options
def self.generate(options)
@options = options

0 comments on commit 7d7c0df

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