diff --git a/lib/html5.rb b/lib/html5.rb index 3f90ca8..353ae06 100644 --- a/lib/html5.rb +++ b/lib/html5.rb @@ -16,32 +16,20 @@ def javascript_src_tag_with_empty_type(source, options) def stylesheet_tag(source, options) tag("link", { "rel" => "stylesheet", "media" => "screen", "href" => html_escape(path_to_stylesheet(source)) }.merge(options), ::SKIP_SELF_CLOSE_TAGS, false) end - - def image_tag(source, options = {}) - options.symbolize_keys! - - options[:src] = path_to_image(source) - options[:alt] ||= File.basename(options[:src], '.*').split('.').first.to_s.capitalize - if size = options.delete(:size) - options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$} - end +end - if mouseover = options.delete(:mouseover) - options[:onmouseover] = "this.src='#{image_path(mouseover)}'" - options[:onmouseout] = "this.src='#{image_path(options[:src])}'" - end - - tag("img", options, ::SKIP_SELF_CLOSE_TAGS) - end +module ActionView::Helpers::TagHelper + # When served as text/html, tags do not need to be self-closed. + # http://www.whatwg.org/specs/web-apps/current-work/#void-elements + VOID_ELEMENTS = %w(base command link meta hr br img embed param area col input source) + + def tag_with_skip_self_closing(name, options = nil, open = false, escape = true) + open = true if VOID_ELEMENTS.include?(name.to_s) && ::SKIP_SELF_CLOSE_TAGS - def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {}) - tag( - "link", - {"rel" => tag_options[:rel] || "alternate", - "type" => tag_options[:type] || Mime::Type.lookup_by_extension(type.to_s).to_s, - "title" => tag_options[:title] || type.to_s.upcase, - "href" => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options}, ::SKIP_SELF_CLOSE_TAGS - ) + tag_without_skip_self_closing(name, options, open, escape) end -end \ No newline at end of file + alias_method_chain :tag, :skip_self_closing +end + +