-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathapplication_helper.rb
99 lines (77 loc) · 2.51 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true
module ApplicationHelper
def cache_image_path(model)
options = {
timestamp: model.updated_at.to_i,
model_name: model.class,
model_id: model.id,
filename: "#{model.slug}.png",
}
image_dispatch_path(options)
end
def login_providers
%w[twitter github google_oauth2 email]
end
def icon_for_provider(provider)
return 'envelope' if provider == 'email'
provider
end
def whitelabel_stylesheet_link_tag
link = "labels/#{Whitelabel[:label_id]}"
stylesheet_link_tag link if File.exist? Rails.root.join("app/assets/stylesheets/#{link}.sass")
end
def whitelabel_javascript_include_tag
link = "labels/#{Whitelabel[:label_id]}"
labels = Rails.root.join('app/assets/javascripts/labels').entries.map(&:to_s)
javascript_include_tag link if labels.any? { |path| path.to_s =~ /#{Whitelabel[:label_id]}/ }
end
def label_auth_url(provider)
host = Rails.env.development? ? "http://#{Whitelabel[:label_id]}.onruby.localhost:3000" : Whitelabel[:canonical_url]
"#{host}/auth/#{provider}?origin=#{CGI.escape(params[:origin]) if params[:origin]}"
end
def label_url(label)
host = Rails.env.development? ? "#{label.label_id}.onruby.localhost" : label.canonical_url
root_url(host:)
end
def canonical_url
host = Whitelabel.label ? Whitelabel[:canonical_url] : 'https://www.onruby.eu'
tag.link rel: :canonical, href: url_for(host:, only_path: false)
end
def browser_icon
icon 'shortcut icon'
end
def touch_icon
icon 'apple-touch-icon-precomposed'
end
def rss_feed
auto_discovery_link_tag :rss, events_path(format: :xml), title: 'Event-Feed'
end
def icon(type)
path = image_path Whitelabel.label ? "labels/#{Whitelabel[:label_id]}.ico" : 'favicon.ico'
tag.link rel: type, href: path
end
def markdown(content)
return nil unless content
content = markdown_parser.render(content).html_safe
tag.div(content, class: :markdown)
end
def section_box(name)
tag.section(class: "#{name} clearfix", id: name) do
concat tag.h2(fa_icon(name, text: t("main.#{name}")))
yield
end
end
def hint(close = true)
tag.section(class: :hint) do
concat tag.div(link_to(t('hint.close'), '#'), class: :close) if close
yield
end
end
def user_name(user)
user.missing_name? ? '-' : user.name
end
private
def markdown_parser
@markdown_parser ||= Redcarpet::Markdown.new Redcarpet::Render::Safe, autolink: true, space_after_headers: true
end
end