Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'html_output' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |