Skip to content

Commit

Permalink
Merge pull request #42 from tamouse/master
Browse files Browse the repository at this point in the history
Add --config global option and blog_slug variable
  • Loading branch information
Pablo Astigarraga committed Apr 11, 2014
2 parents 961d0fa + ad986da commit 1a69fbd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
PATH
remote: .
specs:
planet (0.5.2)
planet (0.5.3)
box
feedzirra
gli
mustache
stringex

GEM
remote: http://rubygems.org/
Expand All @@ -16,7 +17,7 @@ GEM
curb (~> 0.8.1)
loofah (~> 1.2.1)
sax-machine (~> 0.2.1)
gli (2.8.1)
gli (2.9.0)
loofah (1.2.1)
nokogiri (>= 1.4.4)
mini_portile (0.5.2)
Expand All @@ -25,6 +26,7 @@ GEM
mini_portile (~> 0.5.0)
sax-machine (0.2.1)
nokogiri (~> 1.6.0)
stringex (2.1.2)

PLATFORMS
ruby
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ So this is pretty sweet: planet.rb doesn't really want to inject html and random
{{ post_date }} # => "2012-04-14 05:17:00 UTC"
{{ post_content }} # => "I’ve been hurting to write this ever since we had the idea of creating a Planet for Cubox..." (Continued)
{{ blog_name }} # => "This is where I tell you stuff"
{{ blog_slug }} # => "this-is-where-i-tell-you-stuff"
{{ blog_url }} # => "http://blog.poteland.com"
{{ image_url }} # => "http://poteland.com/images/avatars/red_mage.png"
{{ author }} # => "Pablo Astigarraga"
Expand Down
30 changes: 17 additions & 13 deletions bin/planet
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions lib/planet/post.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'stringex_lite'
require 'mustache'

class Planet::Post
Expand Down Expand Up @@ -26,6 +27,7 @@ def to_h
author: self.blog.author,
blog_url: self.blog.url,
blog_name: self.blog.name,
blog_slug: self.blog.name.to_url(:limit => 50, :truncate_words => true),
post_url: self.url,
twitter: self.blog.twitter,
twitter_url: "http://twitter.com/#{ self.blog.twitter }",
Expand Down
2 changes: 1 addition & 1 deletion lib/planet/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Planet
module Version
MAJOR = 0
MINOR = 5
PATCH = 2
PATCH = 3

def self.to_s
[MAJOR, MINOR, PATCH].join('.')
Expand Down
1 change: 1 addition & 0 deletions planet.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ spec = Gem::Specification.new do |s|
s.add_runtime_dependency('feedjira')
s.add_runtime_dependency('mustache')
s.add_runtime_dependency('box')
s.add_runtime_dependency("stringex")
end

0 comments on commit 1a69fbd

Please sign in to comment.