Commit ae1d201628293581becbed17ee8637d452c016de

Add some helper functions to help clean up view logic. Also, tests.
  
3131 puts "loaded credentials: #{@@config['credentials']['username']}, **********"
3232end
3333
34def make_user_link(data)
35 origin = data['origin']
36 name = data['user']['screen_name']
37 string = %Q(<b><a href="#{@@sites[origin]['url']}#{name}">#{name}</a></b>)
38 return string
39end
40
41def parse_text(origin, text)
42 if origin == "identica"
43 return identicaify linkify html text
44 else
45 return linkify html text
46 end
47end
48
3449def escape_amp(text)
3550 return text.gsub(/&(?!(amp|lt|gt|#39|quot);)/, "&amp;")
3651end
5757 gsub("'", "&#39;").
5858 gsub("\"", "&quot;")
5959end
60
6160
6261def linkify(text)
6362 new = text.dup
tests/unit.rb
(37 / 25)
  
33require 'shoulda'
44
55class UnitTests < Test::Unit::TestCase
6 context "correctly parse urls" do
6 context "linkify" do
77 should "correctly parse basic URLs with no slash on the end" do
8 assert_equal
9 "<a href=\"http://www.google.com\">http://www.google.com</a>",
8 assert_equal "<a href=\"http://www.google.com\">http://www.google.com</a>",
109 linkify("http://www.google.com")
1110 end
1211
1312 should "correctly parse URLs with a slash on the end" do
14 assert_equal
15 "<a href=\"http://www.google.com/\">http://www.google.com/</a>",
13 assert_equal "<a href=\"http://www.google.com/\">http://www.google.com/</a>",
1614 linkify("http://www.google.com/")
1715 end
1816
1917 should "correctly parse https urls" do
20 assert_equal
21 "<a href=\"https://www.google.com/\">https://www.google.com/</a>",
18 assert_equal "<a href=\"https://www.google.com/\">https://www.google.com/</a>",
2219 linkify("https://www.google.com/")
2320 end
2421
2522 should "correctly parse urls with pages after a slash" do
26 assert_equal
27 "<a href=\"https://www.google.com/link.html\">https://www.google.com/link.html</a>",
23 assert_equal "<a href=\"https://www.google.com/link.html\">https://www.google.com/link.html</a>",
2824 linkify("https://www.google.com/link.html")
2925 end
3026
3127 should "correctly parse urls with pages with ? in the url" do
32 assert_equal
33 "<a href=\"https://www.google.com/?whatever.com\">https://www.google.com/?whatever.com</a>",
28 assert_equal "<a href=\"https://www.google.com/?whatever.com\">https://www.google.com/?whatever.com</a>",
3429 linkify("https://www.google.com/?whatever.com")
3530 end
3631
3732 should "correctly parse urls ending with a '.'" do
38 assert_equal
39 "blah blah <a href=\"https://www.google.com/\">https://www.google.com/</a>. Blah",
33 assert_equal "blah blah <a href=\"https://www.google.com/\">https://www.google.com/</a>. Blah",
4034 linkify("blah blah https://www.google.com/. Blah")
4135 end
4236
4337 should "correctly parse urls ending with a '.' at the end of a string" do
44 assert_equal
45 "blah blah <a href=\"https://www.google.com/\">https://www.google.com/</a>.",
38 assert_equal "blah blah <a href=\"https://www.google.com/\">https://www.google.com/</a>.",
4639 linkify("blah blah https://www.google.com/.")
4740 end
4841
4942 should "correctly parse urls containing #." do
50 assert_equal
51 "<a href=\"https://www.google.com/#anchor\">https://www.google.com/#anchor</a>",
43 assert_equal "<a href=\"https://www.google.com/#anchor\">https://www.google.com/#anchor</a>",
5244 linkify("https://www.google.com/#anchor")
5345 end
5446
5547 should "correctly parse urls containing +." do
56 assert_equal
57 "<a href=\"https://www.google.com/+stuff\">https://www.google.com/+stuff</a>",
48 assert_equal "<a href=\"https://www.google.com/+stuff\">https://www.google.com/+stuff</a>",
5849 linkify("https://www.google.com/+stuff")
5950 end
6051
6152 should "correctly parse urls containing -" do
62 assert_equal
63 "<a href=\"http://www.hypebot.com/hypebot/2009/06/walmart-shutting-down-drm-download-servers.html\">http://www.hypebot.com/hypebot/2009/06/walmart-shutting-down-drm-download-servers.html</a>",
53 assert_equal "<a href=\"http://www.hypebot.com/hypebot/2009/06/walmart-shutting-down-drm-download-servers.html\">http://www.hypebot.com/hypebot/2009/06/walmart-shutting-down-drm-download-servers.html</a>",
6454 linkify("http://www.hypebot.com/hypebot/2009/06/walmart-shutting-down-drm-download-servers.html")
6555 end
6656
6757 should "correctly parse urls ending with ':'" do
68 assert_equal
69 "some stuff <a href=\"http://google.com/whatever\">http://google.com/whatever</a>: stuff",
58 assert_equal "some stuff <a href=\"http://google.com/whatever\">http://google.com/whatever</a>: stuff",
7059 linkify("some stuff http://google.com/whatever: stuff")
7160 end
7261
7362 should "correctly parse urls ending with ':' at the end of the string" do
74 assert_equal
75 "some stuff <a href=\"http://google.com/whatever\">http://google.com/whatever</a>:",
63 assert_equal "some stuff <a href=\"http://google.com/whatever\">http://google.com/whatever</a>:",
7664 linkify("some stuff http://google.com/whatever:")
65 end
66 end
67
68 context "when making a user link" do
69 setup do
70 @identica = {
71 'origin' => 'identica',
72 'user' => { 'screen_name' => 'paulv' }
73 }
74
75 @twitter = {
76 'origin' => 'twitter',
77 'user' => { 'screen_name' => 'paulv' }
78 }
79 end
80
81 should "correctly make links to twitter" do
82 assert_equal %q(<b><a href="http://twitter.com/paulv">paulv</a></b>),
83 make_user_link(@twitter)
84 end
85
86 should "correctly make links to identica" do
87 assert_equal %q(<b><a href="http://identi.ca/paulv">paulv</a></b>),
88 make_user_link(@identica)
7789 end
7890 end
7991end
  
5353 <div class="timeline">
5454 <% @data.each do |d| %>
5555 <% if @metadata[ d['origin'] ]['new_since'] >= d['id'] %>
56 <% old = true %>
56 <% old = "old" %>
5757 <% else %>
58 <% old = false %>
58 <% old = "" %>
5959 <% end %>
60 <!-- <%= old %> -->
61 <% if old == true %>
62 <div class="old entry rounded <%= d['user']['screen_name'] %>">
63 <% else %>
64 <div class="entry rounded <%= d['user']['screen_name'] %>">
65 <% end %>
66 <div class="outer">
67 <div class="image">
68 <img src="<%= d['user']['profile_image_url'] %>"
69 height="48" width="48" alt="<%= d['user']['name'] %>"
70 title="<%= d['user']['name'] %>" />
71 <!-- <img src="default_profile_normal.png"
72 height="48" width="48" alt="<%= d['user']['name']%>"
73 title="<%= d['user']['name'] %>"/> -->
74 </div>
75 <div class="middle">
76 <div class="inner text">
77 <% if d['origin'] == "identica" %>
78 <b><a href="http://identi.ca/<%= d['user']['screen_name']%>"><%= d['user']['screen_name'] %></a></b>
79 <% else %>
80 <b><a href="http://twitter.com/<%= d['user']['screen_name']%>"><%= d['user']['screen_name'] %></a></b>
81 <% end %>
82 <% if d['origin'] == "identica" %>
83 <%= identicaify linkify html d['text'] %>
84 <% else %>
85 <%= linkify html d['text'] %>
86 <% end %>
87 </div>
88 </div>
89 </div>
9060
91 <% if old == true %>
92 <div class="footer">
93 <% else %>
94 <div class="footer footer_<%= d['origin'] %>">
95 <% end %>
61 <div class="<%= old %> entry rounded <%= d['user']['screen_name'] %>">
9662
97 <% if d['in_reply_to_status_id'] %>
98 In <a href="/status/<%= d['origin'] %>/<%= d['in_reply_to_status_id'] %>" class="domw_reply_to">reply to</a> <a href="http://twitter.com/<%= d['in_reply_to_screen_name'] %>"><%= d['in_reply_to_screen_name'] %></a>
99 <% end %>
100 Via <%= escape_amp d['source'] %> to <%= d['origin'] %> on
101 <span class="entry_time_text"><%= convert_time_to_est(d['created_at']) %></span> <a href="#" onclick="reply('<%= d['origin'] %>', '<%= d['user']['screen_name'] %>', '<%= d['id'] %>')">r</a>
102 </div>
63 <div class="outer"> <!-- outer -->
10364
104 </div>
65 <div class="image">
66 <img src="<%= d['user']['profile_image_url'] %>"
67 height="48" width="48" alt="<%= d['user']['name'] %>"
68 title="<%= d['user']['name'] %>" />
69 <!-- <img src="default_profile_normal.png"
70 height="48" width="48" alt="<%= d['user']['name']%>"
71 title="<%= d['user']['name'] %>"/> -->
72 </div> <!-- image -->
10573
106 <% end %>
74 <div class="middle">
75 <div class="inner text">
76 <%= make_user_link(d) %>
77 <%= parse_text(d['origin'], d['text']) %>
78 </div> <!-- inner -->
79 </div> <!-- middle -->
10780
108 </div>
81 </div> <!-- outer -->
82
83 <div class="footer footer_<%= d['origin'] %>">
84 <% if d['in_reply_to_status_id'] %>
85 In <a href="/status/<%= d['origin'] %>/<%= d['in_reply_to_status_id'] %>" class="domw_reply_to">reply to</a> <a href="http://twitter.com/<%= d['in_reply_to_screen_name'] %>"><%= d['in_reply_to_screen_name'] %></a>
86 <% end %>
87 Via <%= escape_amp d['source'] %> to <%= d['origin'] %> on
88 <span class="entry_time_text"><%= convert_time_to_est(d['created_at']) %></span> <a href="#" onclick="reply('<%= d['origin'] %>', '<%= d['user']['screen_name'] %>', '<%= d['id'] %>')">r</a>
89 </div> <!-- footer -->
90
91 </div> <!-- entry -->
92 <% end %>
93 </div> <!-- timeline -->
10994 </body>
11095</html>