Module: Amrita2::ElementHelper

Included in:
Hpricot::Elem
Defined in:
lib/amrita2/template.rb,
lib/amrita2/template.rb

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#add(elem) ⇒ Object



367
368
369
# File 'lib/amrita2/template.rb', line 367

def add(elem)
  insert_after(elem, nil)
end

#add_text(text) ⇒ Object



371
372
373
# File 'lib/amrita2/template.rb', line 371

def add_text(text)
  insert_after(Hpricot::Text.new(text), nil)
end

#as_amrita_dictionary(opt = {}) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/amrita2/template.rb', line 375

def as_amrita_dictionary(opt={})
  ret = {}
  attributes.each do |k, v|
    ret[k.intern] = v
  end
  if opt[:use_contents]
    ret[opt[:use_contents]] =
      Amrita2::SanitizedString[
                               children.collect do |c|
                                 c.to_s
                               end.join
                              ]
  end

  if opt[:use_tag]
    { name.intern => ret }
  else
    ret
  end
end

#contentsObject



346
347
348
349
350
351
352
# File 'lib/amrita2/template.rb', line 346

def contents
  if children.size > 0
    SanitizedString[children.to_s]
  else
    nil
  end
end

#delete_attribute(key) ⇒ Object



363
364
365
# File 'lib/amrita2/template.rb', line 363

def delete_attribute(key)
  raw_attributes.delete(key)
end

#elementsObject



340
341
342
343
344
# File 'lib/amrita2/template.rb', line 340

def elements
  children.select do |c|
    c.kind_of?(Hpricot::Elem)
  end
end

#set_attribute(key, val) ⇒ Object



354
355
356
357
358
359
360
361
# File 'lib/amrita2/template.rb', line 354

def set_attribute(key, val)
  case val
  when nil, ""
    delete_attribute(key)
  else
    super
  end
end