require 'redcarpet'
module ShopappHelper
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
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
#{link_text}
HTML
<<~HTML2.html_safe
#{ link_to(full_link_text, url_path, class: link_class_list)}
HTML2
end
def secondary_menu(title, &block)
<<~HTML2.html_safe
#{link_text}
HTML
end
def search_placeholder
controller.search_placeholder || "Search..."
end
def search_remote
controller.search_remote
end
def search_path
if controller.class.search_path == :current_path
request.path
else
"#{controller.class.search_path || '/'}"
end
end
def sidebar_item(url, text, dropdown, icon)
<<~HTML.html_safe
-
#{icon}
#{text}
HTML
end
def markdown_safe(text)
@markdown ||= markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
@markdown.render(text).html_safe
end
end