Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #42 from tamouse/master

Add --config global option and blog_slug variable
  • Loading branch information...
commit 1a69fbd1a7807a74a4d7f81e4ee6c132d4578369 2 parents 961d0fa + ad986da
Pablo Astigarraga authored April 11, 2014
6  Gemfile.lock
... ...
@@ -1,11 +1,12 @@
1 1
 PATH
2 2
   remote: .
3 3
   specs:
4  
-    planet (0.5.2)
  4
+    planet (0.5.3)
5 5
       box
6 6
       feedzirra
7 7
       gli
8 8
       mustache
  9
+      stringex
9 10
 
10 11
 GEM
11 12
   remote: http://rubygems.org/
@@ -16,7 +17,7 @@ GEM
16 17
       curb (~> 0.8.1)
17 18
       loofah (~> 1.2.1)
18 19
       sax-machine (~> 0.2.1)
19  
-    gli (2.8.1)
  20
+    gli (2.9.0)
20 21
     loofah (1.2.1)
21 22
       nokogiri (>= 1.4.4)
22 23
     mini_portile (0.5.2)
@@ -25,6 +26,7 @@ GEM
25 26
       mini_portile (~> 0.5.0)
26 27
     sax-machine (0.2.1)
27 28
       nokogiri (~> 1.6.0)
  29
+    stringex (2.1.2)
28 30
 
29 31
 PLATFORMS
30 32
   ruby
1  README.md
Source Rendered
@@ -116,6 +116,7 @@ So this is pretty sweet: planet.rb doesn't really want to inject html and random
116 116
    {{ post_date }}              # => "2012-04-14 05:17:00 UTC"
117 117
    {{ post_content }}           # => "I’ve been hurting to write this ever since we had the idea of creating a Planet for Cubox..." (Continued)
118 118
    {{ blog_name }}              # => "This is where I tell you stuff"
  119
+   {{ blog_slug }}              # => "this-is-where-i-tell-you-stuff"
119 120
    {{ blog_url }}               # => "http://blog.poteland.com"
120 121
    {{ image_url }}              # => "http://poteland.com/images/avatars/red_mage.png"
121 122
    {{ author }}                 # => "Pablo Astigarraga"
30  bin/planet
@@ -10,6 +10,8 @@ include GLI::App
10 10
 
11 11
 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'
12 12
 
  13
+flag [:c,:config], :default_value => 'planet.yml', :desc => "Planet configuration file"
  14
+
13 15
 desc 'Parses planet.yml file for blogs and generates their posts in Jekyll compliant format under the _posts directory'
14 16
 command :generate do |c|
15 17
 
@@ -21,7 +23,7 @@ due to spacing issues possible with markdown.
21 23
 }
22 24
   c.action do |global_options,options,args|
23 25
 
24  
-    Planet::Importer.import('planet.yml') do |planet|
  26
+    Planet::Importer.import(global_options[:config]) do |planet|
25 27
 
26 28
       post_extension = options[:extension] || 'markdown'
27 29
       post_extension = '.' + post_extension unless post_extension[0] == '.'
@@ -43,18 +45,17 @@ end
43 45
 desc 'Creates basic planet.yml config file'
44 46
 command :init do |c|
45 47
   c.action do |global_options,options,args|
46  
-    abort 'There is already a planet.yml file present' if File.exist? 'planet.yml'
47  
-
48  
-    File.open('planet.yml', 'w') { |f| f.write(Box::FILES['planet']) }
49  
-
50  
-    puts '=> Created default planet.yml'
  48
+    abort 'There is already a planet.yml file present' if File.exist?(global_options[:config])
  49
+    File.open(global_options[:config], 'w') { |f| f.write(Box::FILES['planet']) }
  50
+    puts "=> Created default #{global_options[:config]}"
51 51
   end
52 52
 end
53 53
 
54  
-desc 'Creates basic templates on the templates_directory specified in planet.yml'
  54
+desc "Creates basic templates on the templates_directory specified in configuration file"
55 55
 command :create_templates do |c|
56 56
   c.action do |global_options,options,args|
57  
-    conf = YAML.load_file('planet.yml')
  57
+    STDERR.puts "DEBUG: #{caller.first} global_options[:config]=#{global_options[:config].inspect}"
  58
+    conf = YAML.load_file(global_options[:config])
58 59
 
59 60
     templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
60 61
 
@@ -86,25 +87,24 @@ end
86 87
 desc 'Delete existing templates and recreate them'
87 88
 command :update_templates do |c|
88 89
   c.action do |global_options,options,args|
89  
-    conf = YAML.load_file('planet.yml')
  90
+    conf = YAML.load_file(global_options[:config])
90 91
 
91 92
     templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
92 93
 
93 94
     author = templates_dir + 'author.html'
94 95
     header = templates_dir + 'header.md'
95 96
 
96  
-
97 97
     File.delete(author) if File.exists?(author)
98 98
     File.delete(header) if File.exists?(header)
99 99
 
100  
-    response = `#{ $0 } create_templates`
  100
+    response = `#{$0} -d #{global_options[:config]} create_templates`
101 101
     puts response
102 102
   end
103 103
 end
104 104
 
105 105
 pre do |global,command,options,args|
106 106
   if command.name == :generate
107  
-    conf = YAML.load_file('planet.yml')
  107
+    conf = YAML.load_file(global[:config])
108 108
 
109 109
     templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts')
110 110
     FileUtils.mkdir_p(templates_dir)
@@ -114,7 +114,9 @@ pre do |global,command,options,args|
114 114
     files.each do |name, path|
115 115
       if !File.exists?(path)
116 116
         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 }!"
117  
-        response = `#{$0} create_templates`
  117
+
  118
+        response = `#{$0} -c #{global[:config]} create_templates`
  119
+
118 120
         puts response
119 121
       elsif Box::FILES[name] != File.read(path)
120 122
         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|
130 132
 end
131 133
 
132 134
 on_error do |exception|
  135
+  STDERR.puts "Error: #{exception} (#{exception.class})"
  136
+  STDERR.puts exception.backtrace.join("\n")
133 137
   true
134 138
 end
135 139
 
2  lib/planet/post.rb
... ...
@@ -1,3 +1,4 @@
  1
+require 'stringex_lite'
1 2
 require 'mustache'
2 3
 
3 4
 class Planet::Post
@@ -26,6 +27,7 @@ def to_h
26 27
       author: self.blog.author,
27 28
       blog_url: self.blog.url,
28 29
       blog_name: self.blog.name,
  30
+      blog_slug: self.blog.name.to_url(:limit => 50, :truncate_words => true),
29 31
       post_url: self.url,
30 32
       twitter: self.blog.twitter,
31 33
       twitter_url: "http://twitter.com/#{ self.blog.twitter }",
2  lib/planet/version.rb
@@ -2,7 +2,7 @@ class Planet
2 2
   module Version
3 3
     MAJOR = 0
4 4
     MINOR = 5
5  
-    PATCH = 2
  5
+    PATCH = 3
6 6
 
7 7
     def self.to_s
8 8
       [MAJOR, MINOR, PATCH].join('.')
1  planet.gemspec
@@ -17,4 +17,5 @@ spec = Gem::Specification.new do |s|
17 17
   s.add_runtime_dependency('feedjira')
18 18
   s.add_runtime_dependency('mustache')
19 19
   s.add_runtime_dependency('box')
  20
+  s.add_runtime_dependency("stringex")
20 21
 end

0 notes on commit 1a69fbd

Please sign in to comment.
Something went wrong with that request. Please try again.