Module: ExpressAdmin::AdminHelper

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

Instance Method Summary collapse

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_menusObject



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 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

#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_titleObject



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_engineObject



31
32
33
# File 'app/helpers/express_admin/admin_helper.rb', line 31

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

#current_menuObject



35
36
37
# File 'app/helpers/express_admin/admin_helper.rb', line 35

def current_menu
  ExpressAdmin::Menu[current_module_path_name]
end

#current_menu_nameObject



39
40
41
# File 'app/helpers/express_admin/admin_helper.rb', line 39

def current_menu_name
  current_menu.title
end

#current_moduleObject



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_nameObject



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_gravatarObject



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_contentObject



71
72
73
# File 'app/helpers/express_admin/admin_helper.rb', line 71

def description_meta_content
  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

Returns:

  • (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


104
105
106
# File 'app/helpers/express_admin/admin_helper.rb', line 104

def menu_item(name, path)
  (: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_outObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/express_admin/admin_helper.rb', line 11

def 
  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>&nbsp;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_partialObject



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_adminObject



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