Skip to content

Commit

Permalink
A few more tags. mab5 kernel method. html5_options.
Browse files Browse the repository at this point in the history
  • Loading branch information
benauthor authored and smtlaissezfaire committed Dec 18, 2013
1 parent 377fd90 commit 0872596
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
16 changes: 15 additions & 1 deletion lib/markaby/builder.rb
Expand Up @@ -30,20 +30,34 @@ class Builder
:output_xml_instruction => true,
:output_meta_tag => 'xhtml',
:auto_validation => true,
:tagset => Markaby::HTML5,
:tagset => Markaby::XHTMLTransitional,
:root_attributes => {
:xmlns => 'http://www.w3.org/1999/xhtml',
:'xml:lang' => 'en',
:lang => 'en'
}
}

HTML5_OPTIONS = {
:indent => 0,
:output_helpers => true,
:output_xml_instruction => false,
:output_meta_tag => 'html5',
:auto_validation => false,
:tagset => Markaby::HTML5,
:root_attributes => {}
}

@@options = DEFAULT_OPTIONS.dup

def self.restore_defaults!
@@options = DEFAULT_OPTIONS.dup
end

def self.set_html5_options!
@@options = HTML5_OPTIONS.dup
end

def self.set(option, value)
@@options[option] = value
end
Expand Down
2 changes: 1 addition & 1 deletion lib/markaby/builder_tags.rb
Expand Up @@ -58,7 +58,7 @@ def xhtml_frameset(attrs = {}, &block)
def html5(attrs = {}, &block)
self.tagset = Markaby::HTML5
@root_attributes = {} # lose the default xml stuff
@auto_validation = false
@auto_validation = false # because not yet implemented for html5
@output_meta_tag = "html5"
html5_html(attrs, &block)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/markaby/kernel_method.rb
Expand Up @@ -4,4 +4,11 @@ module Kernel
def mab(*args, &block)
Markaby::Builder.new(*args, &block).to_s
end
# Shortcut for creating a quick block of HTML5.
def mab5(*args, &block)
Markaby::Builder.set_html5_options!
mab = Markaby::Builder.new(*args, &block)
Markaby::Builder.restore_defaults!
mab.to_s
end
end
17 changes: 15 additions & 2 deletions lib/markaby/tags.rb
@@ -1,6 +1,8 @@
module Markaby
FORM_TAGS = [ :form, :input, :select, :textarea ]
SELF_CLOSING_TAGS = [ :base, :meta, :link, :hr, :br, :param, :img, :area, :input, :col, :frame ]
SELF_CLOSING_TAGS = [:area, :base, :br, :col, :command, :embed, :frame, :hr,
:img, :input, :keygen, :link, :meta, :param, :source,
:track, :wbr]

# Common sets of attributes.
AttrCore = [:id, :class, :style, :title]
Expand Down Expand Up @@ -209,22 +211,33 @@ class << self
:article => Attrs,
:aside => Attrs,
:audio => Attrs,
:bdi => Attrs,
:canvas => Attrs,
:command => Attrs,
:datalist => Attrs,
:details => Attrs,
:embed => Attrs,
:figure => Attrs,
:figcaption => Attrs,
:footer => Attrs,
:header => Attrs,
:hgroup => Attrs,
:keygen => Attrs,
:mark => Attrs,
:menu => Attrs,
:meter => Attrs,
:nav => Attrs,
:output => Attrs,
:progress => Attrs,
:rp => Attrs,
:rt => Attrs,
:ruby => Attrs,
:section => Attrs,
:source => Attrs,
:time => Attrs,
:video => Attrs
:track => Attrs,
:video => Attrs,
:wbr => Attrs
})

@tags = @tagset.keys
Expand Down
29 changes: 19 additions & 10 deletions spec/markaby/html5_spec.rb
@@ -1,51 +1,60 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

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

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

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

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

it "html5-specific tags work in partials" do
document = mab { header { h1 "Wow" } }
it "should make html5-specific tags in partials" do
document = mab5 { header { h1 "Wow" } }
document.should include("<header><h1>Wow</h1></header>")
end

it "puts correct xhtml charset meta" do
it "should put correct xhtml charset meta" do
document = mab { xhtml_strict { head { title 'OKay' } } }
document.should include('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>')
end

it "puts correct html5 charset meta" do
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">')
end

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

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

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

it "should close empty non-self-closing tags in html5" do
document = mab { header }
document.should include("<header></header>")
end
end

0 comments on commit 0872596

Please sign in to comment.