Sha256: acfc932abd88f99d20ff3537cf2cf2ff5c24466dc460eac02427fd6e0a95f3c5

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 KB

Contents

module Guts
  # Common helpers for the whole application
  module ApplicationHelper
    # Creates a wrapper around `link_to` to destroy objects
    # through javascript by creating a hidden form
    # @param [String] title the title to use for the link
    # @param [Object] object the object record to reference
    # @param [Hash] link_opts an extension of link_to's options
    # @return [String] html to display
    def link_to_destroy(title, object, link_opts = {})
      html = []
      html << link_to(title, "#", link_opts.merge({class: "destroy_resource #{link_opts[:class]}"}))
      html << form_for(object, url: object, method: :delete, html: {style: "display: none"}) {}
      
      html.join("").html_safe
    end
    
    # Creates a human-readable version of an object
    # @param [Object] object the object record to reference
    # @return [String] the result of conversion
    def sub_title_for(object)
      object.class.to_s.demodulize.underscore.titleize
    end
    
    # Simply creates an ID to use in the `body` of the layout
    # which is a combination of the current controller and action
    # @return [String] the ID
    # @example Types#edit
    #   Will produce `guts_types_edit`
    def controller_css_id
      "#{params[:controller].gsub(/\//, "_")}_#{params[:action]}"
    end
    
    # Determines if a menu is active in the admin panel
    # @param [Symbol, String] key the string to compare against
    # @param [Boolean] strict weather to do a direct compare or sub string
    # @example Strict (default)
    #   For /guts/types... `menu_active? :types`
    # @example Non-strict
    #   For /guts/navigations/main-menu/item... `menu_active? :navigation, false`
    def menu_active?(key, strict = true)
      if strict
        controller.controller_name == key.to_s
      else
        controller.controller_name.include? key.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
guts-1.0.8 app/helpers/guts/application_helper.rb
guts-1.0.7 app/helpers/guts/application_helper.rb
guts-1.0.5 app/helpers/guts/application_helper.rb
guts-1.0.3 app/helpers/guts/application_helper.rb