/
application_helper.rb
63 lines (51 loc) · 1.74 KB
/
application_helper.rb
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
52
53
54
55
56
57
58
59
60
61
62
63
module ApplicationHelper
def escape_language(lang)
url_encode(lang.downcase) if lang
end
def parameterize_language(lang)
lang.gsub(/\+/, 'p').gsub(/\#/, 'sharp').parameterize if lang
end
def language_link(language, label = nil)
language = if language.respond_to? :map
language.map(&method(:escape_language))
else
escape_language language
end
label ||= [language].flatten.join(', ')
link_to label, '#', data: { language: language }
end
def github_button(nickname)
%(<iframe src="https://ghbtns.com/github-btn.html?user=#{nickname}&type=follow&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="300" height="20"></iframe>).html_safe
end
def contributors_in(year)
Contribution.year(year).load.map(&:user_id).uniq.length
end
def contributions_in(year)
Contribution.year(year).count
end
def projects_in(year)
Contribution.year(year).select(:repo_name).map(&:repo_name).uniq.count
end
def current_path(locale = nil)
path = request.env['REQUEST_PATH']
path += "?locale=#{locale}" if locale.present?
path
end
def available_locales
%w(en es el pt_br fi fr de ru uk th it nb ta tr zh_Hans zh_Hant ja cs hi pl)
end
def current_translations
@translations ||= I18n.backend.send(:translations)
@translations[I18n.locale].with_indifferent_access
end
def mastodon_url
'https://mastodon.social/@24pullrequests'
end
def unconfirmed_email?
logged_in? && current_user.unconfirmed?
end
def format_markdown(str)
return '' if str.blank?
CommonMarker.render_html(str, :GITHUB_PRE_LANG, [:tagfilter, :autolink, :table, :strikethrough]).gsub(/(\\n|\\r)/, '<br>').html_safe
end
end