planet 0.3.8 → 0.3.9

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 (3) hide show
  1. data/bin/planet +65 -43
  2. data/lib/planet/version.rb +1 -1
  3. metadata +2 -2
data/bin/planet CHANGED
@@ -5,6 +5,43 @@ require 'planet'
5
5
 
6
6
  include GLI
7
7
 
8
+ TEMPLATES = {
9
+ author: '
10
+ <div class="author">
11
+ <img src="{{ image_url }}" style="width: 96px; height: 96;">
12
+ <span style="position: absolute; padding: 32px 15px;">
13
+ <i>Original post by <a href="{{ twitter_url }}">{{ author }}</a> - check out <a href="{{ blog_url }}">{{ blog_name }}</a></i>
14
+ </span>
15
+ </div>
16
+ ',
17
+ header: '---
18
+ title: "{{ post_title }}"
19
+ kind: article
20
+ created_at: {{ post_date }}
21
+ author: {{ author }}
22
+ layout: post
23
+ ---
24
+ ',
25
+ planet: '## Planet.rb default config file, modify it and spawn awesomeness!
26
+
27
+ planet:
28
+ posts_directory: source/_posts/
29
+ templates_directory: source/_layouts/
30
+
31
+ blogs:
32
+ # Bare minimum to get it working
33
+ - author: "Cubox"
34
+ feed: "http://blog.cuboxlabs.com/atom.xml"
35
+ image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
36
+
37
+ - author: "Pablo Astigarraga"
38
+ feed: "http://blog.poteland.com/atom.xml"
39
+ image: "http://poteland.com/images/avatars/red_mage.png"
40
+ # Other fields:
41
+ twitter: "poteland"
42
+ url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field'
43
+ }
44
+
8
45
  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'
9
46
 
10
47
  desc 'Parses planet.yml file for blogs and generates their posts in Jekyll compliant format under the _posts directory'
@@ -38,27 +75,7 @@ command :init do |c|
38
75
  c.action do |global_options,options,args|
39
76
  abort 'There is already a planet.yml file present' if File.exist? 'planet.yml'
40
77
 
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:
48
- # Bare minimum to get it working
49
- - author: "Cubox"
50
- feed: "http://blog.cuboxlabs.com/atom.xml"
51
- image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
52
-
53
- - author: "Pablo Astigarraga"
54
- feed: "http://blog.poteland.com/atom.xml"
55
- image: "http://poteland.com/images/avatars/red_mage.png"
56
- # Other fields:
57
- twitter: "poteland"
58
- url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field'
59
-
60
-
61
- File.open('planet.yml', 'w') { |f| f.write(default) }
78
+ File.open('planet.yml', 'w') { |f| f.write(TEMPLATES[:planet]) }
62
79
 
63
80
  puts '=> Created default planet.yml'
64
81
  end
@@ -69,35 +86,19 @@ command :create_templates do |c|
69
86
  c.action do |global_options,options,args|
70
87
  conf = YAML.load_file('planet.yml')
71
88
 
72
- templates_dir = conf.fetch('planet').fetch('templates_directory', '_layouts/')
89
+ templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
73
90
 
74
91
  FileUtils.mkdir_p(templates_dir)
75
92
 
76
- author = '
77
- <div class="author">
78
- <img src="{{ image_url }}" style="width: 96px; height: 96;">
79
- <span style="position: absolute; padding: 32px 15px;">
80
- <i>Original post by <a href="{{ twitter_url }}">{{ author }}</a> - check out <a href="{{ blog_url }}">{{ blog_name }}</a></i>
81
- </span>
82
- </div>
83
- '
84
93
  if !File.exists?(templates_dir + 'author.html')
85
- File.open(templates_dir + 'author.html', 'w') { |f| f.write(author) }
94
+ File.open(templates_dir + 'author.html', 'w') { |f| f.write(TEMPLATES[:author]) }
86
95
  puts "=> Created default #{ templates_dir }author.html"
87
96
  else
88
97
  puts "=> Template #{ templates_dir }author.html already exists, skipping"
89
98
  end
90
99
 
91
- header ='---
92
- title: "{{ post_title }}"
93
- kind: article
94
- created_at: {{ post_date }}
95
- author: {{ author }}
96
- layout: post
97
- ---
98
- '
99
100
  if !File.exists?(templates_dir + 'header.md')
100
- File.open(templates_dir + 'header.md', 'w') { |f| f.write(header) }
101
+ File.open(templates_dir + 'header.md', 'w') { |f| f.write(TEMPLATES[:header]) }
101
102
  puts "=> Created default #{ templates_dir }header.md"
102
103
  else
103
104
  puts "=> Template #{ templates_dir }header.md already exists, skipping"
@@ -105,6 +106,25 @@ layout: post
105
106
  end
106
107
  end
107
108
 
109
+ desc 'Delete existing templates and recreate them'
110
+ command :update_templates do |c|
111
+ c.action do |global_options,options,args|
112
+ conf = YAML.load_file('planet.yml')
113
+
114
+ templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
115
+
116
+ author = templates_dir + 'author.html'
117
+ header = templates_dir + 'header.md'
118
+
119
+
120
+ File.delete(author) if File.exists?(author)
121
+ File.delete(header) if File.exists?(header)
122
+
123
+ response = `#{ $0 } create_templates`
124
+ puts response
125
+ end
126
+ end
127
+
108
128
  pre do |global,command,options,args|
109
129
  if command.name == :generate
110
130
  conf = YAML.load_file('planet.yml')
@@ -112,13 +132,15 @@ pre do |global,command,options,args|
112
132
  templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts')
113
133
  FileUtils.mkdir_p(templates_dir)
114
134
 
115
- files = [templates_dir + 'author.html', templates_dir + 'header.md']
135
+ files = { author: templates_dir + 'author.html', header: templates_dir + 'header.md' }
116
136
 
117
- files.each do |file|
118
- unless File.exists?(file)
137
+ files.each do |name, path|
138
+ if !File.exists?(path)
119
139
  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 }!"
120
140
  response = `#{$0} create_templates`
121
141
  puts response
142
+ elsif TEMPLATES[name] != File.read(path)
143
+ 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."
122
144
  end
123
145
  end
124
146
  end
@@ -2,7 +2,7 @@ module Planet
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 8
5
+ PATCH = 9
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.8
4
+ version: 0.3.9
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-22 00:00:00.000000000 Z
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake