flannel 0.0.1 → 0.1.0

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.
@@ -0,0 +1,3 @@
1
+ & blog.rubyyot.com/tag/rubyyot/feed/rss
2
+
3
+ & http://devlicio.us/blogs/sergio_pereira/rss.aspx?Tags=JavaScript-Demystified&AndTags=1
@@ -0,0 +1,31 @@
1
+ <ul><li>
2
+ <a href='http://blog.rubyyot.com/2009/05/summer-of-learning-challenge/'>Plans for Rubyyot.com and the Summer of Learning Challenge</a>
3
+ </li>
4
+ <li>
5
+ <a href='http://blog.rubyyot.com/2009/05/using-rack-to-generate-content-from-an-rss-feed/'>Using Rack to generate content from an rss feed</a>
6
+ </li>
7
+ <li>
8
+ <a href='http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/'>Rubyyot.com is dead; Long live Rubyyot.com</a>
9
+ </li></ul>
10
+
11
+ <ul><li>
12
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/09/19/javascript-and-its-love-for-zeroes.aspx'>JavaScript and its love for zeroes</a>
13
+ </li>
14
+ <li>
15
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/06/12/javascript-not-your-father-s-inheritance-model-part-2.aspx'>JavaScript: Not your father's inheritance model - Part 2</a>
16
+ </li>
17
+ <li>
18
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/06/12/javascript-not-your-father-s-inheritance-model-part-1.aspx'>JavaScript: Not your father's inheritance model - Part 1</a>
19
+ </li>
20
+ <li>
21
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/03/31/javascript-avoid-the-evil-eval.aspx'>JavaScript: Avoid the Evil eval</a>
22
+ </li>
23
+ <li>
24
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/02/24/javascript-inner-functions-and-private-members.aspx'>JavaScript, inner functions and private members</a>
25
+ </li>
26
+ <li>
27
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/02/23/javascript-time-to-grok-closures.aspx'>JavaScript, time to grok closures</a>
28
+ </li>
29
+ <li>
30
+ <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx'>JavaScript, 5 ways to call a function</a>
31
+ </li></ul>
@@ -0,0 +1,29 @@
1
+ <!-- generator="WordPress/2.9" -->
2
+ <rss version="0.92">
3
+ <channel>
4
+ <title>Blog &#124; Rubyyot &#187; rubyyot</title>
5
+ <link>http://blog.rubyyot.com</link>
6
+ <description>Pragmatism, productivity, programming and getting by in the world</description>
7
+ <lastBuildDate>Wed, 24 Jun 2009 05:53:27 +0000</lastBuildDate>
8
+ <docs>http://backend.userland.com/rss092</docs>
9
+ <language>en</language>
10
+
11
+ <item>
12
+ <title>Plans for Rubyyot.com and the Summer of Learning Challenge</title>
13
+ <description><![CDATA[Plans for the future
14
+ In the past week I started playing with Rack and put together a little Rack application that generates content from my blog&#8217;s rss feed about the site. As I stated in that post I really didn&#8217;t like having the &#8220;parked&#8221; page up there, and I also wanted to try out Rack, which [...]]]></description>
15
+ <link>http://blog.rubyyot.com/2009/05/summer-of-learning-challenge/</link>
16
+ </item>
17
+ <item>
18
+ <title>Using Rack to generate content from an rss feed</title>
19
+ <description><![CDATA[The Hype
20
+ Rack is taking the Ruby and Rails worlds by storm. It&#8217;s hard to find any recent Ruby related posts that don&#8217;t mention Rack in some way or other. It&#8217;s obvious that Rack is here. If you haven&#8217;t read up on it. Jason Siefer has put together a good post full [...]]]></description>
21
+ <link>http://blog.rubyyot.com/2009/05/using-rack-to-generate-content-from-an-rss-feed/</link>
22
+ </item>
23
+ <item>
24
+ <title>Rubyyot.com is dead; Long live Rubyyot.com</title>
25
+ <description><![CDATA[I have pulled the plug on Rubyyot.com, the task management site. It was an enjoyable learning experience, but I was no longer using it and I don&#8217;t think anyone else was either. I&#8217;ve removed it to make way for new development projects. That is if I can ever concentrate enough on any [...]]]></description>
26
+ <link>http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/</link>
27
+ </item>
28
+ </channel>
29
+ </rss>
@@ -18,3 +18,12 @@ end
18
18
  Given /^a formatter of '([^\"']*)'$/ do |formatter|
19
19
  @wiki_link = lambda { |keyword| eval formatter }
20
20
  end
21
+
22
+ Given /^the necessary feeds$/ do
23
+ require 'mocha'
24
+
25
+ devlicious = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", "devlicious.rss"))
26
+ rubyyot = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", "rubyyot.rss"))
27
+ Flannel::FeedParser.any_instance.stubs(:get_document).returns(rubyyot, devlicious)
28
+ end
29
+
data/flannel.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{flannel}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jamal Hansen"]
12
- s.date = %q{2009-12-26}
12
+ s.date = %q{2009-12-29}
13
13
  s.email = %q{jamal.hansen@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -23,18 +23,23 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION.yml",
25
25
  "features/external_link.feature",
26
+ "features/feed.feature",
27
+ "features/fixtures/devlicious.rss",
26
28
  "features/fixtures/external_link.flannel",
27
29
  "features/fixtures/external_link.out",
30
+ "features/fixtures/feed.flannel",
31
+ "features/fixtures/feed.out",
28
32
  "features/fixtures/list.flannel",
29
33
  "features/fixtures/list.out",
30
34
  "features/fixtures/paragraph.flannel",
31
35
  "features/fixtures/paragraph.out",
32
36
  "features/fixtures/preformatted.flannel",
33
37
  "features/fixtures/preformatted.out",
38
+ "features/fixtures/rubyyot.rss",
34
39
  "features/fixtures/wiki_links.flannel",
35
40
  "features/fixtures/wiki_links.out",
41
+ "features/fixtures/wiki_links_for_lambda.flannel",
36
42
  "features/fixtures/wiki_links_for_lambda.out",
37
- "features/fixtures/wiki_links_for_lamdba.flannel",
38
43
  "features/list.feature",
39
44
  "features/paragraph.feature",
40
45
  "features/preformatted_text.feature",
@@ -43,12 +48,14 @@ Gem::Specification.new do |s|
43
48
  "features/wiki_links.feature",
44
49
  "flannel.gemspec",
45
50
  "lib/cutting_board.rb",
51
+ "lib/feed_parser.rb",
46
52
  "lib/flannel.rb",
47
53
  "lib/shears.rb",
48
54
  "lib/square.rb",
49
55
  "lib/stripe.rb",
50
56
  "lib/wrappable.rb",
51
57
  "test/cutting_board_test.rb",
58
+ "test/feed_parser_test.rb",
52
59
  "test/flannel_test.rb",
53
60
  "test/shears_test.rb",
54
61
  "test/square_test.rb",
@@ -65,6 +72,7 @@ Gem::Specification.new do |s|
65
72
  "test/test_helper.rb",
66
73
  "test/stripe_test.rb",
67
74
  "test/cutting_board_test.rb",
75
+ "test/feed_parser_test.rb",
68
76
  "test/flannel_test.rb",
69
77
  "test/square_test.rb",
70
78
  "test/shears_test.rb"
@@ -75,12 +83,15 @@ Gem::Specification.new do |s|
75
83
  s.specification_version = 3
76
84
 
77
85
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
- s.add_development_dependency(%q<technicalpickles-shoulda>, [">= 0"])
86
+ s.add_runtime_dependency(%q<Hpricot>, [">= 0"])
87
+ s.add_development_dependency(%q<technicalpickles-shouldamocha>, [">= 0"])
79
88
  else
80
- s.add_dependency(%q<technicalpickles-shoulda>, [">= 0"])
89
+ s.add_dependency(%q<Hpricot>, [">= 0"])
90
+ s.add_dependency(%q<technicalpickles-shouldamocha>, [">= 0"])
81
91
  end
82
92
  else
83
- s.add_dependency(%q<technicalpickles-shoulda>, [">= 0"])
93
+ s.add_dependency(%q<Hpricot>, [">= 0"])
94
+ s.add_dependency(%q<technicalpickles-shouldamocha>, [">= 0"])
84
95
  end
85
96
  end
86
97
 
@@ -0,0 +1,42 @@
1
+ require 'hpricot'
2
+ require 'open-uri'
3
+
4
+ module Flannel
5
+ class FeedParser
6
+ def sub_feeds(url)
7
+ url = format_url(url)
8
+ get_news(url)
9
+ end
10
+
11
+ def format_url url
12
+ url.strip!
13
+ url = "http://#{url}" if url[0..6] != "http://"
14
+ url
15
+ end
16
+
17
+ def get_document url
18
+ open(url)
19
+ end
20
+
21
+ def format_item(link, title)
22
+ " <li>\n <a href='#{link}'>#{title}</a>\n </li>\n"
23
+ end
24
+
25
+ def get_news url
26
+ item_string = ""
27
+ #begin
28
+ doc = Hpricot.XML(get_document(url))
29
+
30
+ (doc/"item").each do |item|
31
+ link = (item/"link").inner_html
32
+ title = (item/"title").inner_html
33
+ item_string << format_item(link, title)
34
+ end
35
+
36
+ item_string
37
+ #rescue
38
+ # "Error retrieving data."
39
+ #end
40
+ end
41
+ end
42
+ end
data/lib/shears.rb CHANGED
@@ -51,7 +51,7 @@ module Flannel
51
51
  end
52
52
 
53
53
  def strip_markers line
54
- parts = line.match(/^([=_*]+)(.*)/)
54
+ parts = line.match(/^([=_*&]+)(.*)/)
55
55
 
56
56
  if parts
57
57
  set_style parts[1]
@@ -61,7 +61,7 @@ module Flannel
61
61
  end
62
62
 
63
63
  def set_style marker
64
- if marker
64
+ if marker
65
65
  case marker[0]
66
66
  when 61 # equals (header)
67
67
  style = "header_#{marker.length}"
@@ -71,6 +71,8 @@ module Flannel
71
71
  @preformatted_marker_line = true
72
72
  when 42 # star (list)
73
73
  @square.style = :list
74
+ when 38 # ampersand (feed)
75
+ @square.style = :feed
74
76
  end
75
77
  end
76
78
  end
data/lib/square.rb CHANGED
@@ -6,7 +6,7 @@ module Flannel
6
6
  attr_accessor :style
7
7
 
8
8
  def initialize params={}
9
- @tags ={:preformatted => "pre", :list => "ul", :header_1 => "h1", :header_2 => "h2", :header_3 => "h3", :header_4 => "h4", :header_5 => "h5", :header_6 => "h6"}
9
+ @tags ={:preformatted => "pre", :feed => "ul", :list => "ul", :header_1 => "h1", :header_2 => "h2", :header_3 => "h3", :header_4 => "h4", :header_5 => "h5", :header_6 => "h6"}
10
10
  @stripes = []
11
11
  @style = :paragraph
12
12
  end
data/lib/stripe.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'wrappable'
2
+ require 'feed_parser'
2
3
 
3
4
  module Flannel
4
5
  class Stripe
@@ -39,8 +40,13 @@ module Flannel
39
40
  end
40
41
 
41
42
  def to_h
42
- text = build_wiki_links
43
- markup text
43
+ if feed
44
+ parser = Flannel::FeedParser.new
45
+ parser.sub_feeds @weave
46
+ else
47
+ text = build_wiki_links
48
+ markup text
49
+ end
44
50
  end
45
51
 
46
52
  def preformatted
@@ -50,13 +56,17 @@ module Flannel
50
56
  def list
51
57
  @style == :list
52
58
  end
59
+
60
+ def feed
61
+ @style == :feed
62
+ end
53
63
 
54
64
  def markup text
55
65
  return html_escape text if preformatted
56
66
 
57
67
  tag = "li" if list
58
68
  wrap(text, tag)
59
- end
69
+ end
60
70
 
61
71
  def html_escape text
62
72
  require 'cgi'
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+ require 'mocha'
3
+
4
+ class FeedTest < Test::Unit::TestCase
5
+ context "bootstrapping test" do
6
+ setup do
7
+ @devlicious = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "devlicious.rss"))
8
+ @rubyyot = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "rubyyot.rss"))
9
+ end
10
+
11
+ should "read rss files" do
12
+ assert_not_nil @devlicious
13
+ assert_not_nil @rubyyot
14
+ end
15
+ end
16
+
17
+ context "formatting items" do
18
+ should "format items as link wrapped in li tags" do
19
+ reader = Flannel::FeedParser.new()
20
+ assert_equal(" <li>\n <a href='foo'>bar</a>\n </li>\n", reader.format_item('foo', 'bar'))
21
+ end
22
+ end
23
+
24
+ context "basic call" do
25
+ setup do
26
+ @devlicious = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "devlicious.rss"))
27
+ @rubyyot = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "rubyyot.rss"))
28
+ @expected_rubyyot = " <li>\n <a href='http://blog.rubyyot.com/2009/05/summer-of-learning-challenge/'>Plans for Rubyyot.com and the Summer of Learning Challenge</a>\n </li>\n <li>\n <a href='http://blog.rubyyot.com/2009/05/using-rack-to-generate-content-from-an-rss-feed/'>Using Rack to generate content from an rss feed</a>\n </li>\n <li>\n <a href='http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/'>Rubyyot.com is dead; Long live Rubyyot.com</a>\n </li>\n"
29
+ @expected_devlicious = " <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/09/19/javascript-and-its-love-for-zeroes.aspx'>JavaScript and its love for zeroes</a>\n </li>\n <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/06/12/javascript-not-your-father-s-inheritance-model-part-2.aspx'>JavaScript: Not your father's inheritance model - Part 2</a>\n </li>\n <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/06/12/javascript-not-your-father-s-inheritance-model-part-1.aspx'>JavaScript: Not your father's inheritance model - Part 1</a>\n </li>\n <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/03/31/javascript-avoid-the-evil-eval.aspx'>JavaScript: Avoid the Evil eval</a>\n </li>\n <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/02/24/javascript-inner-functions-and-private-members.aspx'>JavaScript, inner functions and private members</a>\n </li>\n <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/02/23/javascript-time-to-grok-closures.aspx'>JavaScript, time to grok closures</a>\n </li>\n <li>\n <a href='http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx'>JavaScript, 5 ways to call a function</a>\n </li>\n"
30
+ end
31
+
32
+ should "substitute feed line with feed" do
33
+ feed = "http://blog.rubyyot.com/tag/rubyyot/feed/rss"
34
+ reader = Flannel::FeedParser.new()
35
+ reader.expects(:get_document).with(feed).returns(@rubyyot)
36
+ body = reader.sub_feeds(feed)
37
+
38
+ assert_equal(@expected_rubyyot, body)
39
+ end
40
+
41
+ should "substitute without http://" do
42
+ feed = "blog.rubyyot.com/tag/rubyyot/feed/rss"
43
+ reader = Flannel::FeedParser.new()
44
+ reader.expects(:get_document).with("http://#{feed}").returns(@rubyyot)
45
+ body = reader.sub_feeds(feed)
46
+
47
+ assert_equal(@expected_rubyyot, body)
48
+ end
49
+
50
+ should "modify using provided url" do
51
+ feed = "http://devlicio.us/blogs/sergio_pereira/rss.aspx?Tags=JavaScript-Demystified&AndTags=1"
52
+ reader = Flannel::FeedParser.new()
53
+ reader.expects(:get_document).with(feed).returns(@devlicious)
54
+ body = reader.sub_feeds(feed)
55
+
56
+ assert_equal(@expected_devlicious, body)
57
+ end
58
+
59
+ should "format url from body" do
60
+ reader = Flannel::FeedParser.new
61
+ url = reader.format_url("http://blog.rubyyot.com/tag/rubyyot/feed/rss" )
62
+
63
+ assert_equal("http://blog.rubyyot.com/tag/rubyyot/feed/rss", url)
64
+ end
65
+
66
+ should "format url from body and add http if necessary" do
67
+ reader = Flannel::FeedParser.new
68
+ url = reader.format_url("blog.rubyyot.com/tag/rubyyot/feed/rss" )
69
+
70
+ assert_equal("http://blog.rubyyot.com/tag/rubyyot/feed/rss", url)
71
+ end
72
+ end
73
+ end
74
+
data/test/shears_test.rb CHANGED
@@ -39,5 +39,12 @@ class ShearsTest < Test::Unit::TestCase
39
39
  squares = @shears.cut markup
