Module: ExternalLinkHelper

Defined in:
app/helpers/external_link_helper.rb

Instance Method Summary collapse

Instance Method Details

#likesObject


68
69
70
71
72
73
74
75
# File 'app/helpers/external_link_helper.rb', line 68

def likes
   :span, class: 'likes' do
    raw %Q(
      <g:plusone size="medium"></g:plusone>
      <a href="https://twitter.com/share" class="twitter-share-button" data-url="#{url_for(only_path: false)}" data-count="horizontal" data-via="#{Whitelabel[:twitter]}" data-lang="#{I18n.locale.downcase}">Tweet</a>
    )
  end
end

20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/external_link_helper.rb', line 20

def link_to_github(user, &block)
  return unless user.github
  url = "http://github.com/#{user.github}"
  title = user.github
  if block_given?
    link_to url, title: title, &block
  else
    link_to(user.github, url, title: title)
  end
end

9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/external_link_helper.rb', line 9

def link_to_twitter(thing, params={clung: false}, &block)
  nick = thing.respond_to?(:twitter) ? thing.twitter : thing
  url = "http://twitter.com/#{nick}"
  if block_given?
    link_to url, title: nick, &block
  else
    link = "@#{link_to(nick, url, title: nick)}"
    raw params[:clung] ? "(#{link})" : link
  end
end

#mailing_list_entries(count = 15) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/external_link_helper.rb', line 36

def mailing_list_entries(count = 15)
  url = mailing_list_feed_url(count)
  response = Feedjira::Feed.fetch_and_parse(url)
  if response.respond_to?(:entries)
    response.entries.first(count)
  else
    []
  end
rescue
  Rails.logger.warn "error fetching feed from #{url}: #{$!}"
  []
end

#mailing_list_feed_url(count) ⇒ Object


49
50
51
52
53
54
55
# File 'app/helpers/external_link_helper.rb', line 49

def mailing_list_feed_url(count)
  if Rails.env.production? || params[:live]
    "https://groups.google.com/forum/feed/#{Whitelabel[:google_group] || 'rubyonrails-ug-germany'}/topics/rss.xml?num=#{count}"
  else
    "file:///#{Rails.root.join('spec/support/data/mailinglist_rss_feed.xml')}"
  end
end

#mailing_list_urlObject


31
32
33
34
# File 'app/helpers/external_link_helper.rb', line 31

def mailing_list_url
  group = Whitelabel[:google_group] || 'rubyonrails-ug-germany'
  "https://groups.google.com/group/#{group}"
end

#ribbon(type) ⇒ Object


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/external_link_helper.rb', line 77

def ribbon(type)
  types = {
    github:                 ["Fork me on GitHub!",  "https://github.com/phoet/on_ruby"],
    senor_developer:        ["SeƱor Developer!",    "http://senordevelopershop.spreadshirt.de"],
    rgsoc:                  ["SUMMER OF CODE",      "http://railsgirlssummerofcode.org/campaign/"],
  }
  text, url = types[type]
   :div, id: "#{type}_ribbon", class: 'ribbon_wrap' do
    link_to url, id: type, title: text do
       :span, text
    end
  end
end

#twitter_update_url(model) ⇒ Object


57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/external_link_helper.rb', line 57

def twitter_update_url(model)
  case model
  when Event
    options = {name: model.name, date: l(model.date, locale: I18n.locale, format: :short), url: event_url(model)}
  when Topic
    options = {username: model.user.name, name: model.name.truncate(50), url: topic_url(model)}
  end
  text = t("#{model.class.to_s.downcase}.twitter_message", options)
  "http://twitter.com/home?status=#{URI.encode(text)}"
end

#wheelmap_badge(location, klass: "wheelmap-status") ⇒ Object


2
3
4
5
6
7
# File 'app/helpers/external_link_helper.rb', line 2

def wheelmap_badge(location, klass: "wheelmap-status")
  url   = location.wheelmap_id.present? ? "http://wheelmap.org/nodes/#{location.wheelmap_id}" : "http://wheelmap.org/nodes/new"
  image = image_tag "https://img.shields.io/wheelmap/a/#{location.wheelmap_id}.svg", class: klass

  link_to image, url
end