require 'cgi' require 'erb' module ActionView module Helpers # This is poor man's Builder for the rare cases where you need to programmatically make tags but can't use Builder. module TagHelper include ERB::Util # Examples: # * tag("br") =>
# * tag("input", { "type" => "text"}) => def tag(name, options = {}, open = false) "<#{name}#{tag_options(options)}" + (open ? ">" : " />") end # Examples: # * content_tag("p", "Hello world!") =>

Hello world!

# * content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") => #

Hello world!

def content_tag(name, content, options = {}) "<#{name}#{tag_options(options)}>#{content}" end private def tag_options(options) unless options.empty? " " + options.map { |key, value| %(#{key}="#{html_escape(value)}") }.sort.join(" ") end end end end end