Skip to content

Commit

Permalink
Correct behavior for self-closing tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
benauthor committed May 2, 2012
1 parent 53a5ad0 commit f8e5154
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
18 changes: 15 additions & 3 deletions lib/markaby/builder.rb
Expand Up @@ -333,6 +333,11 @@ class XmlMarkup < ::Builder::XmlMarkup
class SgmlMarkup < ::Builder::XmlMarkup
attr_accessor :target, :level

def initialize(options={})
super(options)
@tagset = options[:tagset] || ::Markaby::HTML5
end

def method_missing(sym, *args, &block)
text = nil
attrs = nil
Expand Down Expand Up @@ -363,9 +368,16 @@ def method_missing(sym, *args, &block)
_newline
end
elsif text.nil?
_indent
_start_tag(sym, attrs, false)
_newline
if @tagset.self_closing.include?(sym)
_indent
_start_tag(sym, attrs, false)
_newline
else
_indent
_start_tag(sym, attrs, false)
_end_tag(sym)
_newline
end
else
_indent
_start_tag(sym, attrs)
Expand Down
27 changes: 15 additions & 12 deletions spec/markaby/html5_spec.rb
Expand Up @@ -2,22 +2,22 @@

describe Markaby do
it "should insert an html5 doctype" do
document = mab { html5 { head { title 'OKay' } } }
document = mab5 { html5 { head { title 'OKay' } } }
document.should include("<!DOCTYPE html>")
end

it "should not have xmlns in html5 html tag" do
document = mab { html5 { head { title 'OKay' } } }
document = mab5 { html5 { head { title 'OKay' } } }
document.should_not include("xmlns")
end

it "should make html5-specific tags" do
document = mab { html5 { tag! :header } }
document = mab5 { html5 { tag! :header } }
document.should include("header")
end

it "should accept html5-specific tag as a block" do
document = mab { html5 { header { h1 "Wow" } } }
document = mab5 { html5 { header { h1 "Wow" } } }
document.should include("<header><h1>Wow</h1></header>")
end

Expand All @@ -32,25 +32,28 @@
end

it "should put correct html5 charset meta" do
document = mab { html5 { head { title 'OKay' } } }
document.should include('<meta charset="utf-8"/>')
# TODO: sort out the differences in self-closing in HTML5, i.e.
# document.should include('<meta charset="utf-8">')
document = mab5 { html5 { head { title 'OKay' } } }
document.should include('<meta charset="utf-8">')
end

it "should add a class to a html5 tag" do
document = mab { html5 { canvas.big "yo look" } }
document = mab5 { html5 { canvas.big "yo look" } }
document.should include('<canvas class="big">yo look</canvas>')
end

it "should add an id to a html5 tag" do
document = mab { html5 { canvas.only! "yo look" } }
document = mab5 { html5 { canvas.only! "yo look" } }
document.should include('<canvas id="only">yo look</canvas>')
end

it "should add a closing slash to self-closing tags in xhtml" do
document = mab { br }
document.should include('<br/>')
end

it "should not add a closing slash to self-closing tags in html5" do
document = mab5 { html5 { meta :charset => "utf-8" } }
document.should include('<meta charset="utf-8">')
document = mab5 { br }
document.should include('<br>')
end

it "should close empty non-self-closing tags in html5" do
Expand Down

0 comments on commit f8e5154

Please sign in to comment.