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 = <<~HTML.html_safe
    <i class="fa fa-#{icon}"></i>
    #{link_text}
  HTML
  <<~HTML2.html_safe
    <li class="nav-item">#{ link_to(full_link_text, url_path, class: link_class_list)}</li>
  HTML2
end

#markdown_safe(text) ⇒ Object



84
85
86
87
# File 'app/helpers/shopapp_helper.rb', line 84

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

#search_pathObject



61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/shopapp_helper.rb', line 61

def search_path
  if controller.search_path == :current_path
    request.path
  elsif controller.search_path.present?
    "#{controller.search_path || '/'}"
  elsif 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 || controller.class.search_placeholder || "Search..."
end

#search_remoteObject



57
58
59
# File 'app/helpers/shopapp_helper.rb', line 57

def search_remote
  controller.search_remote
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)
  <<~HTML2.html_safe
    <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
      <span>#{title}</span>
    </h6>
    <ul class="nav flex-column mb-2>
      #{capture &block}
    </ul>
  HTML2
end


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

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


73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/shopapp_helper.rb', line 73

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

#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