Class: Aurita::GUI::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/aurita-gui/html.rb

Overview

class

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.

Raises:

  • (::Exception)


332
333
334
335
336
# File 'lib/aurita-gui/html.rb', line 332

def initialize(&block)
  raise ::Exception.new('Missing block for Builder') unless block_given?
  @output_buffer = ''
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth_name, *attribs, &block) ⇒ Object



358
359
360
# File 'lib/aurita-gui/html.rb', line 358

def method_missing(meth_name, *attribs, &block)
  render(meth_name, *attribs, &block) 
end

Instance Method Details

#brObject

Statically defined as <br /> must not have any attributes.



339
340
341
# File 'lib/aurita-gui/html.rb', line 339

def br
  @output_buffer << '<br />'
end

#p(*attribs, &block) ⇒ Object

p is defined in Kernel, so we have to redirect it manually (method_missing won’t be triggered for it)



354
355
356
# File 'lib/aurita-gui/html.rb', line 354

def p(*attribs, &block)
  render(:p, *attribs, &block)
end

#render(meth_name, *args, &block) ⇒ Object

Raises:

  • (::Exception)


343
344
345
346
347
348
349
# File 'lib/aurita-gui/html.rb', line 343

def render(meth_name, *args, &block)
  raise ::Exception.new('Missing attributes for HTML.' << meth_name.inspect) unless args
  e = Buffered_Element.new(@output_buffer, *args, &block)
  e.tag = meth_name
  @output_buffer << e.string
  e
end

#to_sObject



362
363
364
# File 'lib/aurita-gui/html.rb', line 362

def to_s
  @output_buffer
end