Commit a6c0d0ad734794754679b4ff57744e55d3b05c79
- Diff rendering mode:
- inline
- side by side
coefficient.rb
(13 / 6)
|   | |||
| 30 | 30 | @@config = YAML.load_file ENV['HOME'] + "/.coefficient.yml" | |
| 31 | 31 | end | |
| 32 | 32 | ||
| 33 | def make_user_link(data) | ||
| 34 | origin = data['origin'] | ||
| 35 | name = data['user']['screen_name'] | ||
| 36 | string = %Q(<b><a href="#{@@sites[origin]['url']}#{name}">#{name}</a></b>) | ||
| 33 | def make_user_link(origin, name) | ||
| 34 | # origin = data['origin'] | ||
| 35 | # name = data['user']['screen_name'] | ||
| 36 | string = %Q(<a href="#{@@sites[origin]['url']}#{name}">#{name}</a>) | ||
| 37 | 37 | return string | |
| 38 | 38 | end | |
| 39 | 39 | ||
| … | … | ||
| 41 | 41 | if origin == "identica" | |
| 42 | 42 | return identicaify linkify html text | |
| 43 | 43 | else | |
| 44 | return linkify html text | ||
| 44 | return twitterify linkify html text | ||
| 45 | 45 | end | |
| 46 | 46 | end | |
| 47 | 47 | ||
| … | … | ||
| 57 | 57 | gsub("\"", """) | |
| 58 | 58 | end | |
| 59 | 59 | ||
| 60 | def twitterify(text) | ||
| 61 | new = text.dup | ||
| 62 | new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://twitter.com/\1">\1</a>') | ||
| 63 | return new | ||
| 64 | end | ||
| 65 | |||
| 60 | 66 | def linkify(text) | |
| 61 | 67 | new = text.dup | |
| 62 | 68 | # XXX this shouldn't work if . is the last character in the or | |
| … | … | ||
| 72 | 72 | ||
| 73 | 73 | # maybe laconica-0.7.3/lib/util.php:common_replace_urls_callback() ? | |
| 74 | 74 | new.gsub!(/(https?:\/\/([a-zA-Z0-9_%\-+?#\/,=]|&(?!quot;)|\.(?!\z|\s))+)/, '<a href="\1">\1</a>') | |
| 75 | new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://twitter.com/\1">\1</a>') | ||
| 76 | 75 | return new | |
| 77 | 76 | end | |
| 78 | 77 | ||
| … | … | ||
| 89 | 89 | # hashtag regexp in laconica is /(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/ | |
| 90 | 90 | # #YouTwitFace." breaks it. | |
| 91 | 91 | # text is: Conan's #Tonight_Show: "In the year 3000 #Facebook, #Twitter, and #YouTube merge to form the largest time-wasting site ever: #YouTwitFace." | |
| 92 | |||
| 93 | new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://identi.ca/\1">\1</a>') | ||
| 92 | 94 | ||
| 93 | 95 | new.gsub!(/(^|\s)#(?:(?!39;)([A-Za-z0-9_\-]+|\.(?!\z|\s)))/, '\1#<a href="http://identi.ca/tag/\2">\2</a>') | |
| 94 | 96 |
tests/unit.rb
(4 / 4)
|   | |||
| 98 | 98 | end | |
| 99 | 99 | ||
| 100 | 100 | should "correctly make links to twitter" do | |
| 101 | assert_equal %q(<b><a href="http://twitter.com/paulv">paulv</a></b>), | ||
| 102 | make_user_link(@twitter) | ||
| 101 | assert_equal %q(<a href="http://twitter.com/paulv">paulv</a>), | ||
| 102 | make_user_link(@twitter['origin'], @twitter['user']['screen_name']) | ||
| 103 | 103 | end | |
| 104 | 104 | ||
| 105 | 105 | should "correctly make links to identica" do | |
| 106 | assert_equal %q(<b><a href="http://identi.ca/paulv">paulv</a></b>), | ||
| 107 | make_user_link(@identica) | ||
| 106 | assert_equal %q(<a href="http://identi.ca/paulv">paulv</a>), | ||
| 107 | make_user_link(@identica['origin'], @identica['user']['screen_name']) | ||
| 108 | 108 | end | |
| 109 | 109 | end | |
| 110 | 110 |
views/timeline.html.erb
(2 / 2)
|   | |||
| 74 | 74 | </div> <!-- image --> | |
| 75 | 75 | ||
| 76 | 76 | <div> <!-- text --> | |
| 77 | <%= make_user_link(d) %> | ||
| 77 | <b><%= make_user_link(d['origin'], d['user']['screen_name']) %></b> | ||
| 78 | 78 | <%= parse_text(d['origin'], d['text']) %> | |
| 79 | 79 | </div> <!-- text --> | |
| 80 | 80 | ||
| … | … | ||
| 82 | 82 | ||
| 83 | 83 | <div class="footer footer_<%= d['origin'] %>"> | |
| 84 | 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> | ||
| 85 | In <a href="/status/<%= d['origin'] %>/<%= d['in_reply_to_status_id'] %>" class="domw_reply_to">reply to</a> <%= make_user_link(d['origin'], d['in_reply_to_screen_name']) %> | ||
| 86 | 86 | <% end %> | |
| 87 | 87 | Via <%= escape_amp d['source'] %> to <%= d['origin'] %> on | |
| 88 | 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> |

