Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Accept an argument and override post importing.

* Creates a PostImporter class responsible of saving the parsed posts
* Modifies the executable to read the argument and override the importer
  • Loading branch information...
commit 3f34b809726776e8e12fdaa4d8d261751a455a85 1 parent 585fdc6
@banafederico banafederico authored
Showing with 32 additions and 9 deletions.
  1. +15 −0 bin/planet
  2. +2 −9 lib/planet.rb
  3. +15 −0 lib/planet/importer.rb
View
15 bin/planet
@@ -58,6 +58,21 @@ command :generate do |c|
@planet.aggregate
+ # Take the first argument as the path
+ # for a ruby file in order to change
+ # the way the posts are imported.
+ # Use on your own risk.
+ unless args[0].blank?
+ unless File.exist? args[0]
+ abort "The file you specified does not exist: #{args[0]}"
+ else
+ require args[0]
+ puts '=> ** NOTICE **: Running custom PostImporter'
+ end
+ else
+ puts '=> Running default PostImporter'
+ end
+
@planet.write_posts
end
end
View
11 lib/planet.rb
@@ -1,5 +1,6 @@
require 'planet/version'
require 'planet/blog'
+require 'planet/importer'
class Planet
@@ -32,14 +33,6 @@ def aggregate
end
def write_posts
- posts_dir = self.config.fetch('posts_directory', 'source/_posts/')
- FileUtils.mkdir_p(posts_dir)
- puts "=> Writing #{ self.posts.size } posts to the #{ posts_dir } directory."
-
- self.posts.each do |post|
- file_name = posts_dir + post.file_name
-
- File.open(file_name + '.markdown', "w+") { |f| f.write(post.to_s) }
- end
+ PostImporter.import(self)
end
end
View
15 lib/planet/importer.rb
@@ -0,0 +1,15 @@
+class PostImporter
+
+ def self.import(planet)
+ posts_dir = planet.config.fetch('posts_directory', 'source/_posts/')
+ FileUtils.mkdir_p(posts_dir)
+ puts "=> Writing #{ planet.posts.size } posts to the #{ posts_dir } directory."
+
+ planet.posts.each do |post|
+ file_name = posts_dir + post.file_name
+
+ File.open(file_name + '.markdown', "w+") { |f| f.write(post.to_s) }
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.