Skip to content

Commit

Permalink
Post generator now includes the author name and email from `~/.gitcon…
Browse files Browse the repository at this point in the history
…fig` when present.
  • Loading branch information
nathanaelkane committed Jun 11, 2011
1 parent 5d58b01 commit 4625516
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/generators/postmarkdown/post_generator.rb
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions 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.
Expand Down
1 change: 1 addition & 0 deletions lib/postmarkdown.rb
Expand Up @@ -3,5 +3,6 @@ module Postmarkdown
require 'postmarkdown/engine'
require 'postmarkdown/config'
require 'postmarkdown/routes'
require 'postmarkdown/util'
end
end
8 changes: 8 additions & 0 deletions 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.