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
170
171
172
173
174
175
176
177
|
# File 'lib/mab/mixin.rb', line 170
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
184
185
|
# File 'lib/mab/mixin.rb', line 184
def mab_done(tag)
end
|
#mab_insert(tag) ⇒ Object
179
180
181
182
|
# File 'lib/mab/mixin.rb', line 179
def mab_insert(tag)
ctx = @mab_context || raise(Error, 'mab { }-block required')
ctx << tag
end
|
#mab_options ⇒ Object
187
188
189
|
# File 'lib/mab/mixin.rb', line 187
def mab_options
@mab_options ||= {}
end
|
#mab_tag(name) ⇒ Object
151
152
153
154
155
156
|
# File 'lib/mab/mixin.rb', line 151
def mab_tag(name)
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
end
|
#tag!(name, *args, &blk) ⇒ Object
158
159
160
|
# File 'lib/mab/mixin.rb', line 158
def tag!(name, *args, &blk)
mab_tag(name)._insert(*args, &blk)
end
|
#text(str) ⇒ Object
166
167
168
|
# File 'lib/mab/mixin.rb', line 166
def text(str)
text! CGI.escapeHTML(str.to_s)
end
|
#text!(str) ⇒ Object
162
163
164
|
# File 'lib/mab/mixin.rb', line 162
def text!(str)
mab_insert(str)
end
|