Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This is now a proper gem

  • Loading branch information...
commit 091b8e30c099915bf8c77997142a1f2cd82304e9 1 parent 27ec544
@pote authored
View
2  Gemfile
@@ -2,6 +2,4 @@ source 'http://rubygems.org'
gemspec
gem 'rake'
-gem 'nokogiri'
gem 'simple-rss'
-gem 'undress'
View
24 Rakefile
@@ -1,11 +1,23 @@
-require './lib/planet'
+require 'rake/clean'
+require 'rubygems'
+require 'rubygems/package_task'
+require 'rdoc/task'
+Rake::RDocTask.new do |rd|
+ rd.main = "README.rdoc"
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
+ rd.title = 'Planet.rb'
+end
-desc 'Instanciate Planet and write posts to _posts directory'
-task :planetize do
- planet = Planet.new
+spec = eval(File.read('planet.gemspec'))
- planet.aggregate
+Gem::PackageTask.new(spec) do |pkg|
+end
- planet.write_posts
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/tc_*.rb']
end
+
+task :default => :test
View
67 bin/planet
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
+# have this method, so we add it so we get resolved symlinks
+# and compatibility
+
+unless File.respond_to? :realpath
+ class File #:nodoc:
+ def self.realpath path
+ return realpath(File.readlink(path)) if symlink?(path)
+ path
+ end
+ end
+end
+$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
+require 'rubygems'
+require 'gli'
+require 'planet'
+require 'ruby-debug'
+
+include GLI
+
+program_desc 'Describe your application here'
+
+version Planet::Version
+
+desc 'Describe generate here'
+arg_name 'Describe arguments to generate here'
+command :generate do |c|
+ c.desc 'Describe a switch to generate'
+ c.switch :s
+
+ c.desc 'Describe a flag to generate'
+ c.default_value 'default'
+ c.flag :f
+ c.action do |global_options,options,args|
+ conf = YAML.load File.open('planet.yml', 'r').read
+
+ @planet = Planet.new
+
+ conf['blogs'].each do |blog|
+ @planet.blogs << Blog.new(
+ blog['feed'],
+ blog['author'],
+ blog['image'],
+ []
+ )
+ end
+
+ @planet.aggregate
+
+ @planet.write_posts
+ end
+end
+
+pre do |global,command,options,args|
+ true
+end
+
+post do |global,command,options,args|
+ true
+end
+
+on_error do |exception|
+ true
+end
+
+exit GLI.run(ARGV)
View
28 lib/planet.rb
@@ -1,19 +1,6 @@
require 'simple-rss'
require 'open-uri'
-BLOGS = [
- {
- feed: 'http://blog.cuboxlabs.com/atom.xml',
- author: 'Cubox',
- image: 'http://cuboxlabs.com/img/cubox-humans/could-be-you.png',
- },
- {
- feed: 'http://feeds.feedburner.com/picandocodigo',
- author: 'Fernando Briano',
- image: 'http://www.gravatar.com/avatar/49c5bd577a2d7ef0628c8ceb90b8c7ae?s=128&d=identicon&r=PG',
- }
-]
-
class Blog < Struct.new(:feed, :author, :image, :posts)
end
@@ -87,25 +74,18 @@ def blogs
end
def aggregate
- BLOGS.each do |blog|
- @@_blogs << @blog = Blog.new(
- blog[:feed],
- blog[:author],
- blog[:image],
- []
- )
-
- rss = SimpleRSS.parse open(@blog.feed)
+ @@_blogs.each do |blog|
+ rss = SimpleRSS.parse open(blog.feed)
rss.entries.each do |entry|
@@_posts << @post = Post.new(
entry.fetch(:title),
entry.fetch(:content).strip,
entry.fetch(:updated, nil), # Yeah, I know, Im following the default octopress value for the date parameter.
entry.fetch(:id, nil), # Er, this is the full link to the article
- @blog
+ blog
)
- @blog.posts << @post
+ blog.posts << @post
end
end
end
View
3  lib/planet_version.rb
@@ -0,0 +1,3 @@
+module Planet
+ VERSION = '0.0.1'
+end
View
26 planet.gemspec
@@ -0,0 +1,26 @@
+require File.join([File.dirname(__FILE__),'lib','planet_version.rb'])
+
+spec = Gem::Specification.new do |s|
+ s.name = 'planet'
+ s.version = Planet::VERSION
+ s.author = 'Pablo Astigarraga'
+ s.email = 'pote@tardis.com.uy'
+ s.homepage = 'poteland.com'
+ s.platform = Gem::Platform::RUBY
+ s.summary = 'An awesome rss/atom feed aggregator designed to work with Octopress/Jekyll'
+ s.files = %w(
+bin/planet
+lib/planet_version.rb
+lib/planet.rb
+ )
+ s.require_paths << 'lib'
+ s.has_rdoc = true
+ s.extra_rdoc_files = ['planet.rdoc']
+ s.rdoc_options << '--title' << 'planet' << '--main' << '-ri'
+ s.bindir = 'bin'
+ s.executables << 'planet'
+ s.add_development_dependency('rake')
+ s.add_development_dependency('rdoc')
+ s.add_runtime_dependency('gli')
+ s.add_runtime_dependency('simple-rss')
+end
View
9 planet.yml
@@ -0,0 +1,9 @@
+blogs:
+ - author: "Cubox"
+ feed: "http://blog.cuboxlabs.com/atom.xml"
+ image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
+
+ - author: "Fernando Briano"
+ feed: "http://blog.cuboxlabs.com/atom.xml"
+ feed: "http://feeds.feedburner.com/picandocodigo"
+ image: "http://www.gravatar.com/avatar/49c5bd577a2d7ef0628c8ceb90b8c7ae?s=128&d=identicon&r=PG"
View
9 planet.yml.sample
@@ -0,0 +1,9 @@
+blogs:
+ - author: "Cubox"
+ feed: "http://blog.cuboxlabs.com/atom.xml"
+ image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
+
+ - author: "Fernando Briano"
+ feed: "http://blog.cuboxlabs.com/atom.xml"
+ feed: "http://feeds.feedburner.com/picandocodigo"
+ image: "http://www.gravatar.com/avatar/49c5bd577a2d7ef0628c8ceb90b8c7ae?s=128&d=identicon&r=PG"
View
0  test/.gitkeep
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.