public
Fork of rubys/mars
Description: Yet Another Planet Refactoring
Homepage: http://intertwingly.net/blog/2007/12/19/Yet-Another-Planet-Refactoring
Clone URL: git://github.com/technomancy/mars.git
implemented ERB templating, with an example template that is extremely 
lame!
technomancy (author)
Thu Jun 26 17:45:57 -0700 2008
commit  71c625aa563b43acff9a6594e50253c22b91caec
tree    f121a5832c4478e434d889720a3cbf720854aa3d
parent  62e31bbe207f3299deac5789c9beb24c444e494c
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ Rakefile.rb
0
 bin/planet
0
 bin/reconstitute
0
 lib/mars.rb
0
-lib/planet/config.rb
0
+lib/planet/ini_config.rb
0
 lib/planet/fido.rb
0
 lib/planet/harvest.rb
0
 lib/planet/log.rb
0
...
2
3
4
 
 
5
6
7
...
15
16
17
18
 
 
 
19
20
21
...
2
3
4
5
6
7
8
9
...
17
18
19
 
20
21
22
23
24
25
0
@@ -2,6 +2,8 @@
0
 
0
 Mars is a feed aggregator!
0
 
0
+http://intertwingly.net/blog/2007/12/19/Yet-Another-Planet-Refactoring
0
+
0
 == Installation
0
 
0
 Most of the prerequisites will be handled by Rubygems. Unfortunately
0
@@ -15,7 +17,9 @@ the latest html5lib package contains a bug that's only fixed in 0.10.1
0
 
0
   $ planet $CONFIG_FILE
0
 
0
-Currently only INI files are supported for configuration.
0
+Config files may be in INI or YAML. See test/config.yml for an example.
0
+
0
+TODO: list required values?
0
 
0
 == License
0
 
...
4
5
6
7
 
8
9
10
 
11
12
13
...
4
5
6
 
7
8
9
 
10
11
12
13
0
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib/')
0
 
0
 require 'rubygems'
0
 require 'hoe'
0
-require 'mars'
0
+require 'planet'
0
 require 'rake/testtask'
0
 
0
-Hoe.new('mars', Mars::VERSION) do |p|
0
+Hoe.new('mars', Planet::VERSION) do |p|
0
   p.developer('Sam Ruby', '')
0
   p.url = 'http://github.com/rubys/mars'
0
 
...
1
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
8
9
...
1
2
3
 
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0
@@ -1,9 +1,25 @@
0
 require 'erb'
0
 
0
 module Planet
0
- module ERb
0
- def self.process(template, feed)
0
- # TODO: stuff
0
+ module ERB
0
+ module_function
0
+
0
+ def process(template, feed)
0
+ @sources = []
0
+ ::ERB.new(File.read(template)).result(binding)
0
+ end
0
+
0
+ # Ugh; REXML's API is horrible! Let's wrap it.
0
+ def method_missing(method, *args)
0
+ if args.empty? and @elt.respond_to? :get_elements
0
+ @elt.get_elements(method.to_s).first
0
+ else
0
+ super(method, *args)
0
+ end
0
+ end
0
+
0
+ def source_link(rel = 'alternate')
0
+ (@source || source).get_elements('link').detect{|source| source.attribute('rel').to_s == rel }.attribute('href')
0
     end
0
   end
0
 end
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@ name: Test Planet
0
 link: http://planet.example.com
0
 owner_name: John Doe
0
 owner_email: john@example.com
0
-template_files: foo.erb
0
+template_files: test/index.html.erb
0
 output_directory: test/output
0
 cache_directory: test/cache
0
 feeds:
...
24
25
26
27
 
28
29
30
...
24
25
26
 
27
28
29
30
0
@@ -24,7 +24,7 @@
0
    <%= source.get_elements('title').first.text %></a>
0
   
0
    <a href="<%= link.attribute('href') %>">
0
- <%= title %></a>
0
+ <%= title.text %></a>
0
   </h3>
0
 
0
   <div class="content"><%= content %></div>
...
1
2
3
4
5
6
7
...
1
2
 
 
3
4
5
0
@@ -1,7 +1,5 @@
0
 require File.dirname(__FILE__) + '/test_helper'
0
 
0
-require 'planet/config'
0
-
0
 class TestConfig < Test::Unit::TestCase
0
   def setup
0
     Planet.configure File.dirname(__FILE__) + '/config.yml'
...
3
4
5
6
7
8
 
 
 
 
 
 
 
 
9
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
14
...
3
4
5
 
 
 
6
7
8
9
10
11
12
13
14
15
 
 
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
0
@@ -3,12 +3,30 @@ require File.dirname(__FILE__) + '/test_helper'
0
 require 'planet/splice'
0
 
0
 class TestErb < Test::Unit::TestCase
0
- def setup
0
- Planet.configure File.dirname(__FILE__) + '/config.yml'
0
- Planet.splice
0
+ Planet.configure File.dirname(__FILE__) + '/config.yml'
0
+ Planet.spider
0
+ Planet.splice
0
+ @@output_filename = 'test/output/index.html'
0
+ @@output = File.read(@@output_filename) rescue ''
0
+
0
+ def test_output
0
+ assert File.exist?(@@output_filename)
0
   end
0
 
0
- def test_output
0
- assert File.exist?('test/output/index.html')
0
+ def test_output_html
0
+ assert_in_output /\<html/
0
+ end
0
+
0
+ def test_output_metadata
0
+ assert_in_output /\<title\>Test Planet\<\/title\>/
0
+ end
0
+
0
+ def test_entry
0
+ assert_in_output /<a href="http:\/\/technomancy\.us\/111">\s*in which the cake is found to be delicious and moist<\/a>/
0
+ end
0
+
0
+ private
0
+ def assert_in_output(matcher)
0
+ assert @@output[matcher], "#{matcher.inspect} was not found in output."
0
   end
0
 end
...
 
 
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,4 +1,18 @@
0
+$VERBOSE = false
0
+
0
 require 'test/unit'
0
 require 'rubygems'
0
 
0
 $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
0
+
0
+require 'planet'
0
+
0
+# For tests, never fetch and always consider things not-modified.
0
+class Net::HTTP
0
+ def start; Net::HTTPNotModified.new('1.0', '304', 'Not Modified') end
0
+ def code; '304' end
0
+end
0
+
0
+module Planet
0
+ @@log = Logger.new('test/test.log')
0
+end
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-require 'test/unit'
0
+require File.dirname(__FILE__) + '/test_helper'
0
 require 'planet/sift'
0
 
0
 class TestSift < Test::Unit::TestCase
...
1
 
2
3
4
5
6
7
 
8
9
10
...
 
1
2
3
4
5
6
 
7
8
9
10
0
@@ -1,10 +1,10 @@
0
-require 'test/unit'
0
+require File.dirname(__FILE__) + '/test_helper'
0
 require 'planet/xmlparser'
0
 
0
 # p REXML::VERSION, PLATFORM
0
 
0
 class TestXmlParser < Test::Unit::TestCase
0
- def test_102
0
+ def test_attribute_in_default_namespace
0
     # http://www.germane-software.com/projects/rexml/ticket/102
0
     doc = Planet::XmlParser.parse('<doc xmlns="ns"><item name="foo"/></doc>')
0
     assert doc.root.elements["item[@name='foo']"]

Comments

    No one has commented yet.