class Postmarkdown::PostGenerator
Public Instance Methods
check_date()
click to toggle source
# File lib/generators/postmarkdown/post_generator.rb, line 15 def check_date if options.date && options.date !~ /^#{Post::DATE_FORMAT}$/ puts 'Invalid date - please use the following format: YYYY-MM-DD, eg. 2011-01-01.' exit end end
check_slug()
click to toggle source
# File lib/generators/postmarkdown/post_generator.rb, line 8 def check_slug unless slug =~ /^#{Post::SLUG_FORMAT}$/ puts 'Invalid slug - valid characters include letters, digits and dashes.' exit end end
generate_post()
click to toggle source
# File lib/generators/postmarkdown/post_generator.rb, line 22 def generate_post template 'example-post.markdown', "app/posts/#{publish_date}-#{slug.downcase}.markdown" end
Private Instance Methods
publish_date()
click to toggle source
# File lib/generators/postmarkdown/post_generator.rb, line 28 def publish_date format = '%Y-%m-%d-%H%M%S' if options.date.present? date_string = options.date date_string += '-000000' unless options.date.match(/(#{Post::TIME_FORMAT}$)/) date = Time.strptime(date_string, format) else date = Time.zone.now end date.strftime(format) end