Skip to content
Browse files

adds update_templates command, throws warning on outdated templates (…

…closes #2)
  • Loading branch information...
1 parent 22457f8 commit 67f8ddc4efe38ef2156b256cdec3d896239f26e2 @pote committed Apr 23, 2012
Showing with 65 additions and 43 deletions.
  1. +65 −43 bin/planet
View
108 bin/planet
@@ -5,6 +5,43 @@ require 'planet'
include GLI
+TEMPLATES = {
+ author: '
+<div class="author">
+ <img src="{{ image_url }}" style="width: 96px; height: 96;">
+ <span style="position: absolute; padding: 32px 15px;">
+ <i>Original post by <a href="{{ twitter_url }}">{{ author }}</a> - check out <a href="{{ blog_url }}">{{ blog_name }}</a></i>
+ </span>
+</div>
+',
+ header: '---
+title: "{{ post_title }}"
+kind: article
+created_at: {{ post_date }}
+author: {{ author }}
+layout: post
+---
+',
+ planet: '## Planet.rb default config file, modify it and spawn awesomeness!
+
+planet:
+ posts_directory: source/_posts/
+ templates_directory: source/_layouts/
+
+blogs:
+ # Bare minimum to get it working
+ - author: "Cubox"
+ feed: "http://blog.cuboxlabs.com/atom.xml"
+ image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
+
+ - author: "Pablo Astigarraga"
+ feed: "http://blog.poteland.com/atom.xml"
+ image: "http://poteland.com/images/avatars/red_mage.png"
+ # Other fields:
+ twitter: "poteland"
+ url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field'
+}
+
program_desc 'Planet.rb is an awesome feed-aggregator gem that consumes RSS/Atom feeds and outputs them in a format suitable to use with Octopress or Jekyll'
desc 'Parses planet.yml file for blogs and generates their posts in Jekyll compliant format under the _posts directory'
@@ -38,27 +75,7 @@ command :init do |c|
c.action do |global_options,options,args|
abort 'There is already a planet.yml file present' if File.exist? 'planet.yml'
- default = '## Planet.rb default config file, modify it and spawn awesomeness!
-
-planet:
- posts_directory: source/_posts/
- templates_directory: source/_layouts/
-
-blogs:
- # Bare minimum to get it working
- - author: "Cubox"
- feed: "http://blog.cuboxlabs.com/atom.xml"
- image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
-
- - author: "Pablo Astigarraga"
- feed: "http://blog.poteland.com/atom.xml"
- image: "http://poteland.com/images/avatars/red_mage.png"
- # Other fields:
- twitter: "poteland"
- url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field'
-
-
- File.open('planet.yml', 'w') { |f| f.write(default) }
+ File.open('planet.yml', 'w') { |f| f.write(TEMPLATES[:planet]) }
puts '=> Created default planet.yml'
end
@@ -69,56 +86,61 @@ command :create_templates do |c|
c.action do |global_options,options,args|
conf = YAML.load_file('planet.yml')
- templates_dir = conf.fetch('planet').fetch('templates_directory', '_layouts/')
+ templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
FileUtils.mkdir_p(templates_dir)
- author = '
-<div class="author">
- <img src="{{ image_url }}" style="width: 96px; height: 96;">
- <span style="position: absolute; padding: 32px 15px;">
- <i>Original post by <a href="{{ twitter_url }}">{{ author }}</a> - check out <a href="{{ blog_url }}">{{ blog_name }}</a></i>
- </span>
-</div>
-'
if !File.exists?(templates_dir + 'author.html')
- File.open(templates_dir + 'author.html', 'w') { |f| f.write(author) }
+ File.open(templates_dir + 'author.html', 'w') { |f| f.write(TEMPLATES[:author]) }
puts "=> Created default #{ templates_dir }author.html"
else
puts "=> Template #{ templates_dir }author.html already exists, skipping"
end
- header ='---
-title: "{{ post_title }}"
-kind: article
-created_at: {{ post_date }}
-author: {{ author }}
-layout: post
----
-'
if !File.exists?(templates_dir + 'header.md')
- File.open(templates_dir + 'header.md', 'w') { |f| f.write(header) }
+ File.open(templates_dir + 'header.md', 'w') { |f| f.write(TEMPLATES[:header]) }
puts "=> Created default #{ templates_dir }header.md"
else
puts "=> Template #{ templates_dir }header.md already exists, skipping"
end
end
end
+desc 'Delete existing templates and recreate them'
+command :update_templates do |c|
+ c.action do |global_options,options,args|
+ conf = YAML.load_file('planet.yml')
+
+ templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
+
+ author = templates_dir + 'author.html'
+ header = templates_dir + 'header.md'
+
+
+ File.delete(author) if File.exists?(author)
+ File.delete(header) if File.exists?(header)
+
+ response = `#{ $0 } create_templates`
+ puts response
+ end
+end
+
pre do |global,command,options,args|
if command.name == :generate
conf = YAML.load_file('planet.yml')
templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts')
FileUtils.mkdir_p(templates_dir)
- files = [templates_dir + 'author.html', templates_dir + 'header.md']
+ files = { author: templates_dir + 'author.html', header: templates_dir + 'header.md' }
- files.each do |file|
- unless File.exists?(file)
+ files.each do |name, path|
+ if !File.exists?(path)
puts "=> You are missing some files in your templates directory, planet.rb will create them for you - make sure to review them on #{ templates_dir }!"
response = `#{$0} create_templates`
puts response
+ elsif TEMPLATES[name] != File.read(path)
+ puts "!! WARNING: your planet.rb template files are different from the default, if you haven't made specific changes to them yourself then planet.rb default templates might have changed.Run 'planet update_templates' to override your current files with the newest default file available."
end
end
end

0 comments on commit 67f8ddc

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