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



67
68
69
70
71
72
73
74
75
# File 'app/helpers/express_admin/admin_helper.rb', line 67

def admin_javascript_and_css_includes(admin_path = nil)
  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}")
  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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/helpers/express_admin/admin_helper.rb', line 77

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



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

def amount_in_decimal(amount, currency)
  humanized_money_with_symbol Money.new(amount, currency)
end

#current_engine ⇒ Object



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

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

#current_menu ⇒ Object



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_name ⇒ Object



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

def current_menu_name
  current_menu.title
end

#current_module ⇒ Object



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_name ⇒ Object



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_gravatar ⇒ Object



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_content ⇒ Object



63
64
65
# File 'app/helpers/express_admin/admin_helper.rb', line 63

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

#flash_class(key) ⇒ Object



107
108
109
110
111
112
113
114
# File 'app/helpers/express_admin/admin_helper.rb', line 107

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)


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

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


95
96
97
# File 'app/helpers/express_admin/admin_helper.rb', line 95

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

#readable_namespace(namespace) ⇒ Object



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

def readable_namespace(namespace)
  namespace.demodulize.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')
end

#sign_in_or_sign_out ⇒ Object



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_content ⇒ Object



59
60
61
# File 'app/helpers/express_admin/admin_helper.rb', line 59

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

#title_partial ⇒ Object

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_admin ⇒ Object



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