Skip to content

Commit

Permalink
Install html_output plugin. [#30]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed May 29, 2009
1 parent fe086cd commit 36ce2e1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vendor/plugins/html_output/README.textile
@@ -0,0 +1,4 @@
h2. HTML Output

This miniscule Rails plugin stops Rails outputting self-closing (XHTML-style) markup
which is useful if you want to use the Rails tag helpers and produce valid HTML.
1 change: 1 addition & 0 deletions vendor/plugins/html_output/init.rb
@@ -0,0 +1 @@
require 'html_output'
16 changes: 16 additions & 0 deletions vendor/plugins/html_output/lib/html_output.rb
@@ -0,0 +1,16 @@
require 'active_support'

module ActionView::Helpers::TagHelper
# Forces the "open" param to always be true so it never self-closes
def tag_with_non_self_closing(name, options = nil, open = false, *args)
tag_without_non_self_closing name, options, true
end

alias_method_chain :tag, :non_self_closing
end

class ActionView::Helpers::InstanceTag
# We have to re-alias tag_without_error_wrapping because it is previously
# aliased to the old version of tag, which self-closes
alias_method :tag_without_error_wrapping, :tag_with_non_self_closing
end
23 changes: 23 additions & 0 deletions vendor/plugins/html_output/test/test.rb
@@ -0,0 +1,23 @@
%w(rubygems active_support action_controller action_view test/unit).each { |r| require r }
require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'html_output')

class HtmlOutputTest < Test::Unit::TestCase
include ActionView::Helpers::TagHelper

def test_tag
assert_not_self_closing tag("br")
assert_not_self_closing tag("link", :rel => "stylesheet")
assert_not_self_closing tag("link", {:rel => "stylesheet"}, true)
assert_not_self_closing tag("link", {:rel => "stylesheet"}, true, false)
end

def test_instance_tag
assert_not_self_closing ActionView::Helpers::InstanceTag.new("test", "foo", self).to_input_field_tag("text")
end

private

def assert_not_self_closing tag
assert_nil tag["/"]
end
end

0 comments on commit 36ce2e1

Please sign in to comment.