Module: ExpressAdmin::AdminHelper
- Defined in:
- app/helpers/express_admin/admin_helper.rb
Instance Method Summary collapse
- #admin_javascript_and_css_includes(admin_path = nil) ⇒ Object
- #admin_menus ⇒ Object
- #amount_in_decimal(amount, currency) ⇒ Object
- #app_title ⇒ Object
- #current_engine ⇒ Object
- #current_menu ⇒ Object
- #current_menu_name ⇒ Object
- #current_module ⇒ Object
- #current_module_path_name ⇒ Object
- #current_user_gravatar ⇒ Object
- #description_meta_content ⇒ Object
- #flash_class(key) ⇒ Object
- #is_active?(path) ⇒ Boolean
- #menu_item(name, path) ⇒ Object
- #readable_namespace(namespace) ⇒ Object
- #sign_in_or_sign_out ⇒ Object
- #title_content(content = '', base_title = '') ⇒ Object
- #title_partial ⇒ Object
- #title_partial_or_express_admin ⇒ Object
Instance Method Details
#admin_javascript_and_css_includes(admin_path = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/express_admin/admin_helper.rb', line 75 def admin_javascript_and_css_includes(admin_path = nil) current_module_path = current_module.to_s.underscore addon = Gem.loaded_specs[current_module_path] admin_path ||= addon ? "#{current_module_path}/admin" : "admin" a = [] a << stylesheet_link_tag("#{admin_path}") a << javascript_include_tag("express_admin", 'data-turbolinks-track' => true) a << javascript_include_tag("#{admin_path}", 'data-turbolinks-track' => true) a.join().html_safe end |
#admin_menus ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/express_admin/admin_helper.rb', line 86 def = ExpressAdmin::Engine.all_addons.map do |engine| ExpressAdmin::Menu[engine.addon_name.to_s] rescue nil end.compact .sort do |, | if .position == .position .title <=> .title else .position <=> .position end end = ExpressAdmin::Menu['admin'] rescue nil .unshift if end |
#amount_in_decimal(amount, currency) ⇒ Object
53 54 55 |
# File 'app/helpers/express_admin/admin_helper.rb', line 53 def amount_in_decimal(amount, currency) humanized_money_with_symbol Money.new(amount, currency) end |
#app_title ⇒ Object
67 68 69 |
# File 'app/helpers/express_admin/admin_helper.rb', line 67 def app_title Rails.application.class.parent_name.underscore.titleize end |
#current_engine ⇒ Object
31 32 33 |
# File 'app/helpers/express_admin/admin_helper.rb', line 31 def current_engine "#{current_module}::Engine".constantize end |
#current_menu ⇒ Object
35 36 37 |
# File 'app/helpers/express_admin/admin_helper.rb', line 35 def ExpressAdmin::Menu[current_module_path_name] end |
#current_menu_name ⇒ Object
39 40 41 |
# File 'app/helpers/express_admin/admin_helper.rb', line 39 def .title end |
#current_module ⇒ Object
23 24 25 |
# File 'app/helpers/express_admin/admin_helper.rb', line 23 def current_module controller.class.to_s.split('::').first.constantize end |
#current_module_path_name ⇒ Object
27 28 29 |
# File 'app/helpers/express_admin/admin_helper.rb', line 27 def current_module_path_name current_module.to_s.underscore end |
#current_user_gravatar ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/express_admin/admin_helper.rb', line 43 def current_user_gravatar if defined?(current_user) && !current_user.nil? && !current_user.email.match(/example.com/) gravatar_image_tag current_user.email end end |
#description_meta_content ⇒ Object
71 72 73 |
# File 'app/helpers/express_admin/admin_helper.rb', line 71 def content_for?(:description) ? yield(:description) : 'Testapp' end |
#flash_class(key) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'app/helpers/express_admin/admin_helper.rb', line 116 def flash_class(key) case key when 'notice' then 'info' when 'success' then 'success' when 'alert' then 'warning' when 'error' then 'alert' end end |
#is_active?(path) ⇒ Boolean
108 109 110 111 112 113 114 |
# File 'app/helpers/express_admin/admin_helper.rb', line 108 def is_active?(path) if request.path.eql?(path) "active" else nil end end |
#menu_item(name, path) ⇒ Object
104 105 106 |
# File 'app/helpers/express_admin/admin_helper.rb', line 104 def (name, path) content_tag(:li, link_to(name, path), class: is_active?(path)) end |
#readable_namespace(namespace) ⇒ Object
49 50 51 |
# File 'app/helpers/express_admin/admin_helper.rb', line 49 def readable_namespace(namespace) namespace.demodulize.gsub(/(?<=[a-z])(?=[A-Z])/, ' ') end |
#sign_in_or_sign_out ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/express_admin/admin_helper.rb', line 11 def sign_in_or_sign_out if self.respond_to?(:user_signed_in?) if user_signed_in? link_to main_app.destroy_user_session_path, method: :delete do '<i class="ion-power"></i> Logout'.html_safe end else link_to 'Sign in', main_app.user_session_path end end end |
#title_content(content = '', base_title = '') ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/express_admin/admin_helper.rb', line 57 def title_content(content = '', base_title = '') base_title = base_title.present? ? base_title : app_title if content.present? "#{content} · #{base_title}" else base_title end end |
#title_partial ⇒ Object
3 4 5 |
# File 'app/helpers/express_admin/admin_helper.rb', line 3 def title_partial (ExpressAdmin::Engine.config.title_partial rescue nil) || 'shared/express_admin/title' end |
#title_partial_or_express_admin ⇒ Object
7 8 9 |
# File 'app/helpers/express_admin/admin_helper.rb', line 7 def title_partial_or_express_admin render(title_partial) rescue 'ExpressAdmin' end |