Skip to content

Commit

Permalink
Add global option to set the planet.yml configuration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamouse committed Jan 18, 2014
1 parent 2c75d47 commit f4acfdd
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions bin/planet
Expand Up @@ -10,6 +10,8 @@ include GLI::App

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'

flag [:c,:config], :default_value => 'planet.yml', :desc => "Planet configuration file"

desc 'Parses planet.yml file for blogs and generates their posts in Jekyll compliant format under the _posts directory'
command :generate do |c|

Expand All @@ -21,7 +23,7 @@ due to spacing issues possible with markdown.
}
c.action do |global_options,options,args|

Planet::Importer.import('planet.yml') do |planet|
Planet::Importer.import(global_options[:config]) do |planet|

post_extension = options[:extension] || 'markdown'
post_extension = '.' + post_extension unless post_extension[0] == '.'
Expand All @@ -43,18 +45,17 @@ end
desc 'Creates basic planet.yml config file'
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'

File.open('planet.yml', 'w') { |f| f.write(Box::FILES['planet']) }

puts '=> Created default planet.yml'
abort 'There is already a planet.yml file present' if File.exist?(global_options[:config])
File.open(global_options[:config], 'w') { |f| f.write(Box::FILES['planet']) }
puts "=> Created default #{global_options[:config]}"
end
end

desc 'Creates basic templates on the templates_directory specified in planet.yml'
desc "Creates basic templates on the templates_directory specified in configuration file"
command :create_templates do |c|
c.action do |global_options,options,args|
conf = YAML.load_file('planet.yml')
STDERR.puts "DEBUG: #{caller.first} global_options[:config]=#{global_options[:config].inspect}"
conf = YAML.load_file(global_options[:config])

templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')

Expand Down Expand Up @@ -86,25 +87,24 @@ 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')
conf = YAML.load_file(global_options[:config])

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`
response = `#{$0} -d #{global_options[:config]} create_templates`
puts response
end
end

pre do |global,command,options,args|
if command.name == :generate
conf = YAML.load_file('planet.yml')
conf = YAML.load_file(global[:config])

templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts')
FileUtils.mkdir_p(templates_dir)
Expand All @@ -114,7 +114,9 @@ pre do |global,command,options,args|
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`

response = `#{$0} -c #{global[:config]} create_templates`

puts response
elsif Box::FILES[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."
Expand All @@ -130,6 +132,8 @@ post do |global,command,options,args|
end

on_error do |exception|
STDERR.puts "Error: #{exception} (#{exception.class})"
STDERR.puts exception.backtrace.join("\n")
true
end

Expand Down

0 comments on commit f4acfdd

Please sign in to comment.