40
40
  assert_equal "foo\n\nbar", squares[0].to_s
41
41
  end
42
+
43
+ should "set square style to feed based on ampersand " do
44
+ markup = "& http://www.example.com/rss"
45
+
46
+ squares = @shears.cut markup
47
+ assert_equal :feed, squares[0].style
48
+ end
42
49
  end
43
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flannel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamal Hansen
@@ -9,11 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-26 00:00:00 -06:00
12
+ date: 2009-12-29 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: technicalpickles-shoulda
16
+ name: Hpricot
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: technicalpickles-shouldamocha
17
27
  type: :development
18
28
  version_requirement:
19
29
  version_requirements: !ruby/object:Gem::Requirement
@@ -39,18 +49,23 @@ files:
39
49
  - Rakefile
40
50
  - VERSION.yml
41
51
  - features/external_link.feature
52
+ - features/feed.feature
53
+ - features/fixtures/devlicious.rss
42
54
  - features/fixtures/external_link.flannel
43
55
  - features/fixtures/external_link.out
56
+ - features/fixtures/feed.flannel
57
+ - features/fixtures/feed.out
44
58
  - features/fixtures/list.flannel
45
59
  - features/fixtures/list.out
46
60
  - features/fixtures/paragraph.flannel
47
61
  - features/fixtures/paragraph.out
