Sha256: 3190d5a3bf5b2bcdefb6a144150c1936357f41915de121a0d01f141ef3bf01a9

Contents?: true

Size: 1.73 KB

Versions: 36

Compression:

Stored size: 1.73 KB

Contents

module Merb
  module Helpers
    module Tag    
      # Creates a generic HTML tag. You can invoke it a variety of ways.
      #   
      #   tag :div
      #   # <div></div>
      #   
      #   tag :div, 'content'
      #   # <div>content</div>
      #   
      #   tag :div, :class => 'class'
      #   # <div class="class"></div>
      #   
      #   tag :div, 'content', :class => 'class'
      #   # <div class="class">content</div>
      #   
      #   tag :div do
      #     'content'
      #   end
      #   # <div>content</div>
      #   
      #   tag :div, :class => 'class' do
      #     'content'
      #   end
      #   # <div class="class">content</div>
      # 
      def tag(name, contents = nil, attrs = {}, &block)
        attrs, contents = contents, nil if contents.is_a?(Hash)
        contents = capture(&block) if block_given?
        open_tag(name, attrs) + contents.to_s + close_tag(name)
      end
    
      # Creates the opening tag with attributes for the provided +name+
      # attrs is a hash where all members will be mapped to key="value"
      #
      # Note: This tag will need to be closed
      def open_tag(name, attrs = nil)
        "<#{name}#{' ' + attrs.to_html_attributes unless attrs.blank?}>"
      end
    
      # Creates a closing tag
      def close_tag(name)
        "</#{name}>"
      end
    
      # Creates a self closing tag.  Like <br/> or <img src="..."/>
      #
      # +name+ : the name of the tag to create
      # +attrs+ : a hash where all members will be mapped to key="value"
      def self_closing_tag(name, attrs = nil)
        "<#{name}#{' ' + attrs.to_html_attributes if attrs && !attrs.empty?}/>"
      end
        
    end
  end
end

module Merb::GlobalHelpers
  include Merb::Helpers::Tag
end    

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/tag_helpers.rb
merb-helpers-1.1.3 lib/merb-helpers/tag_helpers.rb
merb-helpers-1.1.2 lib/merb-helpers/tag_helpers.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/tag_helpers.rb
merb-helpers-1.1.1 lib/merb-helpers/tag_helpers.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/tag_helpers.rb
merb-helpers-1.1.0 lib/merb-helpers/tag_helpers.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/tag_helpers.rb
merb-helpers-1.1.0.rc1 lib/merb-helpers/tag_helpers.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/tag_helpers.rb
merb-helpers-1.1.0.pre lib/merb-helpers/tag_helpers.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/tag_helpers.rb
merb-helpers-1.0.15 lib/merb-helpers/tag_helpers.rb
merb-helpers-1.0.14 lib/merb-helpers/tag_helpers.rb
merb-helpers-1.0.13 lib/merb-helpers/tag_helpers.rb
merb-helpers-1.0.12 lib/merb-helpers/tag_helpers.rb
merb-helpers-0.9.10 lib/merb-helpers/tag_helpers.rb
merb-helpers-0.9.9 lib/merb-helpers/tag_helpers.rb
merb-helpers-1.0.1 lib/merb-helpers/tag_helpers.rb
merb-helpers-0.9.13 lib/merb-helpers/tag_helpers.rb