Module: Mab::Mixin
Defined Under Namespace
Modules: HTML5, HTMLDefiners, XHTML5, XML
Classes: Context, Error, Tag
Instance Method Summary
collapse
Instance Method Details
#mab(&blk) ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/mab/mixin.rb', line 151
def mab(&blk)
prev = defined?(@mab_context) && @mab_context
ctx = @mab_context = Context.new
res = instance_eval(&blk)
ctx.empty? ? res : ctx.join
ensure
@mab_context = prev
end
|
#mab_done(tag) ⇒ Object
165
166
|
# File 'lib/mab/mixin.rb', line 165
def mab_done(tag)
end
|
#mab_insert(tag) ⇒ Object
160
161
162
163
|
# File 'lib/mab/mixin.rb', line 160
def mab_insert(tag)
ctx = @mab_context || raise(Error, 'mab { }-block required')
ctx << tag
end
|
#mab_options ⇒ Object
168
169
170
|
# File 'lib/mab/mixin.rb', line 168
def mab_options
@mab_options ||= {}
end
|
#tag!(name, content = nil, attrs = nil, &blk) ⇒ Object
136
137
138
139
140
141
|
# File 'lib/mab/mixin.rb', line 136
def tag!(name, content = nil, attrs = nil, &blk)
ctx = @mab_context || raise(Error, "Tags can only be written within a `mab { }`-block")
tag = Tag.new(name, mab_options, ctx, self)
mab_insert(tag)
tag.insert(content, attrs, &blk)
end
|
#text(str) ⇒ Object
147
148
149
|
# File 'lib/mab/mixin.rb', line 147
def text(str)
text! CGI.escapeHTML(str.to_s)
end
|
#text!(str) ⇒ Object
143
144
145
|
# File 'lib/mab/mixin.rb', line 143
def text!(str)
mab_insert(str)
end
|