planet 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/planet +75 -19
- data/lib/{planet.rb → planet/planet.rb} +37 -25
- data/lib/{version.rb → planet/version.rb} +2 -2
- metadata +21 -10
data/bin/planet
CHANGED
@@ -1,24 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# have this method, so we add it so we get resolved symlinks
|
4
|
-
# and compatibility
|
5
|
-
|
6
|
-
unless File.respond_to? :realpath
|
7
|
-
class File #:nodoc:
|
8
|
-
def self.realpath path
|
9
|
-
return realpath(File.readlink(path)) if symlink?(path)
|
10
|
-
path
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
2
|
+
|
14
3
|
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
15
4
|
require 'rubygems'
|
16
5
|
require 'gli'
|
17
|
-
require 'planet'
|
6
|
+
require 'planet/planet'
|
18
7
|
|
19
8
|
include GLI
|
20
9
|
|
21
|
-
program_desc '
|
10
|
+
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'
|
22
11
|
|
23
12
|
desc 'Parses planet.yml file for blogs and generates their posts in Jekyll compliant format under the _posts directory'
|
24
13
|
command :generate do |c|
|
@@ -26,14 +15,15 @@ command :generate do |c|
|
|
26
15
|
c.action do |global_options,options,args|
|
27
16
|
conf = YAML.load File.open('planet.yml', 'r').read
|
28
17
|
|
29
|
-
@planet = Planet.new
|
18
|
+
@planet = Planet.new(conf.fetch('planet', {}))
|
30
19
|
|
31
20
|
conf['blogs'].each do |blog|
|
32
21
|
@planet.blogs << Planet::Blog.new(
|
33
22
|
blog['feed'],
|
34
23
|
blog['author'],
|
35
24
|
blog['image'],
|
36
|
-
[]
|
25
|
+
[],
|
26
|
+
@planet
|
37
27
|
)
|
38
28
|
end
|
39
29
|
|
@@ -43,12 +33,18 @@ command :generate do |c|
|
|
43
33
|
end
|
44
34
|
end
|
45
35
|
|
46
|
-
desc 'Creates basic planet.yml file'
|
36
|
+
desc 'Creates basic planet.yml config file'
|
47
37
|
command :init do |c|
|
48
38
|
c.action do |global_options,options,args|
|
49
39
|
raise Exception.new('There is already a planet.yml file present') if File.exist? 'planet.yml'
|
50
40
|
|
51
|
-
default = '
|
41
|
+
default = '## Planet.rb default config file, modify it and spawn awesomeness!
|
42
|
+
|
43
|
+
planet:
|
44
|
+
posts_directory: source/_posts/
|
45
|
+
templates_directory: source/_layouts/
|
46
|
+
|
47
|
+
blogs:
|
52
48
|
- author: "Pablo Astigarraga"
|
53
49
|
feed: "http://blog.poteland.com/atom.xml"
|
54
50
|
image: "http://poteland.com/images/avatars/red_mage.png"
|
@@ -58,11 +54,71 @@ command :init do |c|
|
|
58
54
|
image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"'
|
59
55
|
|
60
56
|
File.open('planet.yml', 'w') { |f| f.write(default) }
|
61
|
-
|
57
|
+
|
58
|
+
puts '=> Created default planet.yml'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'Creates basic templates on the templates_directory specified in planet.yml'
|
63
|
+
command :create_templates do |c|
|
64
|
+
c.action do |global_options,options,args|
|
65
|
+
conf = YAML.load File.open('planet.yml', 'r').read
|
66
|
+
|
67
|
+
templates_dir = conf.fetch('planet').fetch('templates_directory', '_layouts/')
|
68
|
+
|
69
|
+
Dir.mkdir(templates_dir) unless File.exists?(templates_dir)
|
70
|
+
|
71
|
+
author = '<div class="author">
|
72
|
+
<img src="{{ image }}" style="width: 48px; height: 48px;">
|
73
|
+
<span style="position: absolute; padding: 12px;">
|
74
|
+
<i>Original post by {{ author }} - <a href="{{ link }}">read it from the source</a></i>
|
75
|
+
</span>
|
76
|
+
</div>
|
77
|
+
'
|
78
|
+
if !File.exists?(templates_dir + 'author.html')
|
79
|
+
File.open(templates_dir + 'author.html', 'w') { |f| f.write(author) }
|
80
|
+
puts "=> Created default #{ templates_dir }author.html"
|
81
|
+
else
|
82
|
+
puts "=> Template #{ templates_dir }author.html already exists, skipping"
|
83
|
+
end
|
84
|
+
|
85
|
+
header ='---
|
86
|
+
title: "{{ title }}"
|
87
|
+
kind: article
|
88
|
+
created_at: {{ date }}
|
89
|
+
author: {{ author }}
|
90
|
+
layout: post
|
91
|
+
---
|
92
|
+
'
|
93
|
+
if !File.exists?(templates_dir + 'header.md')
|
94
|
+
File.open(templates_dir + 'header.md', 'w') { |f| f.write(header) }
|
95
|
+
puts "=> Created default #{ templates_dir }header.md"
|
96
|
+
else
|
97
|
+
puts "=> Template #{ templates_dir }header.md already exists, skipping"
|
98
|
+
end
|
62
99
|
end
|
63
100
|
end
|
64
101
|
|
65
102
|
pre do |global,command,options,args|
|
103
|
+
if command.name == :generate
|
104
|
+
conf = YAML.load File.open('planet.yml', 'r').read
|
105
|
+
|
106
|
+
templates_dir = conf.fetch('planet').fetch('templates_directory', '_layout')
|
107
|
+
|
108
|
+
## I probably shouldn't do this, but I want the default setup to be simple and smooth.
|
109
|
+
Dir.mkdir('source') if templates_dir.split('/').first == 'source' && !File.exists?('source')
|
110
|
+
|
111
|
+
FILES = [templates_dir, templates_dir + 'author.html', templates_dir + 'header.md']
|
112
|
+
|
113
|
+
FILES.each do |file|
|
114
|
+
unless File.exists?(file)
|
115
|
+
puts "=> Your are missing some files in your templates directory, planet.rb will create them for you - make sure to review them on #{ templates_dir }!"
|
116
|
+
response = `planet create_templates`
|
117
|
+
puts response
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
66
122
|
true
|
67
123
|
end
|
68
124
|
|
@@ -1,11 +1,22 @@
|
|
1
1
|
require 'simple-rss'
|
2
2
|
require 'open-uri'
|
3
|
+
require 'mustache'
|
3
4
|
|
4
5
|
class Planet
|
5
6
|
|
6
|
-
def initialize
|
7
|
+
def initialize(config = {})
|
7
8
|
@@_posts = []
|
8
9
|
@@_blogs = []
|
10
|
+
|
11
|
+
@@_config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
@@_config
|
16
|
+
end
|
17
|
+
|
18
|
+
def blogs
|
19
|
+
@@_blogs
|
9
20
|
end
|
10
21
|
|
11
22
|
def posts(options = {})
|
@@ -35,10 +46,6 @@ class Planet
|
|
35
46
|
filtered_posts
|
36
47
|
end
|
37
48
|
|
38
|
-
def blogs
|
39
|
-
@@_blogs
|
40
|
-
end
|
41
|
-
|
42
49
|
def aggregate
|
43
50
|
@@_blogs.each do |blog|
|
44
51
|
puts "=> parsing #{ blog.feed }"
|
@@ -59,11 +66,12 @@ class Planet
|
|
59
66
|
end
|
60
67
|
|
61
68
|
def write_posts
|
62
|
-
|
63
|
-
|
69
|
+
posts_dir = @@_config.fetch('posts_directory', '_posts')
|
70
|
+
Dir.mkdir(posts_dir) unless File.directory?(posts_dir)
|
71
|
+
puts "=> Writing #{ posts.size } posts to the #{ posts_dir } directory"
|
64
72
|
|
65
73
|
posts(filter: {date: true, order: :date}).each do |post|
|
66
|
-
file_name =
|
74
|
+
file_name = posts_dir + post.file_name
|
67
75
|
|
68
76
|
File.open(file_name + '.markdown', "w+") { |f| f.write(post.to_s) }
|
69
77
|
end
|
@@ -83,14 +91,16 @@ class Planet
|
|
83
91
|
|
84
92
|
def header
|
85
93
|
## TODO: We need categories/tags
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'header.md'
|
95
|
+
file_contents = File.open(file, 'r').read
|
96
|
+
|
97
|
+
data = {
|
98
|
+
title: self.title,
|
99
|
+
date: self.date,
|
100
|
+
author: self.blog.author
|
101
|
+
}
|
102
|
+
|
103
|
+
Mustache.render(file_contents, data)
|
94
104
|
end
|
95
105
|
|
96
106
|
def file_name
|
@@ -101,14 +111,16 @@ layout: post
|
|
101
111
|
end
|
102
112
|
|
103
113
|
def footer
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
114
|
+
file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'author.html'
|
115
|
+
file_contents = File.open(file, 'r').read
|
116
|
+
|
117
|
+
data = {
|
118
|
+
image: self.blog.image,
|
119
|
+
author: self.blog.author,
|
120
|
+
link: self.link
|
121
|
+
}
|
122
|
+
|
123
|
+
Mustache.render(file_contents, data)
|
112
124
|
end
|
113
125
|
|
114
126
|
def to_s
|
@@ -116,6 +128,6 @@ layout: post
|
|
116
128
|
end
|
117
129
|
end
|
118
130
|
|
119
|
-
class Blog < Struct.new(:feed, :author, :image, :posts)
|
131
|
+
class Blog < Struct.new(:feed, :author, :image, :posts, :planet)
|
120
132
|
end
|
121
133
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: planet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152594280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152594280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: gli
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152593340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152593340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: simple-rss
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152592460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152592460
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mustache
|
49
|
+
requirement: &2152591640 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152591640
|
47
58
|
description:
|
48
59
|
email: pote@tardis.com.uy
|
49
60
|
executables:
|
@@ -52,8 +63,8 @@ extensions: []
|
|
52
63
|
extra_rdoc_files: []
|
53
64
|
files:
|
54
65
|
- bin/planet
|
55
|
-
- lib/version.rb
|
56
|
-
- lib/planet.rb
|
66
|
+
- lib/planet/version.rb
|
67
|
+
- lib/planet/planet.rb
|
57
68
|
homepage: http://poteland.com
|
58
69
|
licenses: []
|
59
70
|
post_install_message:
|