Class: HammerBuilder::StubBuilderForDocumentation::AbstractDoubleTag

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

Constant Summary

Constant Summary

Constants inherited from AbstractTag

HammerBuilder::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

add_attributes, #attribute, attribute_content_rendering, attributes, #attributes, #class, #data, #default, define_attribute_methods, #flush_classes, #id, inherited, #initialize, #object, #open, #rclass, set_tag, tag_name

Constructor Details

This class inherits a constructor from HammerBuilder::StubBuilderForDocumentation::AbstractTag

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.



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/hammer_builder/doc.rb', line 353

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) 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>


304
305
306
307
# File 'lib/hammer_builder/doc.rb', line 304

def content(content)
  @content = content.to_s
  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



291
292
293
294
295
296
297
# File 'lib/hammer_builder/doc.rb', line 291

def flush
  flush_classes
  @output << Strings::GT
  @output << CGI.escapeHTML(@content) if @content
  @output << Strings::SLASH_LT << @stack.pop << Strings::GT
  @content = nil
end

- (Object) with { ... }

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



316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/hammer_builder/doc.rb', line 316

def with
  flush_classes
  @output << Strings::GT
  @content         = nil
  @builder.current = nil
  yield
  #if (content = yield).is_a?(String)
  #  @output << EscapeUtils.escape_html(content)
  #end
  @builder.flush
  @output << Strings::SLASH_LT << @stack.pop << Strings::GT
  nil
end