Permalink
Browse files

Merge pull request #42 from tamouse/master

Add --config global option and blog_slug variable
  • Loading branch information...
Pablo Astigarraga
Pablo Astigarraga committed Apr 11, 2014
2 parents 961d0fa + ad986da commit 1a69fbd1a7807a74a4d7f81e4ee6c132d4578369
Showing with 26 additions and 16 deletions.
  1. +4 −2 Gemfile.lock
  2. +1 −0 README.md
  3. +17 −13 bin/planet
  4. +2 −0 lib/planet/post.rb
  5. +1 −1 lib/planet/version.rb
  6. +1 −0 planet.gemspec
View
@@ -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/
@@ -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)
@@ -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
View
@@ -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"
View
@@ -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|
@@ -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] == '.'
@@ -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/')
@@ -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)
@@ -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."
@@ -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
View
@@ -1,3 +1,4 @@
+require 'stringex_lite'
require 'mustache'
class Planet::Post
@@ -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 }",
View
@@ -2,7 +2,7 @@ class Planet
module Version
MAJOR = 0
MINOR = 5
- PATCH = 2
+ PATCH = 3
def self.to_s
[MAJOR, MINOR, PATCH].join('.')
View
@@ -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.