Class: Htmless::StubBuilderForDocumentation::AbstractDoubleTag
- Inherits:
-
AbstractTag
- Object
- AbstractTag
- Htmless::StubBuilderForDocumentation::AbstractDoubleTag
- Defined in:
- lib/htmless/doc.rb
Constant Summary
Constants inherited from AbstractTag
Htmless::StubBuilderForDocumentation::AbstractTag::METHOD_MISSING_REGEXP
Instance Attribute Summary
Attributes inherited from AbstractTag
Instance Method Summary collapse
- #attribute(name, value, &block) ⇒ Object
- #attributes(attrs, &block) ⇒ Object
-
#content(content) ⇒ Object
sets content of the double tag.
- #data(hash, &block) ⇒ Object
-
#flush ⇒ Object
private
closes the tag.
-
#initialize(builder) ⇒ AbstractDoubleTag
constructor
private
A new instance of AbstractDoubleTag.
-
#method_missing(method, *args, &block) ⇒ Object
allows data-* attributes and id, classes by method_missing.
- #mimic(obj, &block) ⇒ Object
- #open(*args, &block) ⇒ Object private
-
#with { ... } ⇒ Object
(also: #w)
renders content of the double tag with block.
Methods inherited from AbstractTag
_attributes, _attributes=, attributes, #class, #id, #rclass, strings_injector, tag_name
Constructor Details
#initialize(builder) ⇒ AbstractDoubleTag
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AbstractDoubleTag.
260 261 262 263 |
# File 'lib/htmless/doc.rb', line 260 def initialize(builder) super @content = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
allows data-* attributes and id, classes by method_missing
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/htmless/doc.rb', line 266 def method_missing(method, *args, &block) method = method.to_s if method =~ METHOD_MISSING_REGEXP if $1 self.rclass.add_attributes Data::Attribute.new(method.to_sym, :string) self.send method, *args, &block else attributes(if args.last.is_a?(Hash) args.pop end) content args.first self.__send__($3 == '!' ? :id : :class, $2.gsub(@_str_underscore, @_str_dash), &block) end else super(method, *args, &block) end end |
Instance Method Details
#attribute(name, value, &block) ⇒ Object
354 355 356 357 358 |
# File 'lib/htmless/doc.rb', line 354 def attribute(name, value, &block) super(name, value, &nil) return with(&block) if block self end |
#attributes(attrs, &block) ⇒ Object
360 361 362 363 364 |
# File 'lib/htmless/doc.rb', line 360 def attributes(attrs, &block) super(attrs, &nil) return with(&block) if block self end |
#content(content) ⇒ Object
sets content of the double tag
314 315 316 317 |
# File 'lib/htmless/doc.rb', line 314 def content(content) @content = content.to_s self end |
#data(hash, &block) ⇒ Object
348 349 350 351 352 |
# File 'lib/htmless/doc.rb', line 348 def data(hash, &block) super(hash, &nil) return with(&block) if block self end |
#flush ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
closes the tag
301 302 303 304 305 306 307 |
# File 'lib/htmless/doc.rb', line 301 def flush flush_classes @output << @_str_gt @output << CGI.escapeHTML(@content) if @content @output << @_str_slash_lt << @stack.pop << @_str_gt @content = nil end |
#mimic(obj, &block) ⇒ Object
342 343 344 345 346 |
# File 'lib/htmless/doc.rb', line 342 def mimic(obj, &block) super(obj, &nil) return with(&block) if block self end |
#open(*args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/htmless/doc.rb', line 285 def open(*args, &block) attributes = if args.last.is_a?(Hash) args.pop end content args[0] super attributes @stack << @tag_name if block with &block else self end end |
#with { ... } ⇒ Object Also known as: w
renders content of the double tag with block
326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/htmless/doc.rb', line 326 def with flush_classes @output << @_str_gt @content = nil @builder.current = nil yield #if (content = yield).is_a?(String) # @output << EscapeUtils.escape_html(content) #end @builder.flush @output << @_str_slash_lt << @stack.pop << @_str_gt nil end |