Sha256: 9d4cc10efa3eeca59ae2284a3c2c1b09e3f593008e86b03d0ca59729bad8a0ad

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

require "hashie"

module Fume
  module SimpleNav
    
    def self.try_enable(app)
      ActionView::Base.send :include, HelperExtensions
    end
    
    module HelperExtensions
      
      def simple_nav(attr_reader_name)
        value = self.send(attr_reader_name)
        tag = SimpleNavTag.new({
          :helper => self,
          :value => value,
          :active_class => "active"
        })

        if block_given?
          yield tag
          return nil
        else
          return tag
        end
      end
      
      class SimpleNavTag < Hashie::Mash
        
        def li_tag(value, options = {}, &block)
          self.content_tag(value, :li, options, &block)
        end

        def content_tag(value, tag_name, options = {}, &block)
          if value == self.value
            if options[:class]
              options[:class] += " #{self.active_class}"
            else
              options[:class] = "#{self.active_class}"
            end
          end

          helper.content_tag(tag_name, options, &block)
        end
      end
  
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fume-0.8.1a lib/fume/simple_nav.rb
fume-0.8.0 lib/fume/simple_nav.rb
fume-0.8.0b lib/fume/simple_nav.rb
fume-0.8.0a lib/fume/simple_nav.rb
fume-0.7.2 lib/fume/simple_nav.rb
fume-0.7.1 lib/fume/simple_nav.rb
fume-0.7.0 lib/fume/simple_nav.rb