Class: Campo::Literal

Inherits:
Base
  • Object
show all
Defined in:
lib/campo/campo.rb

Overview

Add whatever you need to with a literal.

Constant Summary

Constants inherited from Base

Base::DEFAULT

Instance Attribute Summary

Attributes inherited from Base

#attributes, #attributes The element's html attributes., #fields, #fields The element's child elements.

Attributes included from Childish

#parent

Instance Method Summary collapse

Methods inherited from Base

#each, #labelled, #on_output, #output, output, quotable, unhash

Methods included from Convenience

#bit_of_ruby, #checkbox, #fieldset, #hidden, #input, #literal, #password, #radio, #select, #submit, #text, #textarea

Methods included from Iding

#id_tag

Methods included from Childish

#push=

Constructor Details

#initialize(s, attributes = {}) ⇒ Literal

Returns a new instance of Literal.

Parameters:

  • s (String)

    The literal string.

  • attributes (Hash, optional) (defaults to: {})

    Any html attributes you wish the literal to have.



489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/campo/campo.rb', line 489

def initialize( s, attributes={} )
  super( nil, attributes ) # no name needed
  @s = s

  self.on_output do |n=0, tab=2|
    left,right = if @attributes.empty?
      ['','']
    else
      ['{ ', '}']
    end
    %Q!#{" " * n * tab}#{@s}! + left + Base.unhash( @attributes ) + right
  end
  self
end