Module: MnoEnterprise::ApplicationHelper

Included in:
ApplicationController
Defined in:
app/helpers/mno_enterprise/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#alert_hash(alert) ⇒ Object



51
52
53
54
55
56
57
58
# File 'app/helpers/mno_enterprise/application_helper.rb', line 51

def alert_hash(alert)
  return {} unless alert
  {
    type:'danger',
    msg: (alert || '').html_safe,
    timeout: -1
  }
end

#authenticate_user!(_favourite = nil, opts = {}) ⇒ Object

Re-implement Devise filter For some reasons the original Devise filter seems to ignore the mnoe prefix when using custom devise controllers



11
12
13
14
# File 'app/helpers/mno_enterprise/application_helper.rb', line 11

def authenticate_user!(_favourite=nil, opts={})
  redirect_to(new_user_session_path) unless current_user
  true
end

#authenticate_user_or_signup!Object

Redirect to signup page if user not authenticated



26
27
28
29
30
31
32
33
# File 'app/helpers/mno_enterprise/application_helper.rb', line 26

def authenticate_user_or_signup!
  unless current_user
    redirect_to new_user_registration_path
    false
  end

  true
end

#avatar_url(user) ⇒ Object

Return the user avatar url. The displayed picture use the gravatar of the user email TODO: add and use avatar_email from the OAUTH user



69
70
71
# File 'app/helpers/mno_enterprise/application_helper.rb', line 69

def avatar_url(user)
  gravatar_url(user.email)
end

#gravatar_url(email) ⇒ Object

Return the gravatar url for the given email



74
75
76
77
78
79
# File 'app/helpers/mno_enterprise/application_helper.rb', line 74

def gravatar_url(email)
  if email
    gravatar_id = Digest::MD5.hexdigest(email.downcase)
    "https://gravatar.com/avatar/#{gravatar_id}.png?s=50&d=mm"
  end
end

#markdown(text) ⇒ Object

This helper converts markdown content to html, using the HtmlProcessor (see /lib)



62
63
64
65
# File 'app/helpers/mno_enterprise/application_helper.rb', line 62

def markdown(text)
  return text unless text.present?
  HtmlProcessor.new(text, format: :markdown).html.html_safe
end

#notice_hash(notice) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/mno_enterprise/application_helper.rb', line 35

def notice_hash(notice)
  return {} unless notice
  # TODO: refactor
  auto_close = (notice =~ /signed (in|out)/i ? 5*1000 : nil)
  # Check if a timeout has been defined in flash
  unless auto_close
    auto_close = flash[:flash_options][:timeout] if flash[:flash_options] && flash[:flash_options][:timeout]
  end

  {
    type:'success',
    msg: (notice || '').html_safe,
    timeout: auto_close
  }
end

#redirect_to_lounge_if_unconfirmedObject

Redirect a signed in user to the confirmation lounge if unconfirmed



18
19
20
21
22
23
# File 'app/helpers/mno_enterprise/application_helper.rb', line 18

def redirect_to_lounge_if_unconfirmed
  if current_user && !current_user.confirmed?
    redirect_to user_confirmation_lounge_path
  end
  return true
end

#support_emailObject



4
5
6
# File 'app/helpers/mno_enterprise/application_helper.rb', line 4

def support_email
  MnoEnterprise.support_email
end