who-needs-wp 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/who-needs-wp/Sidebar.rb +33 -0
- data/lib/who-needs-wp/pages.rb +3 -7
- data/lib/who-needs-wp/posts.rb +14 -26
- data/lib/who-needs-wp/sidebar/delicious.rb +41 -0
- data/lib/who-needs-wp/sidebar/pageindex.rb +9 -0
- data/lib/who-needs-wp/sidebar/recentposts.rb +9 -0
- data/lib/who-needs-wp/sidebar/twitter.rb +85 -0
- data/lib/who-needs-wp/templates/twitter.haml +1 -1
- data/lib/who-needs-wp/templates.rb +14 -11
- data/lib/who-needs-wp.rb +27 -11
- metadata +9 -7
- data/bin/wordpress2wnwp~ +0 -6
- data/lib/who-needs-wp/delicious.rb +0 -20
- data/lib/who-needs-wp/twitter.rb +0 -29
data/README.md
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module WhoNeedsWP
|
2
|
+
# Abstract class to be implemented by all sidebar elements
|
3
|
+
class Sidebar
|
4
|
+
# A list of Sidebar instances which will be rendered
|
5
|
+
@@content = []
|
6
|
+
|
7
|
+
# The HTML output of all of the sidebar instances combined
|
8
|
+
@@generated = nil
|
9
|
+
|
10
|
+
# Iterate through all of the side bar instances, render them and return as HTML
|
11
|
+
def self.render_all
|
12
|
+
if @@generated == nil
|
13
|
+
retval = []
|
14
|
+
@@content.each do |content|
|
15
|
+
retval << content.render
|
16
|
+
end
|
17
|
+
@@generated = retval.join
|
18
|
+
end
|
19
|
+
return @@generated
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create a new instance of this sidebar
|
23
|
+
def initialize
|
24
|
+
@logger = Logger.new(STDOUT)
|
25
|
+
@@content << self
|
26
|
+
end
|
27
|
+
|
28
|
+
# Render this peice of sidebar content. Returns HTML.
|
29
|
+
def render
|
30
|
+
# To be implemented.
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/who-needs-wp/pages.rb
CHANGED
@@ -14,13 +14,9 @@ module WhoNeedsWP
|
|
14
14
|
}
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@sidebar << @template['pageindex'].render(Object.new, {
|
21
|
-
:pages => @pages,
|
22
|
-
:options => @options
|
23
|
-
})
|
17
|
+
|
18
|
+
def self.get_pages
|
19
|
+
@pages
|
24
20
|
end
|
25
21
|
|
26
22
|
def self.generate_pages
|
data/lib/who-needs-wp/posts.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module WhoNeedsWP
|
3
3
|
def self.load_posts
|
4
|
-
@
|
4
|
+
@posts = []
|
5
5
|
Dir.glob('posts/**/*.markdown').each do |filename|
|
6
6
|
@logger.debug "Loading post #{filename}"
|
7
7
|
match = filename.match(/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([^\.]*)/)
|
@@ -16,37 +16,25 @@ module WhoNeedsWP
|
|
16
16
|
:created_at => date
|
17
17
|
}
|
18
18
|
# Generate a unique post ID to be used in the Atom feed
|
19
|
-
post[:id] = "#{options[:url]}#{generated_filename}".gsub(/http:\/\//, 'tag:')
|
19
|
+
post[:id] = "#{@options[:url]}#{generated_filename}".gsub(/http:\/\//, 'tag:')
|
20
20
|
match = post[:id].match(/([^\/]*)\/(.*)/)
|
21
21
|
post[:id] = "#{match[1]},#{date.strftime('%Y-%m-%d')}:#{match[2]}" if match
|
22
22
|
# Append the post to the global list of posts
|
23
|
-
@
|
23
|
+
@posts << post
|
24
24
|
end
|
25
25
|
# Sort the posts, newest first
|
26
|
-
@
|
27
|
-
@
|
26
|
+
@posts.sort! { |a, b| a[:created_at] <=> b[:created_at] }
|
27
|
+
@posts.reverse!
|
28
28
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@sidebar << @template['recentposts'].render(Object.new, {
|
33
|
-
:posts => @POSTS[0..5],
|
34
|
-
:options => @options
|
35
|
-
})
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.options
|
39
|
-
return @options
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.POSTS
|
43
|
-
return @POSTS
|
29
|
+
|
30
|
+
def self.get_posts
|
31
|
+
return @posts
|
44
32
|
end
|
45
33
|
|
46
34
|
def self.rss(filename, limit=10)
|
47
35
|
file = File.open(filename, "w")
|
48
36
|
file.write @template['rss'].render(Object.new, {
|
49
|
-
:posts => @
|
37
|
+
:posts => @posts[0..limit],
|
50
38
|
:options => @options
|
51
39
|
})
|
52
40
|
file.close
|
@@ -55,18 +43,18 @@ module WhoNeedsWP
|
|
55
43
|
def self.atom(filename, limit=10)
|
56
44
|
file = File.open(filename, "w")
|
57
45
|
file.write @template['atom'].render(Object.new, {
|
58
|
-
:posts => @
|
46
|
+
:posts => @posts[0..limit],
|
59
47
|
:options => @options
|
60
48
|
})
|
61
49
|
file.close
|
62
50
|
end
|
63
51
|
|
64
52
|
def self.generate_posts
|
65
|
-
@
|
53
|
+
@posts.each_index do |index|
|
66
54
|
# Calculate the previous and next posts
|
67
|
-
post = @
|
68
|
-
previous_post = @
|
69
|
-
next_post = @
|
55
|
+
post = @posts[index]
|
56
|
+
previous_post = @posts[index + 1] if index + 1 < @posts.length
|
57
|
+
next_post = @posts[index - 1] if index > 1
|
70
58
|
|
71
59
|
# Read the contents of the file
|
72
60
|
markdown = File.read(post[:filename][:original])
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module WhoNeedsWP
|
4
|
+
class Delicious < Sidebar
|
5
|
+
# Create a new Delicious sidebar
|
6
|
+
def initialize(username)
|
7
|
+
super()
|
8
|
+
@username = username
|
9
|
+
validate_options
|
10
|
+
end
|
11
|
+
|
12
|
+
# See Sidebar.render
|
13
|
+
def render
|
14
|
+
WhoNeedsWP::render_template("delicious", { :posts => get_bookmarks })
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Ensure that the Delicious username is set
|
20
|
+
def validate_options
|
21
|
+
if @username == nil or @username.empty?
|
22
|
+
raise "You need to provide a Delicious username"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return a list of bookmarks from Delicious
|
27
|
+
def get_bookmarks
|
28
|
+
@logger.debug "Fetching bookmarks from Delicious"
|
29
|
+
bookmarks = []
|
30
|
+
doc = Nokogiri::XML(open("http://feeds.delicious.com/v2/rss/#{@username}?count=5"))
|
31
|
+
doc.xpath('//channel/item').each do |item|
|
32
|
+
bookmarks << {
|
33
|
+
:title => (item/'title').first.content,
|
34
|
+
:url => (item/'link').first.content,
|
35
|
+
:date => Date.parse((item/'pubDate').first.content)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
return bookmarks
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
|
3
|
+
module WhoNeedsWP
|
4
|
+
# A class combining all the common functions required by Twitter sidebar components
|
5
|
+
class TwitterSidebar < Sidebar
|
6
|
+
protected
|
7
|
+
# Format a Tweet so that all the links appear in HTML
|
8
|
+
def format_text(text)
|
9
|
+
text = text.gsub(/(http:\/\/[^ ]+)/, '<a href="\1">\1</a>')
|
10
|
+
text = text.gsub(/(@([^ :]+))/, '<a href="http://twitter.com/\2">\1</a>')
|
11
|
+
return text.gsub(/(#([^ :]+))/, '<a href="http://twitter.com/#search?q=%23\2">\1</a>')
|
12
|
+
end
|
13
|
+
|
14
|
+
# Format all the tweets in the specified list
|
15
|
+
def format_tweets(tweets)
|
16
|
+
tweets.each do |tweet|
|
17
|
+
tweet[:html] = format_text(tweet[:text])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# A Sidebar component which displays a list of a user's tweets
|
23
|
+
class TwitterFeed < TwitterSidebar
|
24
|
+
# Create a new Twitter sidebar based on "username"'s tweets
|
25
|
+
def initialize(username)
|
26
|
+
super()
|
27
|
+
@username = username
|
28
|
+
validate_options
|
29
|
+
end
|
30
|
+
|
31
|
+
# See Sidebar.render
|
32
|
+
def render
|
33
|
+
WhoNeedsWP::render_template("twitter", {
|
34
|
+
:tweets => tweets,
|
35
|
+
:feed_title => "@#{@username}"
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Ensure the the Twitter username is set
|
42
|
+
def validate_options
|
43
|
+
if @username == nil or @username.empty?
|
44
|
+
raise "You need to provide a Twitter username"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return a list of tweets for the specified user
|
49
|
+
def tweets(per_page = 5)
|
50
|
+
return format_tweets(Twitter::Search.new.from(@username).per_page(per_page).fetch().results)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# A Sidebar component which displays a twitter search term
|
55
|
+
class TwitterSearch < TwitterSidebar
|
56
|
+
# Create a new Twitter sidebar based on a search of "term"
|
57
|
+
def initialize(term)
|
58
|
+
super()
|
59
|
+
@term = term
|
60
|
+
validate_options
|
61
|
+
end
|
62
|
+
|
63
|
+
# See Sidebar.render
|
64
|
+
def render
|
65
|
+
WhoNeedsWP::render_template("twitter", {
|
66
|
+
:tweets => tweets,
|
67
|
+
:feed_title => "Tweets for \"#{@term}\""
|
68
|
+
})
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
# Ensure the the Twitter search term is set
|
74
|
+
def validate_options
|
75
|
+
if @term == nil or @term.empty?
|
76
|
+
raise "You need to provide a Twitter search term"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return a list of tweets for the specified user
|
81
|
+
def tweets(per_page = 5)
|
82
|
+
return format_tweets(Twitter::Search.new(@term).per_page(per_page).fetch().results)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,21 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module WhoNeedsWP
|
2
|
+
# Render the specified template with the given options
|
3
|
+
def self.render_template(name, data)
|
4
|
+
data[:options] = @options
|
5
|
+
@template[name].render(Object.new, data)
|
6
|
+
end
|
4
7
|
|
5
8
|
# Render the specified HTML contents within the layout template
|
6
9
|
def self.render_html(filename, type, contents, title = "")
|
7
10
|
File.open(filename, "w") do |file|
|
8
11
|
body = @template['body'].render(Object.new, {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
:content => contents,
|
13
|
+
:options => @options,
|
14
|
+
:sidebar => Sidebar.render_all,
|
15
|
+
:layout_name => type
|
16
|
+
})
|
14
17
|
file.puts @template['layout'].render(Object.new, {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
:content => body,
|
19
|
+
:options => @options,
|
20
|
+
:title => title
|
21
|
+
})
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
data/lib/who-needs-wp.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'rdiscount'
|
4
4
|
require 'haml'
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
|
7
7
|
require 'open-uri'
|
8
8
|
require 'sass'
|
9
9
|
require 'makers-mark'
|
@@ -12,8 +12,11 @@ require 'rss/maker'
|
|
12
12
|
require 'net/ssh'
|
13
13
|
require 'net/sftp'
|
14
14
|
require 'who-needs-wp/css.rb'
|
15
|
-
require 'who-needs-wp/
|
16
|
-
require 'who-needs-wp/
|
15
|
+
require 'who-needs-wp/Sidebar.rb'
|
16
|
+
require 'who-needs-wp/sidebar/twitter.rb'
|
17
|
+
require 'who-needs-wp/sidebar/delicious.rb'
|
18
|
+
require 'who-needs-wp/sidebar/recentposts.rb'
|
19
|
+
require 'who-needs-wp/sidebar/pageindex.rb'
|
17
20
|
require 'who-needs-wp/templates.rb'
|
18
21
|
require 'who-needs-wp/posts.rb'
|
19
22
|
require 'who-needs-wp/pages.rb'
|
@@ -37,10 +40,23 @@ module WhoNeedsWP
|
|
37
40
|
self.load_templates
|
38
41
|
self.load_posts
|
39
42
|
self.load_pages
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
if @posts.length > 0
|
44
|
+
RecentPosts.new
|
45
|
+
end
|
46
|
+
if @pages.length > 0
|
47
|
+
PageIndex.new
|
48
|
+
end
|
49
|
+
if @options[:twitter]
|
50
|
+
if @options[:twitter][:username]
|
51
|
+
TwitterFeed.new(@options[:twitter][:username])
|
52
|
+
end
|
53
|
+
if @options[:twitter][:search]
|
54
|
+
TwitterSearch.new(@options[:twitter][:search])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if @options[:delicious]
|
58
|
+
delicious = Delicious.new(@options[:delicious][:user])
|
59
|
+
end
|
44
60
|
self.generate_posts
|
45
61
|
self.generate_pages
|
46
62
|
self.index
|
@@ -56,8 +72,8 @@ module WhoNeedsWP
|
|
56
72
|
# Generate the index page for the blog
|
57
73
|
def self.index
|
58
74
|
contents = ""
|
59
|
-
if @
|
60
|
-
@
|
75
|
+
if @posts.length > 0
|
76
|
+
@posts[0..3].each do |post|
|
61
77
|
contents << post[:html]
|
62
78
|
end
|
63
79
|
else
|
@@ -69,7 +85,7 @@ module WhoNeedsWP
|
|
69
85
|
# Generate a page containing a list of all posts
|
70
86
|
def self.all_posts
|
71
87
|
self.render_html("posts/all.html", "post_index", @template['all_posts'].render(Object.new, {
|
72
|
-
:posts => @
|
88
|
+
:posts => @posts,
|
73
89
|
:options => @options
|
74
90
|
}), "All Posts")
|
75
91
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Owen Griffin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-28 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -118,7 +118,6 @@ dependencies:
|
|
118
118
|
description: A static web site generator.
|
119
119
|
email: owen.griffin@gmail.com
|
120
120
|
executables:
|
121
|
-
- wordpress2wnwp~
|
122
121
|
- wordpress2wnwp
|
123
122
|
- who-needs-wp
|
124
123
|
extensions: []
|
@@ -129,10 +128,14 @@ extra_rdoc_files:
|
|
129
128
|
- README.md
|
130
129
|
files:
|
131
130
|
- lib/who-needs-wp.rb
|
131
|
+
- lib/who-needs-wp/Sidebar.rb
|
132
132
|
- lib/who-needs-wp/css.rb
|
133
|
-
- lib/who-needs-wp/delicious.rb
|
134
133
|
- lib/who-needs-wp/pages.rb
|
135
134
|
- lib/who-needs-wp/posts.rb
|
135
|
+
- lib/who-needs-wp/sidebar/delicious.rb
|
136
|
+
- lib/who-needs-wp/sidebar/pageindex.rb
|
137
|
+
- lib/who-needs-wp/sidebar/recentposts.rb
|
138
|
+
- lib/who-needs-wp/sidebar/twitter.rb
|
136
139
|
- lib/who-needs-wp/stylesheets/base.sass
|
137
140
|
- lib/who-needs-wp/stylesheets/pygments.sass
|
138
141
|
- lib/who-needs-wp/stylesheets/reset-fonts-grids.sass
|
@@ -149,7 +152,6 @@ files:
|
|
149
152
|
- lib/who-needs-wp/templates/recentposts.haml
|
150
153
|
- lib/who-needs-wp/templates/rss.haml
|
151
154
|
- lib/who-needs-wp/templates/twitter.haml
|
152
|
-
- lib/who-needs-wp/twitter.rb
|
153
155
|
- LICENSE
|
154
156
|
- README.html
|
155
157
|
- README.md
|
data/bin/wordpress2wnwp~
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
module WhoNeedsWP
|
3
|
-
def self.delicious
|
4
|
-
if @options[:delicious]
|
5
|
-
delicious = []
|
6
|
-
doc = Nokogiri::XML(open("http://feeds.delicious.com/v2/rss/#{@options[:delicious][:user]}?count=5"))
|
7
|
-
doc.xpath('//channel/item').each do |item|
|
8
|
-
delicious << {
|
9
|
-
:title => (item/'title').first.content,
|
10
|
-
:url => (item/'link').first.content,
|
11
|
-
:date => Date.parse((item/'pubDate').first.content)
|
12
|
-
}
|
13
|
-
end
|
14
|
-
@sidebar << @template['delicious'].render(Object.new, {
|
15
|
-
:posts => delicious,
|
16
|
-
:options => @options
|
17
|
-
})
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/who-needs-wp/twitter.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
|
2
|
-
module WhoNeedsWP
|
3
|
-
|
4
|
-
def self.parse_tweet(text)
|
5
|
-
text = text.gsub(/(http:\/\/[^ ]+)/, '<a href="\1">\1</a>')
|
6
|
-
text = text.gsub(/(@([^ :]+))/, '<a href="http://twitter.com/\2">\1</a>')
|
7
|
-
return text.gsub(/(#([^ :]+))/, '<a href="http://twitter.com/#search?q=%23\2">\1</a>')
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.twitter
|
11
|
-
if @options[:twitter][:user] != nil and not @options[:twitter][:user].empty?
|
12
|
-
@logger.debug "Reading Tweets for user #{@options[:twitter][:user]}"
|
13
|
-
tweets = Twitter::Search.new.from(@options[:twitter][:user]).per_page(5).fetch().results
|
14
|
-
@sidebar << @template['twitter'].render(Object.new, {
|
15
|
-
:tweets => tweets,
|
16
|
-
:feed_title => "@#{@options[:twitter][:user]}",
|
17
|
-
:options => @options
|
18
|
-
})
|
19
|
-
end
|
20
|
-
if @options[:twitter][:search] != nil and not @options[:twitter][:search].empty?
|
21
|
-
@logger.debug "Searching Twitter for #{@options[:twitter][:search]}"
|
22
|
-
@sidebar << @template['twitter'].render(Object.new, {
|
23
|
-
:tweets => Twitter::Search.new(@options[:twitter][:search]).per_page(5).fetch().results,
|
24
|
-
:feed_title => "Tweets for \"#{@options[:twitter][:search]}\"",
|
25
|
-
:options => @options
|
26
|
-
})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|