module Grandstand::MainHelper # Returns 'active' if the current page matches the passed URL hash. This will # require the controller to match. If one or more action is passed, those actions # (or params[:return_to]) must match as well. If not, it lets the controller mean # it's active. def active_on(*conditions) match = lambda do |condition| controllers = Array(condition.delete(:controller)).compact.flatten.map(&:to_s).uniq actions = Array(condition.delete(:action)).compact.map(&:to_s).flatten.uniq controllers.include?(controller_name) && (actions.empty? || actions.include?(action_name) || actions.include?(params[:return_to])) end options = {} if conditions.any?(&match) options[:class] = 'active' end options end # Renders a # # The extra spans are for any sliding door styling you may be interested in adding. Adding :icon to the options will # give the inner-most span a class of "#{options[:icon]} icon", allowing you to add extra images inside of your button. def button_link_to(*args) options, icon = button_options(args.extract_options! || {}) link_to(content_tag(:span, :class => icon ? "#{icon} icon" : nil) { args.shift }, *args.push(options)) end def button_options(options) classes = %w(button) if icon = options.delete(:icon) classes.push('has-icon') end if options.delete(:default) classes.push('default') end classes.push(options[:class].to_s.split(' ')) if options[:class] options[:class] = classes.uniq.join(' ') [options, icon] end def expand(*controllers) options = controllers.extract_options! options[:class] = Array(options[:class]).compact options[:class].push(:expandable) section = controllers.first controllers.map!(&:to_s) if controllers.include?(controller_name) || !((session[:expand] ||= []) & controllers).empty? options[:class].push(:expanded) end raw %( class="#{options[:class].join(' ')}") end def expand_link(section) link_to(raw(''), '#', :class => 'expand', :rel => section) end def hide(condition) raw ' style="display:none;"' if condition end # A form wrapper that's used to override the default field_error_proc in a thread-safeish way. # The new field_error_proc returns a