Module: AdminTools::Helper
- Defined in:
- lib/admin_tools/helper.rb
Instance Method Summary collapse
-
#admin_tool(class_name = "", element = nil, **options) { ... } ⇒ Object
Renders content only for admin users.
-
#admin_tool_if(condition, *args, **options) { ... } ⇒ Object
Conditionally renders content for admins only based on a condition.
-
#admin_tools_visible? ⇒ Boolean
Returns whether admin tools should be visible to the current user.
Instance Method Details
#admin_tool(class_name = "", element = nil, **options) { ... } ⇒ Object
Renders content only for admin users
32 33 34 35 36 37 38 39 |
# File 'lib/admin_tools/helper.rb', line 32 def admin_tool(class_name = "", element = nil, **, &block) return unless admin_tools_visible? element ||= AdminTools.configuration.wrapper_element css_classes = [AdminTools.configuration.css_class, class_name].reject(&:blank?).join(" ") concat content_tag(element, class: css_classes, **, &block) end |
#admin_tool_if(condition, *args, **options) { ... } ⇒ Object
Conditionally renders content for admins only based on a condition
If condition is false, content is shown to ALL users. If condition is true, content is only shown to admins.
56 57 58 59 60 |
# File 'lib/admin_tools/helper.rb', line 56 def admin_tool_if(condition, *args, **, &block) yield and return unless condition admin_tool(*args, **, &block) end |
#admin_tools_visible? ⇒ Boolean
Returns whether admin tools should be visible to the current user
66 67 68 69 70 71 72 73 |
# File 'lib/admin_tools/helper.rb', line 66 def admin_tools_visible? user = send(AdminTools.configuration.current_user_method) return false if user.nil? user.send(AdminTools.configuration.admin_method) rescue NoMethodError false end |