Class: Campo::Haml_Ruby_Insert

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

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

Returns a new instance of Haml_Ruby_Insert.



470
471
472
473
474
475
476
477
478
479
480
# File 'lib/campo/campo.rb', line 470

def initialize( s )
  fail ArgumentError, "you may only pass a string to Haml_Ruby_Insert/bit_of_ruby" unless s.kind_of?( String )
  super( nil ) # no name needed
  
  # @todo Don't enforce the equals sign, as a hyphen is also valid for adding a bit of ruby. Raise an exception
  @s = s.start_with?( '=' ) ? s : "= " + s.to_s

  self.on_output do |n=0, tab=2|
    (" " * n * tab) + @s
  end
end