Module: XX::Markup::ClassMethods

Included in:
XX::Markup
Defined in:
lib/rcov/xx.rb

Instance Method Summary collapse

Instance Method Details

#xx_ancestors(xx_which = self) ⇒ Object



496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/rcov/xx.rb', line 496

def xx_ancestors xx_which = self

  list = []
  ancestors.each do |a|
    list << a if a < xx_which
  end
  xx_which.ancestors.each do |a|
    list << a if a <= Markup
  end
  list

end

#xx_configObject



508
509
510
511
512
# File 'lib/rcov/xx.rb', line 508

def xx_config

  @@xx_config ||= Hash::new{|h,k| h[k] = {}}

end

#xx_config_for(key, xx_which = nil) ⇒ Object



513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/rcov/xx.rb', line 513

def xx_config_for key, xx_which = nil 

  key = key.to_s 
  xx_which ||= self
  xx_ancestors(xx_which).each do |a|
    if xx_config[a].has_key? key
      return xx_config[a][key]
    end
  end
  nil

end

#xx_configure(key, value, xx_which = nil) ⇒ Object



525
526
527
528
529
530
531
# File 'lib/rcov/xx.rb', line 525

def xx_configure key, value, xx_which = nil 

  key = key.to_s
  xx_which ||= self
  xx_config[xx_which][key] = value

end

#xx_define_tag_method(tag_method, tag_name = nil) ⇒ Object



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/rcov/xx.rb', line 469

def xx_define_tag_method tag_method, tag_name = nil

  tag_method = tag_method.to_s
  tag_name ||= tag_method.gsub %r/_+$/, ""

  remove_method tag_method if instance_methods.include? tag_method
  module_eval <<-code, __FILE__, __LINE__+1
    def #{ tag_method } *a, &b
      hashes, nothashes = a.partition{|x| Hash === x}

      doc = xx_doc
      element = ::REXML::Element::new '#{ tag_name }'

      hashes.each{|h| h.each{|k,v| element.add_attribute k.to_s, v}}
      nothashes.each{|nh| element << ::REXML::Text::new(nh.to_s)}

      doc.create element, &b
    end
  code
  tag_method

end

#xx_define_tmp_method(m) ⇒ Object



464
465
466
467
468
# File 'lib/rcov/xx.rb', line 464

def xx_define_tmp_method m 

  define_method(m){ raise NotImplementedError, m.to_s }

end

#xx_remove_tag_method(tag_method) ⇒ Object



491
492
493
494
495
# File 'lib/rcov/xx.rb', line 491

def xx_remove_tag_method tag_method

  remove_method tag_method rescue nil

end

#xx_tag_method_name(m) ⇒ Object



457
458
459
460
461
462
463
# File 'lib/rcov/xx.rb', line 457

def xx_tag_method_name m

  m = m.to_s
  tag_method, tag_name = m, m.gsub(%r/_+$/, "")
  [ tag_method, tag_name ]

end