Commit ae1d201628293581becbed17ee8637d452c016de
- Diff rendering mode:
- inline
- side by side
coefficient.rb
(15 / 1)
|   | |||
| 31 | 31 | puts "loaded credentials: #{@@config['credentials']['username']}, **********" | |
| 32 | 32 | end | |
| 33 | 33 | ||
| 34 | def 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 | ||
| 39 | end | ||
| 40 | |||
| 41 | def parse_text(origin, text) | ||
| 42 | if origin == "identica" | ||
| 43 | return identicaify linkify html text | ||
| 44 | else | ||
| 45 | return linkify html text | ||
| 46 | end | ||
| 47 | end | ||
| 48 | |||
| 34 | 49 | def escape_amp(text) | |
| 35 | 50 | return text.gsub(/&(?!(amp|lt|gt|#39|quot);)/, "&") | |
| 36 | 51 | end | |
| … | … | ||
| 57 | 57 | gsub("'", "'"). | |
| 58 | 58 | gsub("\"", """) | |
| 59 | 59 | end | |
| 60 | |||
| 61 | 60 | ||
| 62 | 61 | def linkify(text) | |
| 63 | 62 | new = text.dup |
tests/unit.rb
(37 / 25)
|   | |||
| 3 | 3 | require 'shoulda' | |
| 4 | 4 | ||
| 5 | 5 | class UnitTests < Test::Unit::TestCase | |
| 6 | context "correctly parse urls" do | ||
| 6 | context "linkify" do | ||
| 7 | 7 | 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>", | ||
| 10 | 9 | linkify("http://www.google.com") | |
| 11 | 10 | end | |
| 12 | 11 | ||
| 13 | 12 | 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>", | ||
| 16 | 14 | linkify("http://www.google.com/") | |
| 17 | 15 | end | |
| 18 | 16 | ||
| 19 | 17 | 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>", | ||
| 22 | 19 | linkify("https://www.google.com/") | |
| 23 | 20 | end | |
| 24 | 21 | ||
| 25 | 22 | 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>", | ||
| 28 | 24 | linkify("https://www.google.com/link.html") | |
| 29 | 25 | end | |
| 30 | 26 | ||
| 31 | 27 | 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>", | ||
| 34 | 29 | linkify("https://www.google.com/?whatever.com") | |
| 35 | 30 | end | |
| 36 | 31 | ||
| 37 | 32 | 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", | ||
| 40 | 34 | linkify("blah blah https://www.google.com/. Blah") | |
| 41 | 35 | end | |
| 42 | 36 | ||
| 43 | 37 | 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>.", | ||
| 46 | 39 | linkify("blah blah https://www.google.com/.") | |
| 47 | 40 | end | |
| 48 | 41 | ||
| 49 | 42 | 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>", | ||
| 52 | 44 | linkify("https://www.google.com/#anchor") | |
| 53 | 45 | end | |
| 54 | 46 | ||
| 55 | 47 | 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>", | ||
| 58 | 49 | linkify("https://www.google.com/+stuff") | |
| 59 | 50 | end | |
| 60 | 51 | ||
| 61 | 52 | 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>", | ||
| 64 | 54 | linkify("http://www.hypebot.com/hypebot/2009/06/walmart-shutting-down-drm-download-servers.html") | |
| 65 | 55 | end | |
| 66 | 56 | ||
| 67 | 57 | 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", | ||
| 70 | 59 | linkify("some stuff http://google.com/whatever: stuff") | |
| 71 | 60 | end | |
| 72 | 61 | ||
| 73 | 62 | 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>:", | ||
| 76 | 64 | 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) | ||
| 77 | 89 | end | |
| 78 | 90 | end | |
| 79 | 91 | end |
views/timeline.html.erb
(31 / 46)
|   | |||
| 53 | 53 | <div class="timeline"> | |
| 54 | 54 | <% @data.each do |d| %> | |
| 55 | 55 | <% if @metadata[ d['origin'] ]['new_since'] >= d['id'] %> | |
| 56 | <% old = true %> | ||
| 56 | <% old = "old" %> | ||
| 57 | 57 | <% else %> | |
| 58 | <% old = false %> | ||
| 58 | <% old = "" %> | ||
| 59 | 59 | <% 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> | ||
| 90 | 60 | ||
| 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'] %>"> | ||
| 96 | 62 | ||
| 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 --> | ||
| 103 | 64 | ||
| 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 --> | ||
| 105 | 73 | ||
| 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 --> | ||
| 107 | 80 | ||
| 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 --> | ||
| 109 | 94 | </body> | |
| 110 | 95 | </html> |