48
62
  - features/fixtures/preformatted.flannel
49
63
  - features/fixtures/preformatted.out
64
+ - features/fixtures/rubyyot.rss
50
65
  - features/fixtures/wiki_links.flannel
51
66
  - features/fixtures/wiki_links.out
67
+ - features/fixtures/wiki_links_for_lambda.flannel
52
68
  - features/fixtures/wiki_links_for_lambda.out
53
- - features/fixtures/wiki_links_for_lamdba.flannel
54
69
  - features/list.feature
55
70
  - features/paragraph.feature
56
71
  - features/preformatted_text.feature
@@ -59,12 +74,14 @@ files:
59
74
  - features/wiki_links.feature
60
75
  - flannel.gemspec
61
76
  - lib/cutting_board.rb
77
+ - lib/feed_parser.rb
62
78
  - lib/flannel.rb
63
79
  - lib/shears.rb
64
80
  - lib/square.rb
65
81
  - lib/stripe.rb
66
82
  - lib/wrappable.rb
67
83
  - test/cutting_board_test.rb
84
+ - test/feed_parser_test.rb
68
85
  - test/flannel_test.rb
69
86
  - test/shears_test.rb
70
87
  - test/square_test.rb
@@ -102,6 +119,7 @@ test_files:
102
119
  - test/test_helper.rb
103
120
  - test/stripe_test.rb
104
121
  - test/cutting_board_test.rb
122
+ - test/feed_parser_test.rb
105
123
  - test/flannel_test.rb
106
124
  - test/square_test.rb
107
125
  - test/shears_test.rb