Module: Bookends::ApplicationHelper
- Defined in:
- app/helpers/bookends/application_helper.rb
Instance Method Summary collapse
- #avatar_url(email) ⇒ Object
- #glostick_user_email ⇒ Object
- #glostick_user_id ⇒ Object
- #glostick_user_name ⇒ Object
- #header_search_input ⇒ Object
- #hero_class ⇒ Object
- #link_to_new_window(text, link, options = {}) ⇒ Object
- #logged_in? ⇒ Boolean
- #relative_search_path ⇒ Object
- #search_disabled? ⇒ Boolean
-
#signup_link(title, ga_label: nil, **options) ⇒ Object
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).
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_email ⇒ Object
30 31 32 |
# File 'app/helpers/bookends/application_helper.rb', line 30 def glostick_user_email glostick_user['email'] end |
#glostick_user_id ⇒ Object
34 35 36 |
# File 'app/helpers/bookends/application_helper.rb', line 34 def glostick_user_id glostick_user['id'] end |
#glostick_user_name ⇒ Object
26 27 28 |
# File 'app/helpers/bookends/application_helper.rb', line 26 def glostick_user_name glostick_user['full_name'] end |
#header_search_input ⇒ Object
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_class ⇒ Object
55 56 57 |
# File 'app/helpers/bookends/application_helper.rb', line 55 def hero_class #to be overriden by consumers, optionally end |
#link_to_new_window(text, link, options = {}) ⇒ Object
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, = {}) words = text.split(' ') link_to( link, { aria: { label: "#{text} (Opens in new window)" }, target: '_blank' }.merge!() ) do concat(words[0..-2].join(' ')) if words.length > 1 concat(' ') end concat(content_tag(:span, class: 'new-window-icon') do words[-1] end) end end |
#logged_in? ⇒ Boolean
22 23 24 |
# File 'app/helpers/bookends/application_helper.rb', line 22 def logged_in? !![:heroku_session] end |
#relative_search_path ⇒ Object
5 6 7 |
# File 'app/helpers/bookends/application_helper.rb', line 5 def relative_search_path '/search' end |
#search_disabled? ⇒ Boolean
9 10 11 |
# File 'app/helpers/bookends/application_helper.rb', line 9 def search_disabled? false end |
#signup_link(title, ga_label: nil, **options) ⇒ Object
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 signup_link(title, ga_label: nil, **) url = 'https://signup.heroku.com' url += "/#{[:signup_path]}" if [:signup_path] if [:redirect_url] params = { 'redirect-url' => [:redirect_url] } url << "?#{params.to_query}" end data = { trackable: { category: 'Sign Up Links', action: 'Clicked', label: ga_label } } link_to title, url, class: [:class], data: data end |