Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Helpers > Tag helpers

6.5. Tag helpers

The tag helpers, of which there are only four, are fundamental to the creation of HTML and XML entities. Let’s go through the code that pulls these together:

module Merb
  module Helpers
    module Tag

      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
					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
					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

					  


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint