Module: ShopappHelper

Defined in:
app/helpers/shopapp_helper.rb

Instance Method Summary collapse

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/shopapp_helper.rb', line 13

def main_menu_link(url_path, link_text: nil, icon: nil)
  link_class_list = 'nav-link'
  link_class_list << ' active' if request.original_url.include? url_path.to_s
  link_text ||= url_path.to_s.capitalize

  full_link_text = "    <i class=\"fa fa-\#{icon}\"></i>\n    \#{link_text}\n  HTML\n  <<~HTML2.html_safe\n    <li class=\"nav-item\">\#{ link_to(full_link_text, url_path, class: link_class_list)}</li>\n  HTML2\nend\n".html_safe

#markdown_safe(text) ⇒ Object



76
77
78
79
# File 'app/helpers/shopapp_helper.rb', line 76

def markdown_safe(text)
  @markdown ||= markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
  @markdown.render(text).html_safe
end

#search_pathObject



57
58
59
60
61
62
63
# File 'app/helpers/shopapp_helper.rb', line 57

def search_path
  if controller.class.search_path == :current_path
    request.path
  else
    "#{controller.class.search_path || '/'}"
  end
end

#search_placeholderObject



53
54
55
# File 'app/helpers/shopapp_helper.rb', line 53

def search_placeholder
  controller.search_placeholder || "Search..."
end

#secondary_menu(title, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/shopapp_helper.rb', line 27

def secondary_menu(title, &block)
  "    <h6 class=\"sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted\">\n      <span>\#{title}</span>\n    </h6>\n    <ul class=\"nav flex-column mb-2>\n      \#{capture &block}\n    </ul>\n  HTML2\nend\n".html_safe


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/shopapp_helper.rb', line 38

def secondary_menu_link(url_path, link_text: nil, icon: nil)
  link_text ||= url_path.to_s.capitalize
  link_class_list = 'nav-link'
  link_class_list << ' active' if request.original_url.include? url_path.to_s

  "    <li class=\"nav-item\">\n      <a class=\"\#{link_class_list}\" href=\"\#{url_path}\">\n        <i class=\"fa fa-\#{icon}\"></i>\n        \#{link_text}\n      </a>\n    </li>\n  HTML\nend\n".html_safe


65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/shopapp_helper.rb', line 65

def sidebar_item(url, text, dropdown, icon)
  "    <li class=\"nav-item\">\n      <a class=\"nav-link \#{'active' if request.path.starts_with? url}\" href=\"\#{url}\">\n        <i class=\"material-icons\">\#{icon}</i>\n        \#{text}\n      </a>\n    </li>\n  HTML\nend\n".html_safe

#user_allowed?(scope) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'app/helpers/shopapp_helper.rb', line 4

def user_allowed?(scope)
  unless @current_user['scopes'].is_a? String
    user_scopes = @current_user['scopes']
  else
    user_scopes = JSON.parse @current_user['scopes']
  end
  user_scopes.include?('admin') || user_scopes.include?(scope.to_s)
end