Class: Htmless::StubBuilderForDocumentation::AbstractDoubleTag

Inherits:
AbstractTag
  • Object
show all
Defined in:
lib/htmless/doc.rb

Constant Summary

Constant Summary

Constants inherited from AbstractTag

Htmless::StubBuilderForDocumentation::AbstractTag::METHOD_MISSING_REGEXP

Instance Attribute Summary

Attributes inherited from AbstractTag

#builder

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from AbstractTag

_attributes, _attributes=, add_attributes, attribute_content_rendering, attributes, #class, #default, define_attribute_methods, #flush_classes, #id, inherited, #rclass, set_tag, strings_injector, tag_name

Constructor Details

- (AbstractDoubleTag) initialize(builder)

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.

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

- (Object) method_missing(method, *args, &block)

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

Class Method Details

+ (Object) define_attribute_method(attribute) (protected)

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.



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/htmless/doc.rb', line 369

def self.define_attribute_method(attribute)
  return if instance_methods(false).include?(attribute.name)
  name = attribute.name.to_s

  if instance_methods.include?(attribute.name)
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{name}(*args, &block)
        super(*args, &nil)
        return with(&block) if block
        self
      end
    RUBY
  else
    content_rendering = attribute_content_rendering(attribute)
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{name}(content#{' = true' if attribute.type == :boolean}, &block)
        #{content_rendering}
        return with(&block) if block
        self
      end
    RUBY
  end
end

Instance Method Details

- (Object) attribute(name, value, &block)



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

- (Object) attributes(attrs, &block)



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

- (Object) content(content)

sets content of the double tag

Examples:

div 'content' # => <div>content</div>
div.content 'content' # => <div>content</div>
div :content => 'content' # => <div>content</div>


314
315
316
317
# File 'lib/htmless/doc.rb', line 314

def content(content)
  @content = content.to_s
  self
end

- (Object) data(hash, &block)



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

- (Object) flush

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

- (Object) mimic(obj, &block)



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

- (Object) open(*args, &block)

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

- (Object) with { ... } Also known as: w

renders content of the double tag with block

Examples:

div { text 'content' } # => <div>content</div>
div :id => 'id' do
  text 'content'
end # => <div id="id">content</div>

Yields:

  • content of the tag



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