planet 0.3.3 → 0.3.4

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.
Files changed (4) hide show
  1. data/bin/planet +2 -2
  2. data/lib/planet.rb +44 -32
  3. data/lib/planet/version.rb +1 -1
  4. metadata +2 -2
data/bin/planet CHANGED
@@ -73,7 +73,7 @@ end
73
73
 
74
74
  pre do |global,command,options,args|
75
75
  if command.name == :generate
76
- conf = YAML.load File.open('planet.yml', 'r') { |f| f.read }
76
+ conf = YAML.load_file('planet.yml')
77
77
 
78
78
  templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
79
79
  FileUtils.mkdir_p(templates_dir)
@@ -83,7 +83,7 @@ pre do |global,command,options,args|
83
83
  files.each do |file|
84
84
  unless File.exists?(file)
85
85
  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 }!"
86
- response = `planet create_templates`
86
+ response = `#{$0} create_templates`
87
87
  puts response
88
88
  end
89
89
  end
data/lib/planet.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'feedzirra'
2
2
  require 'mustache'
3
3
 
4
- class Planet < Struct.new(:config, :blogs)
4
+ class Planet
5
+
6
+ attr_accessor :config, :blogs
5
7
 
6
8
  def initialize(attributes = {})
7
9
  self.config = attributes[:config]
@@ -15,33 +17,14 @@ class Planet < Struct.new(:config, :blogs)
15
17
  def aggregate
16
18
  self.blogs.each do |blog|
17
19
  puts "=> Parsing #{ blog.feed }"
18
- feed = Feedzirra::Feed.fetch_and_parse(blog.feed)
19
-
20
- blog.name ||= feed.title || 'the source'
21
- blog.url ||= feed.url
22
-
23
- if blog.url.nil?
24
- abort "#{ blog.author }'s blog does not have a url field on it's feed, you will need to specify it on planet.yml"
25
- end
26
-
27
- feed.entries.each do |entry|
28
- blog.posts << @post = Post.new(
29
- title: entry.title.sanitize,
30
- content: blog.sanitize_images(entry.content.strip),
31
- date: entry.published,
32
- url: blog.url + entry.url,
33
- blog: blog
34
- )
35
-
36
- puts "=> Found post titled #{ @post.title } - by #{ @post.blog.author }"
37
- end
20
+ blog.fetch
38
21
  end
39
22
  end
40
23
 
41
24
  def write_posts
42
- posts_dir = self.config.fetch('posts_directory', '_posts')
25
+ posts_dir = self.config.fetch('posts_directory', 'source/_posts/')
43
26
  FileUtils.mkdir_p(posts_dir)
44
- puts "=> Writing #{ self.posts.size } posts to the #{ posts_dir } directory"
27
+ puts "=> Writing #{ self.posts.size } posts to the #{ posts_dir } directory."
45
28
 
46
29
  self.posts.each do |post|
47
30
  file_name = posts_dir + post.file_name
@@ -50,14 +33,17 @@ class Planet < Struct.new(:config, :blogs)
50
33
  end
51
34
  end
52
35
 
53
- class Post < Struct.new(:title, :content, :date, :url, :blog)
36
+ class Post
37
+
38
+ attr_accessor :title, :content, :date, :url, :blog, :author
54
39
 
55
40
  def initialize(attributes = {})
56
- self.title = attributes.fetch(:title, nil)
57
- self.content = attributes.fetch(:content, nil)
58
- self.date = attributes.fetch(:date, nil)
59
- self.url = attributes.fetch(:url, nil)
60
- self.blog = attributes.fetch(:blog, nil)
41
+ self.title = attributes[:title]
42
+ self.content = attributes[:content]
43
+ self.date = attributes[:date]
44
+ self.url = attributes.[:url]
45
+ self.blog = attributes[:blog]
46
+ self.author = attributes[:author]
61
47
  end
62
48
 
63
49
  def to_s
@@ -70,7 +56,7 @@ class Planet < Struct.new(:config, :blogs)
70
56
  post_title: self.title,
71
57
  post_date: self.date,
72
58
  image_url: self.blog.image,
73
- author: self.blog.author,
59
+ author: self.author,
74
60
  blog_url: self.blog.url,
75
61
  blog_name: self.blog.name,
76
62
  post_url: self.url,
@@ -103,7 +89,9 @@ class Planet < Struct.new(:config, :blogs)
103
89
 
104
90
  end
105
91
 
106
- class Blog < Struct.new(:url, :feed, :name, :author, :image, :twitter, :posts, :planet)
92
+ class Blog
93
+
94
+ attr_accessor :url, :feed, :name, :author, :image, :twitter, :posts, :planet
107
95
 
108
96
  def initialize(attributes = {})
109
97
  self.url = attributes[:url]
@@ -112,10 +100,34 @@ class Planet < Struct.new(:config, :blogs)
112
100
  self.author = attributes[:author]
113
101
  self.image = attributes[:image]
114
102
  self.twitter = attributes[:twitter]
115
- self.posts = attributes.fetch('posts', [])
103
+ self.posts = attributes.fetch(:posts, [])
116
104
  self.planet = attributes[:planet]
117
105
  end
118
106
 
107
+ def fetch
108
+ feed = Feedzirra::Feed.fetch_and_parse(self.feed)
109
+
110
+ self.name ||= feed.title || 'the source'
111
+ self.url ||= feed.url
112
+
113
+ if self.url.nil?
114
+ abort "#{ self.author }'s blog does not have a url field on it's feed, you will need to specify it on planet.yml"
115
+ end
116
+
117
+ feed.entries.each do |entry|
118
+ self.posts << @post = Post.new(
119
+ title: entry.title.sanitize,
120
+ author: entry.author ? entry.author : self.author,
121
+ content: self.sanitize_images(entry.content.strip),
122
+ date: entry.published,
123
+ url: self.url + entry.url,
124
+ blog: self
125
+ )
126
+
127
+ puts "=> Found post titled #{ @post.title } - by #{ @post.author }"
128
+ end
129
+ end
130
+
119
131
  def sanitize_images(html)
120
132
  ## We take all images with src not matching http refs and append
121
133
  ## the original blog to them.
@@ -2,7 +2,7 @@ module Planet
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
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.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-21 00:00:00.000000000 Z
12
+ date: 2012-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake