Sha256: 534ec26f4e7f2c329ef68c275c9034ec2fe10a944a2bbda8b549e89a79a9ac08

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module PluginAWeek #:nodoc:
  module MenuHelper
    # Represents an HTML element
    # 
    # == Modifying HTML options
    # 
    # HTML options can normally be specified when creating the element.
    # However, if they need to be modified after the element has been created,
    # you can access the properties like so:
    # 
    #   m = Menu.new
    #   m[:style] = 'display: none;'
    # 
    # or for a menu bar:
    # 
    #   b = MenuBar.new
    #   b[:style] = 'display: none;'
    class HtmlElement
      include ActionView::Helpers::TagHelper
      
      delegate  :[],
                :[]=,
                  :to => '@html_options'
      
      def initialize(html_options = {}) #:nodoc:
        @html_options = html_options.symbolize_keys
      end
      
      # Generates the html representing this element
      def html
        content_tag(tag_name, content, @html_options)
      end
      
      private
        # The name of the element tag to use (e.g. td, th, tr, etc.)
        def tag_name
          ''
        end
        
        # The content that will be displayed inside of the tag
        def content
          ''
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
menu_helper-0.0.5 lib/menu_helper/html_element.rb
menu_helper-0.0.4 lib/menu_helper/html_element.rb
menu_helper-0.1.0 lib/menu_helper/html_element.rb