Skip to content
Browse files

Post generator now includes the author name and email from `~/.gitcon…

…fig` when present.
  • Loading branch information...
1 parent 5d58b01 commit 46255163d0af02402e95d08371b988ddb940f52b @nathanaelkane nathanaelkane committed Jun 11, 2011
View
2 lib/generators/postmarkdown/post_generator.rb
@@ -20,7 +20,7 @@ def check_date
end
def generate_post
- copy_file 'example-post.markdown', "app/posts/#{publish_date}-#{slug.downcase}.markdown"
+ template 'example-post.markdown', "app/posts/#{publish_date}-#{slug.downcase}.markdown"
end
private
View
8 lib/generators/postmarkdown/templates/example-post.markdown
@@ -1,7 +1,11 @@
---
title: Example Post
-author: Joe Bloggs
-email: joebloggs@example.com
+<%- if author = Postmarkdown::Util.git_config('user.name') -%>
+author: <%= author %>
+<%- end -%>
+<%- if email = Postmarkdown::Util.git_config('user.email') -%>
+email: <%= email %>
+<%- end -%>
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
View
1 lib/postmarkdown.rb
@@ -3,5 +3,6 @@ module Postmarkdown
require 'postmarkdown/engine'
require 'postmarkdown/config'
require 'postmarkdown/routes'
+ require 'postmarkdown/util'
end
end
View
8 lib/postmarkdown/util.rb
@@ -0,0 +1,8 @@
+module Postmarkdown
+ module Util
+ def self.git_config(name)
+ value = `git config --get #{name}`.chomp
+ value if $?.success?
+ end
+ end
+end

0 comments on commit 4625516

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