aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
blob: 61382fce2e49980dec8f14bd86163ba13191a4d1 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- encoding: utf-8 -*-
module ApplicationHelper
  def format_time(dt)
    dt.to_time.localtime("+09:00").strftime("%Y-%m-%d %H:%M:%S")
  end

  def format_tweet_text(text)
    ret = text.gsub(/<([a-z]+?)(?<!\\):(.+?)(?:(?<!\\):(.+?))?>/) do
      case $1
      when "mention"
        screen_name = CGI.unescape($2)
        link_to("@#{screen_name}", "/#{screen_name}")
      when "url"
        n = [$3, $2.gsub(/(https?)%3A/, "\\1:")].map {|m| m.gsub("\\:", ":") }
        link_to(*n)
      when "hashtag"
        hashtag = CGI.unescape($2)
        link_to("##{hashtag}", "https://twitter.com/search?q=#{CGI.escape("##{hashtag}")}")
      when "symbol"
        symbol = CGI.unescape($2)
        link_to("$#{symbol}", "https://twitter.com/search?q=#{CGI.escape("$#{symbol}")}")
      else
        $&
      end
    end
    return ret
  end
  alias format_source_text format_tweet_text


  def title(*args)
    content_for :title do
      (args.compact + ["aclog"]).join(" - ")
    end
  end

  def caption(text)
    content_for :caption do
      text
    end
  end

  def sidebar(name)
    content_for :sidebar do
      render "shared/sidebar/#{name}"
    end
  end

  # utf8, form
  def utf8_enforcer_tag; raw "" end
end