Module: ExpressAdmin::AdminHelper

Defined in:
app/helpers/express_admin/admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_javascript_and_css_includesObject



59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/express_admin/admin_helper.rb', line 59

def admin_javascript_and_css_includes
  current_module_path = current_module.to_s.underscore
  admin_path = current_module_path.eql?('admin') ? "admin" : "#{current_module_path}/admin"
  a = []
  a << stylesheet_link_tag("#{admin_path}/application")
  a << stylesheet_link_tag("app_express/admin/application") if defined?(AppExpress)
  a << javascript_include_tag("express_admin", 'data-turbolinks-track' => true)
  a << javascript_include_tag("#{admin_path}/application", 'data-turbolinks-track' => true)
  a.join().html_safe
end

#admin_menusObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/express_admin/admin_helper.rb', line 70

def admin_menus
  menus = ExpressAdmin::Engine.all_addons.map do |engine|
    ExpressAdmin::Menu[engine.addon_name.to_s] rescue nil
  end.compact

  menus.sort do |menuA, menuB|
    if menuA.position == menuB.position
      menuA.title <=> menuB.title
    else
      menuA.position <=> menuB.position
    end
  end

  application_menu = ExpressAdmin::Menu['admin'] rescue nil
  menus.unshift application_menu if application_menu
  menus
end

#current_engineObject



33
34
35
# File 'app/helpers/express_admin/admin_helper.rb', line 33

def current_engine
  "#{current_module}::Engine".constantize
end

#current_menuObject



37
38
39
# File 'app/helpers/express_admin/admin_helper.rb', line 37

def current_menu
  ExpressAdmin::Menu[current_module_path_name]
end

#current_menu_nameObject



41
42
43
# File 'app/helpers/express_admin/admin_helper.rb', line 41

def current_menu_name
  current_menu.title
end

#current_moduleObject



25
26
27
# File 'app/helpers/express_admin/admin_helper.rb', line 25

def current_module
  controller.class.to_s.split('::').first.constantize
end

#current_module_path_nameObject



29
30
31
# File 'app/helpers/express_admin/admin_helper.rb', line 29

def current_module_path_name
  current_module.to_s.underscore
end

#current_user_gravatarObject



45
46
47
48
49
# File 'app/helpers/express_admin/admin_helper.rb', line 45

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_contentObject



55
56
57
# File 'app/helpers/express_admin/admin_helper.rb', line 55

def description_meta_content
  content_for?(:description) ? yield(:description) : 'Testapp'
end

#flash_class(key) ⇒ Object



100
101
102
103
104
105
106
107
# File 'app/helpers/express_admin/admin_helper.rb', line 100

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



92
93
94
95
96
97
98
# File 'app/helpers/express_admin/admin_helper.rb', line 92

def is_active?(path)
  if request.path.eql?(path)
    "active"
  else
    nil
  end
end


88
89
90
# File 'app/helpers/express_admin/admin_helper.rb', line 88

def menu_item(name, path)
  (:li, link_to(name, path), class: is_active?(path))
end

#sign_in_or_sign_outObject



15
16
17
18
19
20
21
22
23
# File 'app/helpers/express_admin/admin_helper.rb', line 15

def 
  if self.respond_to?(:user_signed_in?)
    if user_signed_in?
      link_to 'Logout', main_app.destroy_user_session_path, method: :delete
    else
      link_to 'Sign in', main_app.user_session_path
    end
  end
end

#title_contentObject



51
52
53
# File 'app/helpers/express_admin/admin_helper.rb', line 51

def title_content
  content_for?(:title) ? yield(:title) : Rails.application.class.parent_name.underscore.titleize
end

#title_partialObject

TODO move this out include ExpressMedia::Admin::MediaHelper if Kernel.const_defined?("ExpressMedia::Engine")



7
8
9
# File 'app/helpers/express_admin/admin_helper.rb', line 7

def title_partial
  (ExpressAdmin::Engine.config.title_partial rescue nil) || 'shared/express_admin/title'
end

#title_partial_or_express_adminObject



11
12
13
# File 'app/helpers/express_admin/admin_helper.rb', line 11

def title_partial_or_express_admin
  render(title_partial) rescue 'ExpressAdmin'
end