Module: Bookends::ApplicationHelper

Defined in:
app/helpers/bookends/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#avatar_url(email) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/bookends/application_helper.rb', line 59

def avatar_url(email)
  default_avatar_url = 'https://www.herokucdn.com/images/ninja-avatar-48x48.png'
  return default_avatar_url unless email

  gravatar_url = 'https://gravatar.com/avatar'
  hashed_email = Digest::MD5.hexdigest(email)
  size = 48

  "#{gravatar_url}/#{hashed_email}?s=#{size}&d=#{default_avatar_url}"
end

#glostick_user_emailObject



30
31
32
# File 'app/helpers/bookends/application_helper.rb', line 30

def glostick_user_email
  glostick_user['email']
end

#glostick_user_idObject



34
35
36
# File 'app/helpers/bookends/application_helper.rb', line 34

def glostick_user_id
  glostick_user['id']
end

#glostick_user_nameObject



26
27
28
# File 'app/helpers/bookends/application_helper.rb', line 26

def glostick_user_name
  glostick_user['full_name']
end

#header_search_inputObject



13
14
15
16
17
18
19
20
# File 'app/helpers/bookends/application_helper.rb', line 13

def header_search_input
  tag 'input',
    type: 'text',
    spellcheck: 'false',
    autocomplete: 'off',
    name: 'q',
    title: 'search'
end

#hero_classObject



55
56
57
# File 'app/helpers/bookends/application_helper.rb', line 55

def hero_class
  #to be overriden by consumers, optionally
end


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/bookends/application_helper.rb', line 70

def link_to_new_window(text, link, options = {})
  words = text.split(' ')
  link_to(
    link, {
      aria: { label: "#{text} (Opens in new window)" },
      target: '_blank'
    }.merge!(options)
  ) do
    concat(words[0..-2].join(' '))
    if words.length > 1
      concat(' ')
    end
    concat((:span, class: 'new-window-icon') do
      words[-1]
    end)
  end
end

#logged_in?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/helpers/bookends/application_helper.rb', line 22

def logged_in?
  !!cookies[:heroku_session]
end

#relative_search_pathObject



5
6
7
# File 'app/helpers/bookends/application_helper.rb', line 5

def relative_search_path
  '/search'
end

#search_disabled?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/helpers/bookends/application_helper.rb', line 9

def search_disabled?
  false
end

Available options:

  • class: classes to be set in the class HTML attribute

  • redirect_url: will be inserted as a redirect-url param in the signup URL

  • signup_path: will be appended to the signup URL (e.g: signup_path “ruby” will generate a link to signup.h.c/ruby)



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/bookends/application_helper.rb', line 42

def (title, ga_label: nil, **options)
  url = 'https://signup.heroku.com'
  url += "/#{options[:signup_path]}" if options[:signup_path]

  if options[:redirect_url]
    params = { 'redirect-url' => options[:redirect_url] }
    url << "?#{params.to_query}"
  end

  data = { trackable: { category: 'Sign Up Links', action: 'Clicked', label: ga_label } }
  link_to title, url, class: options[:class], data: data
end