markaby 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +3 -7
- data/CHANGELOG.rdoc +19 -0
- data/Gemfile +10 -8
- data/Gemfile.lock +63 -49
- data/Markaby.gemspec +12 -16
- data/README.rdoc +68 -14
- data/Rakefile +30 -24
- data/lib/markaby/builder.rb +50 -73
- data/lib/markaby/builder_tags.rb +6 -4
- data/lib/markaby/cssproxy.rb +5 -5
- data/lib/markaby/html5.rb +118 -0
- data/lib/markaby/kernel_method.rb +3 -3
- data/lib/markaby/rails.rb +6 -6
- data/lib/markaby/tagset.rb +89 -0
- data/lib/markaby/version.rb +7 -0
- data/lib/markaby/xhtml_frameset.rb +13 -0
- data/lib/markaby/xhtml_strict.rb +89 -0
- data/lib/markaby/xhtml_transitional.rb +61 -0
- data/lib/markaby/xml_tagset.rb +19 -0
- data/lib/markaby.rb +6 -10
- data/spec/markaby/builder_spec.rb +1 -1
- data/spec/markaby/css_proxy_spec.rb +13 -12
- data/spec/markaby/html5_spec.rb +59 -25
- data/spec/markaby/markaby_spec.rb +19 -19
- data/spec/markaby/markaby_test_unit_spec.rb +97 -38
- data/spec/markaby/rails_spec.rb +1 -1
- data/spec/spec_helper.rb +18 -11
- metadata +18 -21
- data/lib/markaby/tags.rb +0 -310
data/lib/markaby/builder_tags.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require "markaby/html5"
|
2
|
+
|
1
3
|
module Markaby
|
2
4
|
module BuilderTags
|
3
5
|
(HTML5.tags - [:head]).each do |k|
|
4
|
-
class_eval <<-CODE, __FILE__, __LINE__
|
6
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
5
7
|
def #{k}(*args, &block)
|
6
8
|
html_tag(#{k.inspect}, *args, &block)
|
7
9
|
end
|
@@ -28,8 +30,8 @@ module Markaby
|
|
28
30
|
# set to <tt>text/html; charset=utf-8</tt>.
|
29
31
|
def head(*args, &block)
|
30
32
|
tag!(:head, *args) do
|
31
|
-
tag!(:meta, "http-equiv" => "Content-Type", "content" => "text/html; charset=utf-8") if @output_meta_tag ==
|
32
|
-
tag!(:meta, "charset" => "utf-8") if @output_meta_tag ==
|
33
|
+
tag!(:meta, "http-equiv" => "Content-Type", "content" => "text/html; charset=utf-8") if @output_meta_tag == "xhtml"
|
34
|
+
tag!(:meta, "charset" => "utf-8") if @output_meta_tag == "html5"
|
33
35
|
instance_eval(&block)
|
34
36
|
end
|
35
37
|
end
|
@@ -64,7 +66,7 @@ module Markaby
|
|
64
66
|
raise NotImplementedError, "Deprecated! Call self.tagset = Markaby::HTML5"
|
65
67
|
end
|
66
68
|
|
67
|
-
|
69
|
+
private
|
68
70
|
|
69
71
|
def xhtml_html(attrs = {}, &block)
|
70
72
|
instruct! if @output_xml_instruction
|
data/lib/markaby/cssproxy.rb
CHANGED
@@ -6,9 +6,9 @@ module Markaby
|
|
6
6
|
class CssProxy
|
7
7
|
def initialize(builder, stream, sym)
|
8
8
|
@builder = builder
|
9
|
-
@stream
|
10
|
-
@sym
|
11
|
-
@attrs
|
9
|
+
@stream = stream
|
10
|
+
@sym = sym
|
11
|
+
@attrs = {}
|
12
12
|
|
13
13
|
@original_stream_length = @stream.length
|
14
14
|
|
@@ -16,10 +16,10 @@ module Markaby
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def respond_to?(sym, include_private = false)
|
19
|
-
include_private || !private_methods.map { |m| m.to_sym }.include?(sym.to_sym) ? true : false
|
19
|
+
(include_private || !private_methods.map { |m| m.to_sym }.include?(sym.to_sym)) ? true : false
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
private
|
23
23
|
|
24
24
|
# Adds attributes to an element. Bang methods set the :id attribute.
|
25
25
|
# Other methods add to the :class attribute.
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require "markaby/xhtml_transitional"
|
2
|
+
module Markaby
|
3
|
+
class HTML5 < Tagset
|
4
|
+
class << self
|
5
|
+
def default_options
|
6
|
+
super.merge({
|
7
|
+
output_xml_instruction: false,
|
8
|
+
output_meta_tag: "html5",
|
9
|
+
root_attributes: {}
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
def custom_element? tag_name
|
14
|
+
tag_name.to_s.include? "_"
|
15
|
+
end
|
16
|
+
|
17
|
+
def can_handle? tag_name
|
18
|
+
custom_element? tag_name
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_tag tag_name, builder, *args, &block
|
22
|
+
builder.tag! tag_name, *args, &block
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_and_transform_tag_name! tag_name
|
26
|
+
custom_element?(tag_name) ? custom_element_tag_for(tag_name) : super
|
27
|
+
end
|
28
|
+
|
29
|
+
def custom_element_tag_for tag_name
|
30
|
+
tag_name.to_s.tr("_", "-").to_sym
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate_attribute! tag_name, attribute_name
|
34
|
+
custom_element?(tag_name) || super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@doctype = ["html"]
|
39
|
+
@tagset = XHTMLTransitional.tagset.merge({
|
40
|
+
abbr: Attrs,
|
41
|
+
article: Attrs,
|
42
|
+
aside: Attrs,
|
43
|
+
audio: Attrs,
|
44
|
+
bdi: Attrs,
|
45
|
+
canvas: Attrs,
|
46
|
+
command: Attrs,
|
47
|
+
datalist: Attrs,
|
48
|
+
details: Attrs,
|
49
|
+
embed: Attrs,
|
50
|
+
figure: Attrs,
|
51
|
+
figcaption: Attrs,
|
52
|
+
footer: Attrs,
|
53
|
+
header: Attrs,
|
54
|
+
hgroup: Attrs,
|
55
|
+
keygen: Attrs,
|
56
|
+
mark: Attrs,
|
57
|
+
menu: Attrs,
|
58
|
+
meter: Attrs,
|
59
|
+
nav: Attrs,
|
60
|
+
output: Attrs,
|
61
|
+
progress: Attrs,
|
62
|
+
rp: Attrs,
|
63
|
+
rt: Attrs,
|
64
|
+
ruby: Attrs,
|
65
|
+
section: Attrs,
|
66
|
+
source: Attrs,
|
67
|
+
time: Attrs,
|
68
|
+
track: Attrs,
|
69
|
+
video: Attrs,
|
70
|
+
wbr: Attrs
|
71
|
+
})
|
72
|
+
|
73
|
+
# Additional attributes found in HTML5
|
74
|
+
additional_tags = {
|
75
|
+
a: [:media, :download, :ping],
|
76
|
+
area: [:media, :download, :ping, :hreflang, :rel, :type],
|
77
|
+
base: [:target],
|
78
|
+
button: [:autofocus, :form, :formaction, :formenctype, :formmethod,
|
79
|
+
:formnovalidate, :formtarget],
|
80
|
+
fieldset: [:form, :disabled, :name],
|
81
|
+
form: [:novalidate],
|
82
|
+
label: [:form],
|
83
|
+
html: [:manifest],
|
84
|
+
iframe: [:sandbox, :seamless, :srcdoc],
|
85
|
+
img: [:crossorigin],
|
86
|
+
input: [:autofocus, :placeholder, :form, :required, :autocomplete,
|
87
|
+
:min, :max, :multiple, :pattern, :step, :list, :width, :height,
|
88
|
+
:dirname, :formaction, :formenctype, :formmethod,
|
89
|
+
:formnovalidate, :formtarget],
|
90
|
+
link: [:sizes],
|
91
|
+
meta: [:charset],
|
92
|
+
menu: [:type, :label],
|
93
|
+
object: [:form, :typemustmatch],
|
94
|
+
ol: [:reversed],
|
95
|
+
output: [:form],
|
96
|
+
script: [:async],
|
97
|
+
select: [:autofocus, :form, :required],
|
98
|
+
style: [:scoped],
|
99
|
+
textarea: [:autofocus, :placeholder, :form, :required, :dirname,
|
100
|
+
:maxlength, :wrap]
|
101
|
+
}
|
102
|
+
|
103
|
+
AttrsHTML5 = [:contenteditable, :contextmentu, :draggable, :dropzone,
|
104
|
+
:hidden, :role, :spellcheck, :translate]
|
105
|
+
|
106
|
+
additional_tags.each do |k, v|
|
107
|
+
@tagset[k] += v
|
108
|
+
end
|
109
|
+
|
110
|
+
@tagset.each do |k, v|
|
111
|
+
@tagset[k] += AttrsHTML5
|
112
|
+
end
|
113
|
+
|
114
|
+
@tags = @tagset.keys
|
115
|
+
@forms = @tags & FORM_TAGS
|
116
|
+
@self_closing = @tags & SELF_CLOSING_TAGS
|
117
|
+
end
|
118
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# You'll need to <tt>require 'markaby/kernel_method'</tt> for this.
|
2
|
-
require
|
2
|
+
require "markaby"
|
3
3
|
|
4
4
|
module Kernel
|
5
5
|
# Shortcut for creating a quick block of Markaby.
|
6
|
-
def mab(
|
7
|
-
Markaby::Builder.new(
|
6
|
+
def mab(...)
|
7
|
+
Markaby::Builder.new(...).to_s
|
8
8
|
end
|
9
9
|
end
|
data/lib/markaby/rails.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "markaby"
|
2
2
|
|
3
3
|
module Markaby
|
4
4
|
module Rails
|
5
5
|
class TemplateHandler
|
6
6
|
class << self
|
7
|
-
def register!(options={})
|
7
|
+
def register!(options = {})
|
8
8
|
self.options = options
|
9
9
|
ActionView::Template.register_template_handler(:mab, new)
|
10
10
|
end
|
@@ -19,15 +19,15 @@ module Markaby
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def options=(val)
|
22
|
-
|
23
|
-
|
22
|
+
options.merge!(val)
|
23
|
+
options
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def call(template)
|
27
|
+
def call(template, source = template.source)
|
28
28
|
<<-CODE
|
29
29
|
Markaby::Builder.new(Markaby::Rails::TemplateHandler.options, self) do
|
30
|
-
#{
|
30
|
+
#{source}
|
31
31
|
end.to_s
|
32
32
|
CODE
|
33
33
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Markaby
|
2
|
+
FORM_TAGS = [:form, :input, :select, :textarea]
|
3
|
+
SELF_CLOSING_TAGS = [:area, :base, :br, :col, :command, :embed, :frame, :hr,
|
4
|
+
:img, :input, :keygen, :link, :meta, :param, :source,
|
5
|
+
:track, :wbr]
|
6
|
+
|
7
|
+
# Common sets of attributes.
|
8
|
+
AttrCore = [:id, :class, :style, :title]
|
9
|
+
AttrI18n = [:lang, :"xml:lang", :dir]
|
10
|
+
AttrEvents = [:onclick,
|
11
|
+
:ondblclick,
|
12
|
+
:onmousedown,
|
13
|
+
:onmouseup,
|
14
|
+
:onmouseover,
|
15
|
+
:onmousemove,
|
16
|
+
:onmouseout,
|
17
|
+
:onkeypress,
|
18
|
+
:onkeydown,
|
19
|
+
:onkeyup]
|
20
|
+
AttrFocus = [:accesskey, :tabindex, :onfocus, :onblur]
|
21
|
+
AttrHAlign = [:align, :char, :charoff]
|
22
|
+
AttrVAlign = [:valign]
|
23
|
+
Attrs = AttrCore + AttrI18n + AttrEvents
|
24
|
+
|
25
|
+
AttrsBoolean = [
|
26
|
+
:checked, :disabled, :multiple, :readonly, :selected, # standard forms
|
27
|
+
:autofocus, :required, :novalidate, :formnovalidate, # HTML5 forms
|
28
|
+
:defer, :ismap, # <script defer>, <img ismap>
|
29
|
+
:compact, :declare, :noresize, :noshade, :nowrap # deprecated or unused
|
30
|
+
]
|
31
|
+
class Tagset
|
32
|
+
class << self
|
33
|
+
attr_accessor :tags, :tagset, :forms, :self_closing, :doctype
|
34
|
+
|
35
|
+
def default_options
|
36
|
+
{tagset: self}
|
37
|
+
end
|
38
|
+
|
39
|
+
def can_handle? tag_name
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
def handle_tag tag_name, builder, *args, &block
|
44
|
+
raise NoMethodError.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate_and_transform_tag_name! tag_name
|
48
|
+
raise(InvalidXhtmlError, "no element `#{tag_name}' for #{doctype}") unless @tagset.has_key?(tag_name)
|
49
|
+
tag_name
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate_and_transform_attributes! tag_name, *args
|
53
|
+
args.last.respond_to?(:to_hash) ? transform_attributes(tag_name, args.last.to_hash) : {}
|
54
|
+
end
|
55
|
+
|
56
|
+
def transform_attributes tag_name, attributes
|
57
|
+
attributes[:name] ||= attributes[:id] if forms.include?(tag_name) && attributes[:id]
|
58
|
+
attributes.transform_keys! { |name| transform_attribute_name name }
|
59
|
+
hashed_attributes = attributes.keys.select { |name| attributes[name].is_a? Hash }
|
60
|
+
hashed_attributes.each { |name| transform_attribute_hash attributes, name }
|
61
|
+
attributes.reject! { |name, value| name.nil? || (AttrsBoolean.include?(name) && value.nil?) }
|
62
|
+
attributes.keys.each { |name| validate_attribute! tag_name, name }
|
63
|
+
attributes
|
64
|
+
end
|
65
|
+
|
66
|
+
def transform_attribute_name name
|
67
|
+
name.to_s.downcase.tr("_", "-").to_sym
|
68
|
+
end
|
69
|
+
|
70
|
+
def transform_attribute_hash attributes, prefix
|
71
|
+
values = attributes[prefix]
|
72
|
+
expanded_attributes = {}
|
73
|
+
values.each do |suffix, value|
|
74
|
+
name = transform_attribute_name "#{prefix}-#{suffix}"
|
75
|
+
expanded_attributes[name] = value
|
76
|
+
end
|
77
|
+
attributes.merge!(expanded_attributes).delete(prefix)
|
78
|
+
end
|
79
|
+
|
80
|
+
def validate_attribute! tag_name, attribute_name
|
81
|
+
raise InvalidXhtmlError, "no attribute `#{attribute_name}' on #{tag_name} elements" unless valid_attribute_name? tag_name, attribute_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def valid_attribute_name? tag_name, attribute_name
|
85
|
+
attribute_name.to_s.start_with?(":", "data-", "aria-") || @tagset[tag_name].include?(attribute_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Markaby
|
2
|
+
class XHTMLFrameset < XmlTagset
|
3
|
+
@doctype = ["-//W3C//DTD XHTML 1.0 Frameset//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"]
|
4
|
+
@tagset = XHTMLTransitional.tagset.merge({
|
5
|
+
frameset: AttrCore + [:rows, :cols, :onload, :onunload],
|
6
|
+
frame: AttrCore + [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :noresize, :scrolling]
|
7
|
+
})
|
8
|
+
|
9
|
+
@tags = @tagset.keys
|
10
|
+
@forms = @tags & FORM_TAGS
|
11
|
+
@self_closing = @tags & SELF_CLOSING_TAGS
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Markaby
|
2
|
+
# All the tags and attributes from XHTML 1.0 Strict
|
3
|
+
class XHTMLStrict < XmlTagset
|
4
|
+
@doctype = ["-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]
|
5
|
+
@tagset = {
|
6
|
+
html: AttrI18n + [:id, :xmlns],
|
7
|
+
head: AttrI18n + [:id, :profile],
|
8
|
+
title: AttrI18n + [:id],
|
9
|
+
base: [:href, :id],
|
10
|
+
meta: AttrI18n + [:id, :http, :name, :content, :scheme, :"http-equiv"],
|
11
|
+
link: Attrs + [:charset, :href, :hreflang, :type, :rel, :rev, :media],
|
12
|
+
style: AttrI18n + [:id, :type, :media, :title, :"xml:space"],
|
13
|
+
script: [:id, :charset, :type, :src, :defer, :"xml:space"],
|
14
|
+
noscript: Attrs,
|
15
|
+
body: Attrs + [:onload, :onunload],
|
16
|
+
div: Attrs,
|
17
|
+
p: Attrs,
|
18
|
+
ul: Attrs,
|
19
|
+
ol: Attrs,
|
20
|
+
li: Attrs,
|
21
|
+
dl: Attrs,
|
22
|
+
dt: Attrs,
|
23
|
+
dd: Attrs,
|
24
|
+
address: Attrs,
|
25
|
+
hr: Attrs,
|
26
|
+
pre: Attrs + [:"xml:space"],
|
27
|
+
blockquote: Attrs + [:cite],
|
28
|
+
ins: Attrs + [:cite, :datetime],
|
29
|
+
del: Attrs + [:cite, :datetime],
|
30
|
+
a: Attrs + AttrFocus + [:charset, :type, :name, :href, :hreflang, :rel, :rev, :shape, :coords],
|
31
|
+
span: Attrs,
|
32
|
+
bdo: AttrCore + AttrEvents + [:lang, :"xml:lang", :dir],
|
33
|
+
br: AttrCore,
|
34
|
+
em: Attrs,
|
35
|
+
strong: Attrs,
|
36
|
+
dfn: Attrs,
|
37
|
+
code: Attrs,
|
38
|
+
samp: Attrs,
|
39
|
+
kbd: Attrs,
|
40
|
+
var: Attrs,
|
41
|
+
cite: Attrs,
|
42
|
+
abbr: Attrs,
|
43
|
+
acronym: Attrs,
|
44
|
+
q: Attrs + [:cite],
|
45
|
+
sub: Attrs,
|
46
|
+
sup: Attrs,
|
47
|
+
tt: Attrs,
|
48
|
+
i: Attrs,
|
49
|
+
b: Attrs,
|
50
|
+
big: Attrs,
|
51
|
+
small: Attrs,
|
52
|
+
object: Attrs + [:declare, :classid, :codebase, :data, :type, :codetype, :archive, :standby, :height, :width, :usemap, :name, :tabindex],
|
53
|
+
param: [:id, :name, :value, :valuetype, :type],
|
54
|
+
img: Attrs + [:src, :alt, :longdesc, :height, :width, :usemap, :ismap],
|
55
|
+
map: AttrI18n + AttrEvents + [:id, :class, :style, :title, :name],
|
56
|
+
area: Attrs + AttrFocus + [:shape, :coords, :href, :nohref, :alt],
|
57
|
+
form: Attrs + [:action, :method, :enctype, :onsubmit, :onreset, :accept, :accept],
|
58
|
+
label: Attrs + [:for, :accesskey, :onfocus, :onblur],
|
59
|
+
input: Attrs + AttrFocus + [:type, :name, :value, :checked, :disabled, :readonly, :size, :maxlength, :src, :alt, :usemap, :onselect, :onchange, :accept],
|
60
|
+
select: Attrs + [:name, :size, :multiple, :disabled, :tabindex, :onfocus, :onblur, :onchange],
|
61
|
+
optgroup: Attrs + [:disabled, :label],
|
62
|
+
option: Attrs + [:selected, :disabled, :label, :value],
|
63
|
+
textarea: Attrs + AttrFocus + [:name, :rows, :cols, :disabled, :readonly, :onselect, :onchange],
|
64
|
+
fieldset: Attrs,
|
65
|
+
legend: Attrs + [:accesskey],
|
66
|
+
button: Attrs + AttrFocus + [:name, :value, :type, :disabled],
|
67
|
+
table: Attrs + [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding],
|
68
|
+
caption: Attrs,
|
69
|
+
colgroup: Attrs + AttrHAlign + AttrVAlign + [:span, :width],
|
70
|
+
col: Attrs + AttrHAlign + AttrVAlign + [:span, :width],
|
71
|
+
thead: Attrs + AttrHAlign + AttrVAlign,
|
72
|
+
tfoot: Attrs + AttrHAlign + AttrVAlign,
|
73
|
+
tbody: Attrs + AttrHAlign + AttrVAlign,
|
74
|
+
tr: Attrs + AttrHAlign + AttrVAlign,
|
75
|
+
th: Attrs + AttrHAlign + AttrVAlign + [:abbr, :axis, :headers, :scope, :rowspan, :colspan],
|
76
|
+
td: Attrs + AttrHAlign + AttrVAlign + [:abbr, :axis, :headers, :scope, :rowspan, :colspan],
|
77
|
+
h1: Attrs,
|
78
|
+
h2: Attrs,
|
79
|
+
h3: Attrs,
|
80
|
+
h4: Attrs,
|
81
|
+
h5: Attrs,
|
82
|
+
h6: Attrs
|
83
|
+
}
|
84
|
+
|
85
|
+
@tags = @tagset.keys
|
86
|
+
@forms = @tags & FORM_TAGS
|
87
|
+
@self_closing = @tags & SELF_CLOSING_TAGS
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "markaby/xml_tagset"
|
2
|
+
require "markaby/xhtml_strict"
|
3
|
+
module Markaby
|
4
|
+
# Additional tags found in XHTML 1.0 Transitional
|
5
|
+
class XHTMLTransitional < XmlTagset
|
6
|
+
@doctype = ["-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]
|
7
|
+
@tagset = XHTMLStrict.tagset.merge({
|
8
|
+
strike: Attrs,
|
9
|
+
center: Attrs,
|
10
|
+
dir: Attrs + [:compact],
|
11
|
+
noframes: Attrs,
|
12
|
+
basefont: [:id, :size, :color, :face],
|
13
|
+
u: Attrs,
|
14
|
+
menu: Attrs + [:compact],
|
15
|
+
iframe: AttrCore + [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :scrolling, :align, :height, :width],
|
16
|
+
font: AttrCore + AttrI18n + [:size, :color, :face],
|
17
|
+
s: Attrs,
|
18
|
+
applet: AttrCore + [:codebase, :archive, :code, :object, :alt, :name, :width, :height, :align, :hspace, :vspace],
|
19
|
+
isindex: AttrCore + AttrI18n + [:prompt]
|
20
|
+
})
|
21
|
+
|
22
|
+
# Additional attributes found in XHTML 1.0 Transitional
|
23
|
+
additional_tags = {
|
24
|
+
script: [:language],
|
25
|
+
a: [:target],
|
26
|
+
td: [:bgcolor, :nowrap, :width, :height],
|
27
|
+
p: [:align],
|
28
|
+
h5: [:align],
|
29
|
+
h3: [:align],
|
30
|
+
li: [:type, :value],
|
31
|
+
div: [:align],
|
32
|
+
pre: [:width],
|
33
|
+
body: [:background, :bgcolor, :text, :link, :vlink, :alink],
|
34
|
+
ol: [:type, :compact, :start],
|
35
|
+
h4: [:align],
|
36
|
+
h2: [:align],
|
37
|
+
object: [:align, :border, :hspace, :vspace],
|
38
|
+
img: [:name, :align, :border, :hspace, :vspace],
|
39
|
+
link: [:target],
|
40
|
+
legend: [:align],
|
41
|
+
dl: [:compact],
|
42
|
+
input: [:align],
|
43
|
+
h6: [:align],
|
44
|
+
hr: [:align, :noshade, :size, :width],
|
45
|
+
base: [:target],
|
46
|
+
ul: [:type, :compact],
|
47
|
+
br: [:clear],
|
48
|
+
form: [:name, :target],
|
49
|
+
area: [:target],
|
50
|
+
h1: [:align]
|
51
|
+
}
|
52
|
+
|
53
|
+
additional_tags.each do |k, v|
|
54
|
+
@tagset[k] += v
|
55
|
+
end
|
56
|
+
|
57
|
+
@tags = @tagset.keys
|
58
|
+
@forms = @tags & FORM_TAGS
|
59
|
+
@self_closing = @tags & SELF_CLOSING_TAGS
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "markaby/tagset"
|
2
|
+
module Markaby
|
3
|
+
# Additional tags found in XHTML 1.0 Frameset
|
4
|
+
class XmlTagset < Tagset
|
5
|
+
class << self
|
6
|
+
def default_options
|
7
|
+
super.merge({
|
8
|
+
output_xml_instruction: true,
|
9
|
+
output_meta_tag: "xhtml",
|
10
|
+
root_attributes: {
|
11
|
+
xmlns: "http://www.w3.org/1999/xhtml",
|
12
|
+
"xml:lang": "en",
|
13
|
+
lang: "en"
|
14
|
+
}
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/markaby.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# as well as the full set of Markaby classes.
|
5
5
|
#
|
6
6
|
# For a full list of features and instructions, see the README.
|
7
|
-
$:.unshift
|
7
|
+
$:.unshift __dir__
|
8
8
|
|
9
9
|
# Markaby is a module containing all of the great Markaby classes that
|
10
10
|
# do such an excellent job.
|
@@ -17,15 +17,11 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
|
|
17
17
|
# * Markaby::Tags: lists the roles of various XHTML tags to help Builder
|
18
18
|
# use these tags as they are intended.
|
19
19
|
module Markaby
|
20
|
-
MAJOR = 0
|
21
|
-
MINOR = 9
|
22
|
-
TINY = 0
|
23
|
-
|
24
|
-
VERSION = "#{MAJOR}.#{MINOR}.#{TINY}"
|
25
|
-
|
26
20
|
class InvalidXhtmlError < StandardError; end
|
27
21
|
end
|
28
22
|
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
23
|
+
require "markaby/version"
|
24
|
+
require "builder" unless defined?(Builder)
|
25
|
+
require "markaby/tagset"
|
26
|
+
require "markaby/builder"
|
27
|
+
require "markaby/cssproxy"
|
@@ -9,34 +9,35 @@ describe Markaby::CssProxy do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def mock_builder
|
12
|
-
|
13
|
-
def tag!(*args)
|
12
|
+
Class.new do
|
13
|
+
def tag!(*args)
|
14
|
+
end
|
14
15
|
end.new
|
15
16
|
end
|
16
17
|
|
17
18
|
it "responds_to_everything" do
|
18
|
-
proxy = Markaby::CssProxy.new(mock_builder,
|
19
|
-
proxy.respond_to?(:any_method).should
|
20
|
-
proxy.respond_to?(:foobarbazasdfasdfadfs).should
|
19
|
+
proxy = Markaby::CssProxy.new(mock_builder, "stream", :sym)
|
20
|
+
proxy.respond_to?(:any_method).should be true
|
21
|
+
proxy.respond_to?(:foobarbazasdfasdfadfs).should be true
|
21
22
|
end
|
22
23
|
|
23
24
|
it "does_not_respond_to_method_missing" do
|
24
|
-
proxy = Markaby::CssProxy.new(mock_builder,
|
25
|
+
proxy = Markaby::CssProxy.new(mock_builder, "stream", :sym)
|
25
26
|
proxy.should_not respond_to(:method_missing)
|
26
27
|
end
|
27
28
|
|
28
29
|
it "does_respond_to_private_instance_methods_with_private_flag_set_to_true" do
|
29
|
-
proxy = Markaby::CssProxy.new(mock_builder,
|
30
|
-
proxy.respond_to?(:method_missing, true).should
|
30
|
+
proxy = Markaby::CssProxy.new(mock_builder, "stream", :sym)
|
31
|
+
proxy.respond_to?(:method_missing, true).should be true
|
31
32
|
end
|
32
33
|
|
33
34
|
it "does_not_respond_to_private_instance_methods_with_private_flag_set_to_false" do
|
34
|
-
proxy = Markaby::CssProxy.new(mock_builder,
|
35
|
-
proxy.respond_to?(:method_missing, false).should
|
35
|
+
proxy = Markaby::CssProxy.new(mock_builder, "stream", :sym)
|
36
|
+
proxy.respond_to?(:method_missing, false).should be false
|
36
37
|
end
|
37
38
|
|
38
39
|
it "respond_to_should_always_return_boolean" do
|
39
|
-
proxy = Markaby::CssProxy.new(mock_builder,
|
40
|
-
proxy.respond_to?(:method_missing, :a_value).should
|
40
|
+
proxy = Markaby::CssProxy.new(mock_builder, "stream", :sym)
|
41
|
+
proxy.respond_to?(:method_missing, :a_value).should be true
|
41
42
|
end
|
42
43
|
end
|