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

–}}}



503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/rcov/xx.rb', line 503

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

–}}}



515
516
517
518
519
# File 'lib/rcov/xx.rb', line 515

def xx_config
#--{{{
  @@xx_config ||= Hash::new{|h,k| h[k] = {}}
#--}}}
end

#xx_config_for(key, xx_which = nil) ⇒ Object

–}}}



520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/rcov/xx.rb', line 520

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

–}}}



532
533
534
535
536
537
538
# File 'lib/rcov/xx.rb', line 532

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

–}}}



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/rcov/xx.rb', line 476

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

–}}}



471
472
473
474
475
# File 'lib/rcov/xx.rb', line 471

def xx_define_tmp_method m 
#--{{{
  define_method(m){ raise NotImplementedError, m.to_s }
#--}}}
end

#xx_remove_tag_method(tag_method) ⇒ Object

–}}}



498
499
500
501
502
# File 'lib/rcov/xx.rb', line 498

def xx_remove_tag_method tag_method
#--{{{
  remove_method tag_method rescue nil
#--}}}
end

#xx_tag_method_name(m) ⇒ Object

–{{{



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

def xx_tag_method_name m
#--{{{
  m = m.to_s
  tag_method, tag_name = m, m.gsub(%r/_+$/, "")
  [ tag_method, tag_name ]
#--}}}
end